48 lines
1.4 KiB
Python
Executable File
48 lines
1.4 KiB
Python
Executable File
# pylint: disable=too-few-public-methods
|
|
from selenium import webdriver
|
|
from selenium.webdriver.chrome.options import Options as ChromeOptions
|
|
from selenium.webdriver.firefox.options import Options as FirefoxOptions
|
|
from selenium.webdriver.edge.options import Options as EdgeOptions
|
|
|
|
|
|
class BrowserDriver:
|
|
|
|
@staticmethod
|
|
def get(browser=None, headless=True):
|
|
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")
|
|
|
|
|
|
def chrome(headless=True):
|
|
options = ChromeOptions()
|
|
if headless:
|
|
options.add_argument("--headless")
|
|
options.add_argument('--ignore-certificate-errors')
|
|
return webdriver.Chrome(options=options)
|
|
|
|
|
|
def firefox(headless=True):
|
|
options = FirefoxOptions()
|
|
if headless:
|
|
options.add_argument("--headless")
|
|
options.accept_insecure_certs = True
|
|
return webdriver.Firefox(options=options)
|
|
|
|
|
|
def edge(headless=True):
|
|
options = EdgeOptions()
|
|
options.use_chromium = True
|
|
options.add_argument('disable-gpu')
|
|
if headless:
|
|
options.add_argument('headless')
|
|
return webdriver.Edge(options=options)
|
|
|
|
|
|
def safari():
|
|
# Because safari driver is bundled with safari
|
|
return webdriver.Safari()
|