def quit_driver(): warnings.warn( 'selene.browser.quit_driver is deprecated, ' 'use `from selene.support.shared import browser` import', DeprecationWarning, ) browser.quit()
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()
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()
def set_browser_for_tests(self): Settings() yield try: browser.quit() except WebDriverException: pass
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()
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()
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
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')
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()
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)
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')
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)
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()
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()
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()
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()
def teardown_function(): browser.quit() browser.config.browser_name = 'chrome'
def teardown_function(): global selenium_browser selenium_browser.quit() browser.quit()
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()
def close_browser(): yield browser.quit()
def teardown_method(self): browser.quit()
def teardown_function(): browser.quit()
def setup_function(): browser.quit() browser.config.hold_browser_open = SharedConfig().hold_browser_open """setting to default"""
def teardown_module(): browser.config.hold_browser_open = SharedConfig().hold_browser_open browser.quit()
def setup_function(): browser.quit()
def teardown_module(): browser.quit()
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()