-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathdriver_factory.py
43 lines (41 loc) · 1.8 KB
/
driver_factory.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
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from helpers.webdriver_listener import WebDriverListener
from msedge.selenium_tools import EdgeOptions, Edge
from extensions.webdriver_extended import WebDriverExtended
class DriverFactory:
@staticmethod
def get_driver(config) -> WebDriverExtended:
if config["browser"] == "chrome":
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
if config["headless_mode"] is True:
options.add_argument("--headless")
driver = WebDriverExtended(
webdriver.Chrome(ChromeDriverManager().install(), options=options),
WebDriverListener(), config
)
return driver
elif config["browser"] == "firefox":
options = webdriver.FirefoxOptions()
if config["headless_mode"] is True:
options.headless = True
driver = WebDriverExtended(
webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=options),
WebDriverListener(), config
)
return driver
elif config["browser"] == "edge":
options = EdgeOptions()
options.use_chromium = True
if config["headless_mode"] is True:
options.headless = True
driver_path = EdgeChromiumDriverManager().install()
driver = WebDriverExtended(
Edge(executable_path=driver_path, options=options),
WebDriverListener(), config
)
return driver
raise Exception("Provide valid driver name")