How to use create_chrome method in Selene

Best Python code snippet using selene_python

conftest.py

Source:conftest.py Github

copy

Full Screen

...6 parser.addoption("--language", action="store", default="en-GB",7 help="Choose one of languages: ar, it, uk or en-GB")8 parser.addoption("--browser", action="store", default="chrome",9 help="Choose one of available browsers: chrome, chrome-headless, firefox")10def create_chrome(language, headless=False) -> webdriver:11 chrome_options = webdriver.ChromeOptions()12 chrome_options.add_experimental_option('prefs', {'intl.accept_languages': f"{language}, en"})13 if headless:14 chrome_options.add_argument("--headless")15 else:16 chrome_options.add_argument("--window-size=1920,1080")17 return webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=chrome_options)18def create_firefox():19 return webdriver.Firefox(executable_path=GeckoDriverManager().install())20@pytest.fixture()21def driver(request):22 driver = None23 language = request.config.getoption("language")24 browser = request.config.getoption("browser")25 if browser == "chrome":26 driver = create_chrome(language)27 elif browser == "chrome-headless":28 driver = create_chrome(language, headless=True)29 elif browser == "firefox":30 driver = create_firefox()31 else:32 raise pytest.UsageError("--browsers: chrome, chrome-headless, firefox")33 driver.implicitly_wait(5)34 yield driver...

Full Screen

Full Screen

factory_driver.py

Source:factory_driver.py Github

copy

Full Screen

...5def get_driver() -> WebDriver:6 config.load_config()7 browser = config.get_browser_name()8 if browser.lower() == 'chrome':9 driver = create_chrome()10 elif browser.lower() == 'firefox':11 driver = create_firefox()12 else:13 raise ValueError(f'Invalid browser {browser}')14 if config.get_headless_mode():15 driver.set_window_size(**config.get_headless_resolution())16 else:17 driver.maximize_window()18 driver.set_page_load_timeout(config.get_page_load_timeout())19 driver.implicitly_wait(config.get_implicit_wait())...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful