add webdriver option arguments via env (#2783)

* add webdriver option arguments via env

* forgot to split the args
This commit is contained in:
benedikt-bartscher 2024-03-07 02:13:40 +01:00 committed by GitHub
parent ecb4dbaea9
commit 8903ebb8b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -49,6 +49,9 @@ try:
)
if TYPE_CHECKING:
from selenium.webdriver.common.options import (
ArgOptions, # pyright: ignore [reportMissingImports]
)
from selenium.webdriver.remote.webelement import ( # pyright: ignore [reportMissingImports]
WebElement,
)
@ -485,12 +488,13 @@ class AppHarness:
if self.frontend_url is None:
raise RuntimeError("Frontend is not running.")
want_headless = False
options = None
options: ArgOptions | None = None
if os.environ.get("APP_HARNESS_HEADLESS"):
want_headless = True
if driver_clz is None:
requested_driver = os.environ.get("APP_HARNESS_DRIVER", "Chrome")
driver_clz = getattr(webdriver, requested_driver)
options = webdriver.ChromeOptions()
if driver_clz is webdriver.Chrome and want_headless:
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
@ -500,6 +504,9 @@ class AppHarness:
elif driver_clz is webdriver.Edge and want_headless:
options = webdriver.EdgeOptions()
options.add_argument("headless")
if options and (args := os.environ.get("APP_HARNESS_DRIVER_ARGS")):
for arg in args.split(","):
options.add_argument(arg)
driver = driver_clz(options=options) # type: ignore
driver.get(self.frontend_url)
self._frontends.append(driver)