Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add webdriver option arguments via env #2783

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion reflex/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
)

if TYPE_CHECKING:
from selenium.webdriver.common.options import (
ArgOptions, # pyright: ignore [reportMissingImports]
)
from selenium.webdriver.remote.webelement import ( # pyright: ignore [reportMissingImports]
WebElement,
)
Expand Down Expand Up @@ -485,12 +488,13 @@ def frontend(self, driver_clz: Optional[Type["WebDriver"]] = None) -> "WebDriver
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")
Expand All @@ -500,6 +504,9 @@ def frontend(self, driver_clz: Optional[Type["WebDriver"]] = None) -> "WebDriver
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)
Expand Down
Loading