SHARE
TWEET

Untitled

a guest May 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @pytest.fixture(scope="function")
  2. def base_fixture(request):
  3.  
  4.     if saucelabs:
  5.  
  6.         desired_cap = {
  7.             'platform': "Mac OS X 10.13",
  8.             'browserName': "safari",
  9.             'version': "11.1",
  10.             'build': "OCT",
  11.             'name': "test",
  12.         }
  13.  
  14.         driver = webdriver.Remote(
  15.             command_executor=f'http://{sauce_username}:{sauce_access_key}@ondemand.eu-central-1.saucelabs.com/wd/hub',
  16.             desired_capabilities=desired_cap)
  17.  
  18.         browser.set_driver(driver)
  19.         browser.open_url(base_url)
  20.  
  21.     else:
  22.        
  23.         chrome_options = Options()
  24.         chrome_options.add_experimental_option('prefs', {
  25.             'credentials_enable_service': False,
  26.             'profile': {'password_manager_enabled': False}
  27.             })
  28.  
  29.         if headless_mode:
  30.             chrome_options.add_argument('--window-size=1920x1080')
  31.             chrome_options.add_argument('--headless')
  32.             chrome_options.add_argument('--disable-gpu')
  33.             chrome_options.add_argument('--no-sandbox')
  34.         else:
  35.             chrome_options.add_argument("--start-maximized")
  36.  
  37.         driver = webdriver.Chrome(ChromeDriverManager(web_driver_version).install(), options=chrome_options)
  38.  
  39.         # To run inside a Docker container
  40.         # capabilities = DesiredCapabilities.CHROME
  41.         # remote_server = 'http://chrome:4444/wd/hub'
  42.         # driver = webdriver.Remote(command_executor=remote_server, desired_capabilities=capabilities)
  43.  
  44.         browser.set_driver(driver)
  45.         browser.open_url(base_url)
  46.  
  47.     def teardown():
  48.  
  49.         if js_logs:
  50.             browser_logs = browser.driver().get_log('browser')
  51.             console_msgs = [console_msg for console_msg in browser_logs if console_msg['level'] in
  52.                             ['SEVERE', 'ERROR', 'WARNING']]
  53.             unique_msgs = [dict(y) for y in set(tuple(x.items()) for x in console_msgs)]
  54.             for msg in unique_msgs:
  55.                 logging.warning(msg)
  56.  
  57.         browser.quit()
  58.  
  59.     request.addfinalizer(teardown)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top