-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
36 lines (30 loc) · 1.36 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.firefox.options import Options as FirefoxOptions
def pytest_addoption(parser):
parser.addoption('--browser_name', action='store', default="chrome",
help="Choose browser: chrome or firefox")
parser.addoption('--language', action='store', default="en",
help="Choose one language from: ru, en, es")
@pytest.fixture(scope="function")
def browser(request):
browser_name = request.config.getoption("browser_name")
browser = None
user_language = request.config.getoption("language")
if browser_name == "chrome":
print("\nstart chrome browser for test..")
options = ChromeOptions()
# options.add_argument("--headless")
options.add_experimental_option('prefs', {'intl.accept_languages': user_language})
browser = webdriver.Chrome(options=options)
elif browser_name == "firefox":
print("\nstart firefox browser for test..")
options = FirefoxOptions()
options.set_preference("intl.accept_languages", user_language)
browser = webdriver.Firefox(options=options)
else:
raise pytest.UsageError("--browser_name should be chrome or firefox")
yield browser
print("\nquit browser..")
browser.quit()