コード例 #1
0
ファイル: browser.py プロジェクト: rodinant/selene
def quit_driver():
    warnings.warn(
        'selene.browser.quit_driver is deprecated, '
        'use `from selene.support.shared import browser` import',
        DeprecationWarning,
    )
    browser.quit()
コード例 #2
0
def browser_management():
    """
    Here, before yield,
    goes all "setup" code for each test case
    aka "before test function" hook
    """

    import config
    browser.config.base_url = config.settings.base_url
    browser.config.timeout = config.settings.timeout
    browser.config.save_page_source_on_failure \
        = config.settings.save_page_source_on_failure

    browser.config.driver = _driver_from(config.settings)

    yield
    """
    Here, after yield,
    goes all "tear down" code for each test case
    aka "after test function" hook
    """

    browser.config.hold_browser_open = config.settings.hold_browser_open
    if not config.settings.hold_browser_open:
        browser.quit()
コード例 #3
0
def browser_management(config):
    browser.config.timeout = config.timeout
    browser.config.save_page_source_on_failure \
        = config.save_page_source_on_failure
    yield

    browser.quit()
コード例 #4
0
 def set_browser_for_tests(self):
     Settings()
     yield
     try:
         browser.quit()
     except WebDriverException:
         pass
コード例 #5
0
def test_shared_browser_reopens_on_url_open_action():
    browser.open('https://duckduckgo.com/')
    browser.element('[id="search_form_input_homepage"]').click()

    browser.quit()
    browser.open('https://duckduckgo.com/')

    browser.element('[id="search_form_input_homepage"]').click()
コード例 #6
0
def test_shared_browser_reopens_on_url_open_action():
    browser.open('http://google.ru')
    browser.element('[name="q"]').click()

    browser.quit()
    browser.open('http://google.ru')

    browser.element('[name="q"]').click()
コード例 #7
0
def driver():
    browser = get_driver_config(URL_BASE)
    yield browser
    try:
        pytest.globalDict = None
        browser.quit()
    except Exception as exc:
        print('Error in close browser')
        pass
コード例 #8
0
def native_selenium():
    start = time.time()
    logging.info(f'start {start}')
    logging.info(f'before start browser: {time.time() - start} seconds')
    browser = webdriver.Chrome(ChromeDriverManager().install())
    logging.info(f'browser start duration: {time.time() - start} seconds')
    browser.implicitly_wait(5)
    yield browser
    browser.quit()
    logging.info(f'test duration : {time.time() - start} seconds')
コード例 #9
0
def browser_management(request):
    """
    Here, before yield,
    goes all "setup" code for each test case
    aka "before test function" hook
    """

    # def attach_snapshots_on_failure(error: TimeoutException) -> Exception:
    #     """
    #     An example of selene hook_wait_failure that attaches snapshots to failed test step.
    #     It is actually not needed and optional,
    #     because in the pytest_runtest_makereport hook below
    #     we attach screenshots to the test body itself,
    #     that is more handy during analysis of test report
    #
    #     but if you need it, you can enable it by uncommenting
    #     together with the following ``browser.config.hook_wait_failure =`` line;)
    #
    #     otherwise, you can remove it
    #     """
    #     last_screenshot = browser.config.last_screenshot
    #     if last_screenshot:
    #         allure.attach.file(source=last_screenshot,
    #                            name='screenshot on failure',
    #                            attachment_type=allure.attachment_type.PNG)
    #
    #     last_page_source = browser.config.last_page_source
    #     if last_page_source:
    #         allure.attach.file(source=last_page_source,
    #                            name='page source on failure',
    #                            attachment_type=allure.attachment_type.HTML)
    #     return error
    # browser.config.hook_wait_failure = attach_snapshots_on_failure

    capabilities = {
        "browserName": "chrome",
        "version": "84.0",
        "enableVNC": True,
        "enableVideo": False
    }

    browser.config.driver = webdriver.Remote(
        command_executor="http://localhost:4444/wd/hub",
        desired_capabilities=capabilities)
    browser.config.base_url = 'https://www.saucedemo.com'
    browser.driver.maximize_window()

    yield
    """
    Here, after yield,
    goes all "tear down" code for each test case
    aka "after test function" hook
    """

    browser.quit()
コード例 #10
0
def test_shared_browser_not_reopen_on_action_after_been_closed():
    browser.open('https://duckduckgo.com/')
    browser.element('[id="search_form_input_homepage"]').click()

    browser.quit()

    with pytest.raises(RuntimeError) as error:
        browser.element('[id="search_form_input_homepage"]').click()
    assert 'Webdriver has been closed.' in str(error.value)
    assert 'You need to call open(url) to open a browser again.' in str(
        error.value)
コード例 #11
0
def selene_config():
    start = time.time()
    logging.info(f'start config browser : {time.time() - start} seconds')
    browser.config.browser_name = "chrome"
    browser.config.base_url = "https://google.com"
    browser.config.timeout = 2
    browser.config.reports_folder = "selene_reports"
    logging.info(f'browser config duration: {time.time() - start} seconds')
    yield
    browser.quit()
    logging.info(f'test duration : {time.time() - start} seconds')
コード例 #12
0
def test_shared_browser_not_reopen_on_action_after_been_closed():
    browser.open('http://google.ru')
    browser.element('[name="q"]').click()

    browser.quit()

    with pytest.raises(RuntimeError) as error:
        browser.element('[name="q"]').click()
    assert 'Webdriver has been closed.' in str(error.value)
    assert 'You need to call open(url) to open a browser again.' in str(
        error.value)
コード例 #13
0
ファイル: conftest.py プロジェクト: Cludent/todomvc-tests
def browser_management():
    browser.config.browser_name = config.settings.browser_name
    browser.config.timeout = config.settings.browser_config_timeout
    driver = _set_custom_driver(config.settings)
    if driver:
        browser.config.driver = driver

    yield
    if config.settings.browser_quit_after_each_test:
        browser.quit()
    else:
        browser.clear_local_storage()
コード例 #14
0
ファイル: conftest.py プロジェクト: pashamagpie/test-todomvc
def browser_management():
    browser.config.browser_name = config.settings.browser_name

    driver = _maybe_driver_from_settings(config.settings)
    if driver:
        browser.config.driver = driver

    yield
    if config.settings.browser_quit:
        browser.quit()
    else:
        browser.clear_local_storage()
コード例 #15
0
def browser_management():
    """
    Here, before yield,
    goes all "setup" code for each test case
    aka "before test function" hook
    """

    # def attach_snapshots_on_failure(error: TimeoutException) -> Exception:
    #     """
    #     An example of selene hook_wait_failure that attaches snapshots to failed test step.
    #     It is actually not needed and optional,
    #     because in the pytest_runtest_makereport hook below
    #     we attach screenshots to the test body itself,
    #     that is more handy during analysis of test report
    #
    #     but if you need it, you can enable it by uncommenting
    #     together with the following ``browser.config.hook_wait_failure =`` line;)
    #
    #     otherwise, you can remove it
    #     """
    #     last_screenshot = browser.config.last_screenshot
    #     if last_screenshot:
    #         allure.attach.file(source=last_screenshot,
    #                            name='screenshot on failure',
    #                            attachment_type=allure.attachment_type.PNG)
    #
    #     last_page_source = browser.config.last_page_source
    #     if last_page_source:
    #         allure.attach.file(source=last_page_source,
    #                            name='page source on failure',
    #                            attachment_type=allure.attachment_type.HTML)
    #     return error
    # browser.config.hook_wait_failure = attach_snapshots_on_failure

    import config
    browser.config.base_url = config.settings.base_url
    browser.config.timeout = config.settings.timeout
    browser.config.save_page_source_on_failure \
        = config.settings.save_page_source_on_failure

    browser.config.driver = _driver_from(config.settings)

    yield
    """
    Here, after yield,
    goes all "tear down" code for each test case
    aka "after test function" hook
    """

    browser.config.hold_browser_open = config.settings.hold_browser_open
    if not config.settings.hold_browser_open:
        browser.quit()
コード例 #16
0
ファイル: conftest.py プロジェクト: fkthereality/todomvc-test
def browser_management():
    browser.config.browser_name = \
        os.getenv('browser.config.browser_name', 'chrome')
    browser.config.browser_name = config.options.browser_name

    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager

    chrome_options = webdriver.ChromeOptions()
    chrome_options.headless = False
    driver = webdriver.Chrome(
        executable_path=ChromeDriverManager().install(),
        options=chrome_options
    )
    browser.config.driver = driver

    yield
    if config.options.browser_quit_after_each_test:
        browser.quit()
    else:
        browser.clear_local_storage()
コード例 #17
0
ファイル: todomvc_test.py プロジェクト: yashaka/selene
def teardown_function():
    browser.quit()
    browser.config.browser_name = 'chrome'
コード例 #18
0
def teardown_function():
    global selenium_browser
    selenium_browser.quit()
    browser.quit()
コード例 #19
0
from selene import have
from selene.support.shared import browser
from selene.support.shared.jquery_style import s, ss

# ARRANGE
URL = 'https://www.ecosia.org/'
query_string = "'yashaka selene'"
# користувач завантажує сторінку в браузері: https://www.ecosia.org/
# browser.config.hold_browser_open = True
browser.open(URL)

# ACTS
# користувач в поле пошуку вводить текст 'yashaka selene'
# користувач натискає Enter
s('[placeholder="Search the web to plant trees..."]').type(query_string).press_enter()

# користувач переходить по першому посиланню серед знайдених результатів
s('[class="result-snippet-link"]').click()

# ASSERT
# користувач перевіряє що на відкритій сторінці
# є три локальні посилання на https://github.com/yashaka/selene
ss('[href="/yashaka/selene"]').should(have.size(3))

browser.quit()
コード例 #20
0
def close_browser():
    yield
    browser.quit()
コード例 #21
0
 def teardown_method(self):
     browser.quit()
コード例 #22
0
ファイル: order_test.py プロジェクト: rodinant/selene
def teardown_function():
    browser.quit()
コード例 #23
0
def setup_function():
    browser.quit()
    browser.config.hold_browser_open = SharedConfig().hold_browser_open
    """setting to default"""
コード例 #24
0
def teardown_module():
    browser.config.hold_browser_open = SharedConfig().hold_browser_open
    browser.quit()
コード例 #25
0
def setup_function():
    browser.quit()
コード例 #26
0
def teardown_module():
    browser.quit()
コード例 #27
0
ファイル: conftest.py プロジェクト: Dahavi/abom_autotest
 def fin():
     attach = browser.driver.get_screenshot_as_png()
     allure.attach(attach, attachment_type=allure.attachment_type.PNG)
     logging.info("Closing webdriver instance")
     browser.quit()