behave-framework/browserdriver/__init__.py

55 lines
1.5 KiB
Python
Raw Normal View History

from selenium import webdriver
2020-10-10 22:27:46 +00:00
from msedge.selenium_tools import Edge, EdgeOptions
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
class BrowserDriver:
@staticmethod
def get(browser=None, headless=True):
if browser == "chrome":
return chrome(headless)
elif browser == "firefox":
return firefox(headless)
elif browser == "edge":
2020-10-10 22:27:46 +00:00
return edge(headless)
elif browser == "safari":
return safari()
else:
raise ValueError("'{}' is not a supported browser".format(browser))
def chrome(headless=True):
options = webdriver.ChromeOptions()
options.headless = headless
options.add_argument('--ignore-certificate-errors')
return webdriver.Chrome(
ChromeDriverManager().install(),
options=options)
def firefox(headless=True):
options = webdriver.FirefoxOptions()
options.accept_insecure_certs = True
options.headless = headless
gecko_driver = GeckoDriverManager().install()
2020-10-10 18:14:35 +00:00
return webdriver.Firefox(
executable_path=gecko_driver,
options=options)
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
def safari():
# Because safari driver is bundled with safari
return webdriver.Safari()