|
16 | 16 | # under the License. |
17 | 17 |
|
18 | 18 | import http.server |
| 19 | +import json |
19 | 20 | import os |
20 | 21 | import socketserver |
21 | 22 | import sys |
@@ -208,6 +209,43 @@ def _resolve_bazel_path(path): |
208 | 209 | return path |
209 | 210 |
|
210 | 211 |
|
| 212 | +# Maps the test driver name to its (browserName, vendor options key). |
| 213 | +_GRID_VENDOR_OPTIONS = { |
| 214 | + "chrome": ("chrome", "goog:chromeOptions"), |
| 215 | + "edge": ("MicrosoftEdge", "ms:edgeOptions"), |
| 216 | + "firefox": ("firefox", "moz:firefoxOptions"), |
| 217 | +} |
| 218 | + |
| 219 | + |
| 220 | +def _pinned_grid_args(config): |
| 221 | + """Pin the driver and browser in a driver-configuration so the Grid node skips Selenium Manager. |
| 222 | +
|
| 223 | + Returns an empty list when nothing is pinned, keeping the default Selenium Manager behavior. |
| 224 | + """ |
| 225 | + drivers_opt = config.option.drivers or [] |
| 226 | + driver = next((d for d in drivers_opt if d.lower() in _GRID_VENDOR_OPTIONS), None) |
| 227 | + executable = config.option.executable # --driver-binary |
| 228 | + binary = config.option.binary # --browser-binary |
| 229 | + if not (driver and executable and binary): |
| 230 | + return [] |
| 231 | + |
| 232 | + driver_path = _resolve_bazel_path(executable).strip("'") |
| 233 | + browser_path = _resolve_bazel_path(binary).strip("'") |
| 234 | + browser_name, vendor_key = _GRID_VENDOR_OPTIONS[driver.lower()] |
| 235 | + stereotype = json.dumps({"browserName": browser_name, vendor_key: {"binary": browser_path}}) |
| 236 | + return [ |
| 237 | + "--enable-managed-downloads", |
| 238 | + "true", |
| 239 | + "--detect-drivers", |
| 240 | + "false", |
| 241 | + "--driver-configuration", |
| 242 | + f"display-name={driver}", |
| 243 | + "max-sessions=1", |
| 244 | + f"webdriver-executable={driver_path}", |
| 245 | + f"stereotype={stereotype}", |
| 246 | + ] |
| 247 | + |
| 248 | + |
211 | 249 | def get_extensions_location(): |
212 | 250 | """Locate the test extensions directory. |
213 | 251 |
|
@@ -551,7 +589,7 @@ def server(request): |
551 | 589 | # under Wayland, so we use XWayland instead. |
552 | 590 | remote_env["MOZ_ENABLE_WAYLAND"] = "0" |
553 | 591 |
|
554 | | - server = Server(env=remote_env, startup_timeout=60) |
| 592 | + server = Server(env=remote_env, startup_timeout=60, args=_pinned_grid_args(request.config) or None) |
555 | 593 |
|
556 | 594 | repo_root = Path(__file__).parent.parent # py/conftest.py -> py/ -> selenium/ |
557 | 595 | jar_path = "java/src/org/openqa/selenium/grid/selenium_server_deploy.jar" |
|
0 commit comments