Skip to content

Commit cb1694f

Browse files
committed
[py] Use pinned browser and driver for remote Grid tests instead of Selenium Manager
1 parent e4eac88 commit cb1694f

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

py/conftest.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
import http.server
19+
import json
1920
import os
2021
import socketserver
2122
import sys
@@ -208,6 +209,43 @@ def _resolve_bazel_path(path):
208209
return path
209210

210211

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+
211249
def get_extensions_location():
212250
"""Locate the test extensions directory.
213251
@@ -551,7 +589,7 @@ def server(request):
551589
# under Wayland, so we use XWayland instead.
552590
remote_env["MOZ_ENABLE_WAYLAND"] = "0"
553591

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)
555593

556594
repo_root = Path(__file__).parent.parent # py/conftest.py -> py/ -> selenium/
557595
jar_path = "java/src/org/openqa/selenium/grid/selenium_server_deploy.jar"

py/selenium/webdriver/remote/server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ class Server:
4444
Available levels: "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST".
4545
env: Mapping that defines the environment variables for the server process.
4646
java_path: Path to the java executable to run the server.
47+
args: Arguments for the standalone server command. Defaults to enabling Selenium
48+
Manager and managed downloads; pass a list to override these entirely (e.g. to
49+
pin drivers with "--driver-configuration").
4750
"""
4851

52+
DEFAULT_ARGS = ("--selenium-manager", "true", "--enable-managed-downloads", "true")
53+
4954
def __init__(
5055
self,
5156
host=None,
@@ -56,6 +61,7 @@ def __init__(
5661
env=None,
5762
java_path=None,
5863
startup_timeout=10,
64+
args=None,
5965
):
6066
if path and version:
6167
raise TypeError("Not allowed to specify a version when using an existing server path")
@@ -68,6 +74,7 @@ def __init__(
6874
self.env = env
6975
self.java_path = java_path
7076
self.startup_timeout = startup_timeout
77+
self.args = list(args) if args is not None else list(self.DEFAULT_ARGS)
7178
self.process = None
7279

7380
@property
@@ -190,10 +197,7 @@ def start(self):
190197
str(self.port),
191198
"--log-level",
192199
self.log_level,
193-
"--selenium-manager",
194-
"true",
195-
"--enable-managed-downloads",
196-
"true",
200+
*self.args,
197201
]
198202
if self.host is not None:
199203
command.extend(["--host", self.host])

0 commit comments

Comments
 (0)