(request, server)
| 492 | |
| 493 | @pytest.fixture |
| 494 | def driver(request, server): |
| 495 | global selenium_driver |
| 496 | driver_class = getattr(request, "param", "Chrome").lower() |
| 497 | |
| 498 | if selenium_driver is None: |
| 499 | selenium_driver = Driver(driver_class, request) |
| 500 | if server: |
| 501 | selenium_driver._server = server |
| 502 | |
| 503 | # skip tests if not available on the platform |
| 504 | if not selenium_driver.is_platform_valid: |
| 505 | pytest.skip(f"{driver_class} tests can only run on {selenium_driver.exe_platform}") |
| 506 | |
| 507 | # skip tests in the 'remote' directory if not running with --remote flag |
| 508 | if request.node.path.parts[-2] == "remote" and not selenium_driver.is_remote: |
| 509 | pytest.skip("Remote tests require the --remote flag") |
| 510 | |
| 511 | # skip tests for drivers that don't support BiDi when --bidi is enabled |
| 512 | if selenium_driver.bidi: |
| 513 | if driver_class.lower() not in selenium_driver.supported_bidi_drivers: |
| 514 | pytest.skip(f"{driver_class} does not support BiDi") |
| 515 | |
| 516 | # conditionally mark tests as expected to fail based on driver |
| 517 | marker = request.node.get_closest_marker(f"xfail_{driver_class.lower()}") |
| 518 | # Also check for xfail_remote when running with --remote |
| 519 | if marker is None and selenium_driver.is_remote: |
| 520 | marker = request.node.get_closest_marker("xfail_remote") |
| 521 | if marker is not None: |
| 522 | kwargs = dict(marker.kwargs) |
| 523 | # Support condition kwarg - if condition is False, skip the xfail |
| 524 | condition = kwargs.pop("condition", True) |
| 525 | if callable(condition): |
| 526 | condition = condition() |
| 527 | if condition: |
| 528 | if "run" in kwargs: |
| 529 | if not kwargs["run"]: |
| 530 | pytest.skip() |
| 531 | yield |
| 532 | return |
| 533 | kwargs.pop("raises", None) |
| 534 | pytest.xfail(**kwargs) |
| 535 | |
| 536 | # For BiDi tests, only restart driver when explicitly marked as needing fresh driver. |
| 537 | # Tests marked with @pytest.mark.needs_fresh_driver get full driver restart for test isolation. |
| 538 | # Cleanup after every test is recommended. |
| 539 | if selenium_driver is not None and selenium_driver.bidi: |
| 540 | if request.node.get_closest_marker("needs_fresh_driver"): |
| 541 | request.addfinalizer(selenium_driver.stop_driver) |
| 542 | else: |
| 543 | |
| 544 | def ensure_valid_window(): |
| 545 | try: |
| 546 | driver = selenium_driver._driver |
| 547 | if driver: |
| 548 | try: |
| 549 | # Check if current window is still valid |
| 550 | driver.current_window_handle |
| 551 | except Exception: |
nothing calls this directly
no test coverage detected