-
Notifications
You must be signed in to change notification settings - Fork 3
/
fixtures_browsers.py
103 lines (87 loc) · 3.29 KB
/
fixtures_browsers.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import logging
import pytest
from selene import Browser, Config
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
@pytest.fixture(scope='function')
def browser_func(choose_driver):
"""Browser that closes after each test function or method."""
yield choose_driver
choose_driver.quit()
@pytest.fixture(scope='class')
def browser_class(choose_driver):
"""Browser that closes after each test class."""
yield choose_driver
choose_driver.quit()
@pytest.fixture(scope='module')
def browser_module(choose_driver):
"""Browser that closes after each test module."""
yield choose_driver
choose_driver.quit()
@pytest.fixture(scope='session')
def choose_driver(is_remote, t_browser):
"""Remote or local browser selector fixture."""
if is_remote:
return remote_driver(t_browser)
return custom_driver(t_browser)
def custom_driver(t_browser):
""" Custom driver """
logging.debug('custom driver config start')
if t_browser == 'chrome':
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(),
options=headless_chrome_options())
else:
raise ValueError('t_browser does not set')
driver.set_page_load_timeout(10)
browser = Browser(Config(
driver=driver,
timeout=10,
window_width=1366,
window_height=1200,
))
logging.debug('custom driver config finish')
return browser
def headless_chrome_options():
""" Custom chrome options """
logging.info('set chromedriver options start')
chrome_options = Options()
chrome_options.set_capability("pageLoadStrategy", "eager")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--enable-automation")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-setuid-sandbox")
logging.info('set chromedriver options finish')
return chrome_options
def remote_driver(t_browser, page_load_strategy=None):
""" Remote driver """
logging.debug('remote driver config start')
remote_mapping = {
'chrome': {
'command_executor': 'http://selenium__standalone-chrome:4444/wd/hub',
'options': webdriver.ChromeOptions()
},
'firefox': {
'command_executor': 'http://selenium__standalone-firefox:4444/wd/hub',
'options': webdriver.FirefoxOptions()
}
}
if page_load_strategy:
desired_capabilities = webdriver.DesiredCapabilities().CHROME
desired_capabilities["pageLoadStrategy"] = "eager"
driver = webdriver.Remote(command_executor=remote_mapping[t_browser]['command_executor'],
options=remote_mapping[t_browser]['options'])
driver.set_page_load_timeout(20)
browser = Browser(Config(
driver=driver,
timeout=10,
window_width=1500,
window_height=1200,
))
logging.debug('remote driver config finish')
return browser