2024-07-23 14:00:35 +00:00
|
|
|
# pylint: disable=too-few-public-methods
|
2020-10-09 17:34:54 +00:00
|
|
|
from selenium import webdriver
|
|
|
|
|
|
|
|
|
|
|
|
class BrowserDriver:
|
2024-07-23 14:00:35 +00:00
|
|
|
|
2020-10-09 17:34:54 +00:00
|
|
|
@staticmethod
|
2020-10-10 21:40:06 +00:00
|
|
|
def get(browser=None, headless=True):
|
2024-07-23 14:00:35 +00:00
|
|
|
valid_browsers = ['chrome', 'firefox', 'safari', 'edge']
|
|
|
|
if browser in valid_browsers:
|
|
|
|
browser_method = globals()[browser]
|
|
|
|
return browser_method(headless)
|
|
|
|
|
|
|
|
raise ValueError(f"'{browser}' is not a supported browser")
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
2020-10-10 21:40:06 +00:00
|
|
|
def chrome(headless=True):
|
2020-10-09 17:34:54 +00:00
|
|
|
options = webdriver.ChromeOptions()
|
2020-10-10 21:40:06 +00:00
|
|
|
options.headless = headless
|
2020-10-09 17:34:54 +00:00
|
|
|
options.add_argument('--ignore-certificate-errors')
|
2024-07-23 14:00:35 +00:00
|
|
|
return webdriver.Chrome(options=options)
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
2020-10-10 21:40:06 +00:00
|
|
|
def firefox(headless=True):
|
2020-10-09 17:34:54 +00:00
|
|
|
options = webdriver.FirefoxOptions()
|
|
|
|
options.accept_insecure_certs = True
|
2020-10-10 21:40:06 +00:00
|
|
|
options.headless = headless
|
2024-07-23 14:48:03 +00:00
|
|
|
options.add_argument('--ignore-certificate-errors')
|
2024-07-23 14:00:35 +00:00
|
|
|
return webdriver.Firefox(options=options)
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
2020-10-10 22:27:46 +00:00
|
|
|
def edge(headless=True):
|
2024-07-23 14:00:35 +00:00
|
|
|
options = webdriver.EdgeOptions()
|
2020-10-10 22:27:46 +00:00
|
|
|
options.use_chromium = True
|
|
|
|
options.headless = headless
|
2024-07-23 14:00:35 +00:00
|
|
|
driver = webdriver.Edge(options=options)
|
2020-10-10 22:27:46 +00:00
|
|
|
return driver
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def safari():
|
|
|
|
# Because safari driver is bundled with safari
|
|
|
|
return webdriver.Safari()
|