| 602 | |
| 603 | @pytest.fixture(autouse=True, scope="session") |
| 604 | def server(request): |
| 605 | is_remote = request.config.getoption("remote") |
| 606 | if not is_remote: |
| 607 | yield None |
| 608 | return |
| 609 | |
| 610 | remote_env = os.environ.copy() |
| 611 | if sys.platform == "linux": |
| 612 | # There are issues with window size/position when running Firefox |
| 613 | # under Wayland, so we use XWayland instead. |
| 614 | remote_env["MOZ_ENABLE_WAYLAND"] = "0" |
| 615 | |
| 616 | server = Server(env=remote_env, startup_timeout=60, args=_pinned_grid_args(request.config) or None) |
| 617 | |
| 618 | repo_root = Path(__file__).parent.parent # py/conftest.py -> py/ -> selenium/ |
| 619 | jar_path = "java/src/org/openqa/selenium/grid/selenium_server_deploy.jar" |
| 620 | |
| 621 | if Path(jar_path).exists(): |
| 622 | # Found in runfiles (bazel test) - relative to cwd |
| 623 | server.path = jar_path |
| 624 | elif (repo_root / "bazel-bin" / jar_path).exists(): |
| 625 | # Found in bazel-bin relative to repo root (pytest from anywhere) |
| 626 | server.path = str(repo_root / "bazel-bin" / jar_path) |
| 627 | |
| 628 | java_location_env = os.environ.get("SE_BAZEL_JAVA_LOCATION") |
| 629 | if Runfiles is not None and java_location_env: |
| 630 | # Find bazel's Java |
| 631 | r = Runfiles.Create() |
| 632 | java_location_txt = r.Rlocation("_main/" + java_location_env) |
| 633 | try: |
| 634 | rel_path = Path(java_location_txt).read_text().strip().removeprefix("external/") |
| 635 | java_path = r.Rlocation(rel_path) |
| 636 | if sys.platform == "win32" and java_path and os.path.exists(java_path): |
| 637 | java_path = os.path.realpath(java_path) |
| 638 | server.java_path = java_path |
| 639 | except Exception: |
| 640 | pass |
| 641 | |
| 642 | server.port = free_port() |
| 643 | server.start() |
| 644 | yield server |
| 645 | server.stop() |
| 646 | |
| 647 | |
| 648 | @pytest.fixture(autouse=True, scope="session") |