Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Dec 20, 2023
1 parent 76c034d commit d6c1b88
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sphinxcontrib/typer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ def typer_get_web_driver(directive: TyperDirective) -> t.Any:
:param directive: The TyperDirective instance
"""
import platform

try:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
Expand All @@ -760,61 +761,65 @@ def opts(options=ChromeOptions()):
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1920x1080")
return options

def chrome():
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

return webdriver.Chrome(
service=Service(ChromeDriverManager().install()),
options=opts()
service=Service(ChromeDriverManager().install()), options=opts()
)

def chromium():
from selenium.webdriver.chrome.service import Service as ChromiumService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import ChromeType

return webdriver.Chrome(
service=ChromiumService(
ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()
),
options=opts()
options=opts(),
)

def firefox():
from selenium.webdriver.firefox.options import Options
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager

return webdriver.Firefox(
service=FirefoxService(GeckoDriverManager().install()),
options=opts(Options())
options=opts(Options()),
)

def edge():
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager

options = Options()
options.use_chromium = True
return webdriver.Edge(
service=EdgeService(EdgeChromiumDriverManager().install()),
options=opts(options)
options=opts(options),
)

services = [
chrome,
edge if platform.system().lower() == 'windows' else chromium,
firefox
firefox,
]

driver = None
for service in services:
try:
driver = service()
break # use the first one that works!
except Exception as err:
directive.debug(f'Unable to initialize webdriver {service.__name__}: {err}')
directive.debug(
f'Unable to initialize webdriver {service.__name__}: {err}'
)

if driver:
yield driver
Expand Down

0 comments on commit d6c1b88

Please sign in to comment.