-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
64 lines (53 loc) · 1.79 KB
/
conftest.py
File metadata and controls
64 lines (53 loc) · 1.79 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
import config
def pytest_addoption(parser):
parser.addoption(
"--browser",
action="store",
default=config.BROWSER,
choices=["chrome", "firefox"],
help="Browser to run tests with (default: chrome)",
)
parser.addoption(
"--headless",
action="store_true",
default=False,
help="Run browser in headless mode",
)
@pytest.fixture(scope="session")
def browser_name(request):
return request.config.getoption("--browser")
@pytest.fixture(scope="session")
def headless(request):
return request.config.getoption("--headless")
@pytest.fixture
def driver(browser_name, headless):
if browser_name == "firefox":
options = webdriver.FirefoxOptions()
if headless:
options.add_argument("--headless")
drv = webdriver.Firefox(
service=FirefoxService(GeckoDriverManager().install()),
options=options,
)
else:
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
if headless:
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
drv = webdriver.Chrome(
service=ChromeService(ChromeDriverManager().install()),
options=options,
)
drv.implicitly_wait(config.IMPLICIT_WAIT)
drv.set_page_load_timeout(config.PAGE_LOAD_TIMEOUT)
drv.maximize_window()
yield drv
drv.quit()