2020-10-09 17:34:54 +00:00
|
|
|
from selenium import webdriver
|
|
|
|
from selenium.webdriver import DesiredCapabilities
|
|
|
|
|
|
|
|
from webdriver_manager.firefox import GeckoDriverManager
|
|
|
|
from webdriver_manager.chrome import ChromeDriverManager
|
|
|
|
|
|
|
|
|
|
|
|
class BrowserDriver:
|
|
|
|
@staticmethod
|
|
|
|
def get(browser=None):
|
|
|
|
if browser == "chrome":
|
|
|
|
return chrome()
|
|
|
|
elif browser == "firefox":
|
|
|
|
return firefox()
|
|
|
|
elif browser == "edge":
|
|
|
|
return edge()
|
|
|
|
elif browser == "safari":
|
|
|
|
return safari()
|
|
|
|
else:
|
|
|
|
raise ValueError("'{}' is not a supported browser".format(browser))
|
|
|
|
|
|
|
|
|
|
|
|
def chrome():
|
|
|
|
options = webdriver.ChromeOptions()
|
2020-10-10 18:04:35 +00:00
|
|
|
options.headless = True
|
2020-10-09 17:34:54 +00:00
|
|
|
options.add_argument('--ignore-certificate-errors')
|
|
|
|
return webdriver.Chrome(ChromeDriverManager().install(), options=options)
|
|
|
|
|
|
|
|
|
|
|
|
def firefox():
|
|
|
|
options = webdriver.FirefoxOptions()
|
|
|
|
options.accept_insecure_certs = True
|
2020-10-10 18:04:35 +00:00
|
|
|
options.headless = True
|
2020-10-09 17:34:54 +00:00
|
|
|
gecko_driver = GeckoDriverManager().install()
|
2020-10-10 18:14:35 +00:00
|
|
|
return webdriver.Firefox(
|
|
|
|
executable_path=gecko_driver,
|
|
|
|
firefox_options=options,
|
|
|
|
firefox_binary="/usr/local/bin/firefox")
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def edge():
|
|
|
|
return webdriver.Edge(DesiredCapabilities.EDGE)
|
|
|
|
|
|
|
|
|
|
|
|
def safari():
|
|
|
|
# Because safari driver is bundled with safari
|
|
|
|
return webdriver.Safari()
|