| 658 | |
| 659 | @pytest.fixture(autouse=True, scope="session") |
| 660 | def server(request): |
| 661 | is_remote = request.config.getoption("remote") |
| 662 | if not is_remote: |
| 663 | yield None |
| 664 | return |
| 665 | |
| 666 | remote_env = os.environ.copy() |
| 667 | if sys.platform == "linux": |
| 668 | # There are issues with window size/position when running Firefox |
| 669 | # under Wayland, so we use XWayland instead. |
| 670 | remote_env["MOZ_ENABLE_WAYLAND"] = "0" |
| 671 | |
| 672 | server = Server(env=remote_env, startup_timeout=60, args=_pinned_grid_args(request.config) or None) |
| 673 | |
| 674 | repo_root = Path(__file__).parent.parent # py/conftest.py -> py/ -> selenium/ |
| 675 | jar_path = "java/src/org/openqa/selenium/grid/selenium_server_deploy.jar" |
| 676 | |
| 677 | if Path(jar_path).exists(): |
| 678 | # Found in runfiles (bazel test) - relative to cwd |
| 679 | server.path = jar_path |
| 680 | elif (repo_root / "bazel-bin" / jar_path).exists(): |
| 681 | # Found in bazel-bin relative to repo root (pytest from anywhere) |
| 682 | server.path = str(repo_root / "bazel-bin" / jar_path) |
| 683 | |
| 684 | java_location_env = os.environ.get("SE_BAZEL_JAVA_LOCATION") |
| 685 | if Runfiles is not None and java_location_env: |
| 686 | # Find bazel's Java |
| 687 | r = Runfiles.Create() |
| 688 | java_location_txt = r.Rlocation("_main/" + java_location_env) |
| 689 | try: |
| 690 | rel_path = Path(java_location_txt).read_text().strip().removeprefix("external/") |
| 691 | java_path = r.Rlocation(rel_path) |
| 692 | if sys.platform == "win32" and java_path and os.path.exists(java_path): |
| 693 | java_path = os.path.realpath(java_path) |
| 694 | server.java_path = java_path |
| 695 | except Exception: |
| 696 | pass |
| 697 | |
| 698 | server.port = free_port() |
| 699 | server.start() |
| 700 | yield server |
| 701 | server.stop() |
| 702 | |
| 703 | |
| 704 | @pytest.fixture(autouse=True, scope="session") |