-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
38 lines (31 loc) · 1.38 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
37
38
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def pytest_addoption(parser):
# parser.addoption('--browser_name', action='store', default=None,
# help="Choose browser: chrome or firefox")
# Ïîñòàâèì ïî óìîë÷àíèþ Õðîì
parser.addoption('--browser_name', action='store', default="chrome",
help="Choose browser: chrome or firefox")
parser.addoption('--language', action='store', default=None,
help="Choose language: en, ru...etc.")
@pytest.fixture(scope="function")
def browser(request):
browser_name = request.config.getoption("browser_name")
user_language = request.config.getoption("language")
browser = None
if browser_name == "chrome":
options = Options()
options.add_experimental_option('prefs', {'intl.accept_languages': user_language})
print("\nStart chrome browser for test..")
browser = webdriver.Chrome(options=options)
elif browser_name == "firefox":
fp = webdriver.FirefoxProfile()
fp.set_preference("intl.accept_languages", user_language)
print("\nStart firefox browser for test..")
browser = webdriver.Firefox(firefox_profile=fp)
else:
raise pytest.UsageError("Please set all required options")
yield browser
print("\nQuit browser..")
browser.quit()