2020-10-09 17:34:54 +00:00
|
|
|
from selenium import webdriver
|
|
|
|
|
2020-10-10 22:27:46 +00:00
|
|
|
from msedge.selenium_tools import Edge, EdgeOptions
|
2020-10-09 17:34:54 +00:00
|
|
|
from webdriver_manager.firefox import GeckoDriverManager
|
|
|
|
from webdriver_manager.chrome import ChromeDriverManager
|
2020-10-10 22:27:46 +00:00
|
|
|
from webdriver_manager.microsoft import EdgeChromiumDriverManager
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BrowserDriver:
|
|
|
|
@staticmethod
|
2020-10-10 21:40:06 +00:00
|
|
|
def get(browser=None, headless=True):
|
2020-10-09 17:34:54 +00:00
|
|
|
if browser == "chrome":
|
2020-10-10 21:40:06 +00:00
|
|
|
return chrome(headless)
|
2020-10-09 17:34:54 +00:00
|
|
|
elif browser == "firefox":
|
2020-10-10 21:40:06 +00:00
|
|
|
return firefox(headless)
|
2020-10-09 17:34:54 +00:00
|
|
|
elif browser == "edge":
|
2020-10-10 22:27:46 +00:00
|
|
|
return edge(headless)
|
2020-10-09 17:34:54 +00:00
|
|
|
elif browser == "safari":
|
|
|
|
return safari()
|
|
|
|
else:
|
|
|
|
raise ValueError("'{}' is not a supported browser".format(browser))
|
|
|
|
|
|
|
|
|
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')
|
2020-10-10 21:40:06 +00:00
|
|
|
return webdriver.Chrome(
|
|
|
|
ChromeDriverManager().install(),
|
|
|
|
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
|
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,
|
2020-10-10 21:40:06 +00:00
|
|
|
options=options)
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
2020-10-10 22:27:46 +00:00
|
|
|
def edge(headless=True):
|
|
|
|
options = EdgeOptions()
|
|
|
|
options.use_chromium = True
|
|
|
|
options.headless = headless
|
|
|
|
edge_driver = EdgeChromiumDriverManager().install()
|
|
|
|
driver = Edge(edge_driver, options=options)
|
|
|
|
return driver
|
2020-10-09 17:34:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def safari():
|
|
|
|
# Because safari driver is bundled with safari
|
|
|
|
return webdriver.Safari()
|