diff --git a/.skipped-tests b/.skipped-tests index 7a58b02f42aaf..529d77884302b 100644 --- a/.skipped-tests +++ b/.skipped-tests @@ -27,11 +27,6 @@ -//javascript/selenium-webdriver:test-chrome-service-test.js-chrome -//javascript/selenium-webdriver:test-firefox-options-test.js-firefox -//javascript/selenium-webdriver:test-lib-capabilities-test.js-chrome --//py:test-chrome-test/selenium/webdriver/chrome/chrome_launcher_tests.py --//py:test-chrome-test/selenium/webdriver/chrome/chrome_service_tests.py --//py:test-chrome-test/selenium/webdriver/chrome/proxy_tests.py --//py:test-edge-test/selenium/webdriver/edge/edge_launcher_tests.py --//py:test-edge-test/selenium/webdriver/edge/edge_service_tests.py -//rb/spec/integration/selenium/webdriver/chrome:service-chrome -//rb/spec/integration/selenium/webdriver/chrome:service-chrome-bidi -//rb/spec/integration/selenium/webdriver/chrome:service-chrome-remote diff --git a/py/conftest.py b/py/conftest.py index 3cc2693259515..5e674bc6d1dba 100644 --- a/py/conftest.py +++ b/py/conftest.py @@ -213,11 +213,10 @@ def get_options(driver_class, config): browser_args = config.option.args headless = config.option.headless bidi = config.option.bidi - options = None + + options = getattr(webdriver, f"{driver_class}Options")() if browser_path or browser_args: - if not options: - options = getattr(webdriver, f"{driver_class}Options")() if driver_class == "WebKitGTK": options.overlay_scrollbars_enabled = False if browser_path is not None: @@ -227,16 +226,12 @@ def get_options(driver_class, config): options.add_argument(arg) if headless: - if not options: - options = getattr(webdriver, f"{driver_class}Options")() if driver_class == "Chrome" or driver_class == "Edge": options.add_argument("--headless=new") if driver_class == "Firefox": options.add_argument("-headless") if bidi: - if not options: - options = getattr(webdriver, f"{driver_class}Options")() options.web_socket_url = True options.unhandled_prompt_behavior = "ignore" @@ -336,30 +331,30 @@ def driver_executable(request): return request.config.option.executable -@pytest.fixture(scope="function") -def clean_service(request): - try: - driver_class = get_driver_class(request.config.option.drivers[0]) - except (AttributeError, TypeError): - raise Exception("This test requires a --driver to be specified") - - yield get_service(driver_class, request.config.option.executable) - - @pytest.fixture(scope="function") def clean_driver(request): try: driver_class = get_driver_class(request.config.option.drivers[0]) except (AttributeError, TypeError): raise Exception("This test requires a --driver to be specified") - driver_reference = getattr(webdriver, driver_class) yield driver_reference - if request.node.get_closest_marker("no_driver_after_test"): driver_reference = None +@pytest.fixture(scope="function") +def clean_service(request): + driver_class = get_driver_class(request.config.option.drivers[0]) + yield get_service(driver_class, request.config.option.executable) + + +@pytest.fixture(scope="function") +def clean_options(request): + driver_class = get_driver_class(request.config.option.drivers[0]) + yield get_options(driver_class, request.config) + + @pytest.fixture def firefox_options(request): try: diff --git a/py/test/selenium/webdriver/chrome/chrome_launcher_tests.py b/py/test/selenium/webdriver/chrome/chrome_launcher_tests.py index 95a22785f9420..c2bdd370e8b2d 100644 --- a/py/test/selenium/webdriver/chrome/chrome_launcher_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_launcher_tests.py @@ -19,16 +19,16 @@ @pytest.mark.no_driver_after_test -def test_launch_and_close_browser(clean_driver, clean_service): - driver = clean_driver(service=clean_service) +def test_launch_and_close_browser(clean_driver, clean_options, clean_service): + driver = clean_driver(options=clean_options, service=clean_service) driver.quit() @pytest.mark.no_driver_after_test -def test_we_can_launch_multiple_chrome_instances(clean_driver, clean_service): - driver1 = clean_driver(service=clean_service) - driver2 = clean_driver(service=clean_service) - driver3 = clean_driver(service=clean_service) +def test_we_can_launch_multiple_chrome_instances(clean_driver, clean_options, clean_service): + driver1 = clean_driver(options=clean_options, service=clean_service) + driver2 = clean_driver(options=clean_options, service=clean_service) + driver3 = clean_driver(options=clean_options, service=clean_service) driver1.quit() driver2.quit() driver3.quit() diff --git a/py/test/selenium/webdriver/chrome/chrome_service_tests.py b/py/test/selenium/webdriver/chrome/chrome_service_tests.py index 345f6b5d1bfdd..fc110921cfd1d 100644 --- a/py/test/selenium/webdriver/chrome/chrome_service_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_service_tests.py @@ -23,12 +23,11 @@ import pytest from selenium.common.exceptions import SessionNotCreatedException -from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service @pytest.mark.no_driver_after_test -def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None: +def test_uses_chromedriver_logging(clean_driver, clean_options, driver_executable) -> None: log_file = "chromedriver.log" service_args = ["--append-log"] @@ -47,10 +46,10 @@ def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None: driver1 = None driver2 = None try: - driver1 = clean_driver(service=service1) + driver1 = clean_driver(options=clean_options, service=service1) with open(log_file) as fp: lines = len(fp.readlines()) - driver2 = clean_driver(service=service2) + driver2 = clean_driver(options=clean_options, service=service2) with open(log_file) as fp: assert len(fp.readlines()) >= 2 * lines finally: @@ -62,12 +61,12 @@ def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None: @pytest.mark.no_driver_after_test -def test_log_output_as_filename(clean_driver, driver_executable) -> None: +def test_log_output_as_filename(clean_driver, clean_options, driver_executable) -> None: log_file = "chromedriver.log" service = Service(log_output=log_file, executable_path=driver_executable) try: assert "--log-path=chromedriver.log" in service.service_args - driver = clean_driver(service=service) + driver = clean_driver(options=clean_options, service=service) with open(log_file) as fp: assert "Starting ChromeDriver" in fp.readline() finally: @@ -76,12 +75,12 @@ def test_log_output_as_filename(clean_driver, driver_executable) -> None: @pytest.mark.no_driver_after_test -def test_log_output_as_file(clean_driver, driver_executable) -> None: +def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> None: log_name = "chromedriver.log" log_file = open(log_name, "w", encoding="utf-8") service = Service(log_output=log_file, executable_path=driver_executable) try: - driver = clean_driver(service=service) + driver = clean_driver(options=clean_options, service=service) time.sleep(1) with open(log_name) as fp: assert "Starting ChromeDriver" in fp.readline() @@ -92,9 +91,9 @@ def test_log_output_as_file(clean_driver, driver_executable) -> None: @pytest.mark.no_driver_after_test -def test_log_output_as_stdout(clean_driver, capfd, driver_executable) -> None: +def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executable) -> None: service = Service(log_output=subprocess.STDOUT, executable_path=driver_executable) - driver = clean_driver(service=service) + driver = clean_driver(options=clean_options, service=service) out, err = capfd.readouterr() assert "Starting ChromeDriver" in out @@ -109,12 +108,11 @@ def test_log_output_null_default(driver, capfd) -> None: @pytest.mark.no_driver_after_test -def test_driver_is_stopped_if_browser_cant_start(clean_driver) -> None: - options = Options() - options.add_argument("--user-data-dir=/no/such/location") - service = Service() +def test_driver_is_stopped_if_browser_cant_start(clean_driver, clean_options, driver_executable) -> None: + clean_options.add_argument("--user-data-dir=/no/such/location") + service = Service(executable_path=driver_executable) with pytest.raises(SessionNotCreatedException): - clean_driver(options=options, service=service) + clean_driver(options=clean_options, service=service) assert not service.is_connectable() assert service.process.poll() is not None diff --git a/py/test/selenium/webdriver/chrome/proxy_tests.py b/py/test/selenium/webdriver/chrome/proxy_tests.py index 10454e4285f1f..ee5071c39cccf 100644 --- a/py/test/selenium/webdriver/chrome/proxy_tests.py +++ b/py/test/selenium/webdriver/chrome/proxy_tests.py @@ -20,17 +20,13 @@ import pytest import urllib3 -from selenium import webdriver - @pytest.mark.no_driver_after_test -def test_bad_proxy_doesnt_interfere(clean_driver, clean_service): +def test_bad_proxy_doesnt_interfere(clean_driver, clean_options, clean_service): # Proxy environment variables should be ignored if # ignore_local_proxy_environment_variables() is called. - - options = webdriver.ChromeOptions() - options.ignore_local_proxy_environment_variables() - chrome_kwargs = {"options": options, "service": clean_service} + clean_options.ignore_local_proxy_environment_variables() + chrome_kwargs = {"options": clean_options, "service": clean_service} with patch.dict("os.environ", {"http_proxy": "bad", "https_proxy": "bad"}): driver = clean_driver(**chrome_kwargs) assert hasattr(driver, "command_executor") diff --git a/py/test/selenium/webdriver/edge/edge_launcher_tests.py b/py/test/selenium/webdriver/edge/edge_launcher_tests.py index f928054a2c725..65a80971f81bd 100644 --- a/py/test/selenium/webdriver/edge/edge_launcher_tests.py +++ b/py/test/selenium/webdriver/edge/edge_launcher_tests.py @@ -19,16 +19,16 @@ @pytest.mark.no_driver_after_test -def test_launch_and_close_browser(clean_driver, clean_service): - driver = clean_driver(service=clean_service) +def test_launch_and_close_browser(clean_driver, clean_options, clean_service): + driver = clean_driver(options=clean_options, service=clean_service) driver.quit() @pytest.mark.no_driver_after_test -def test_we_can_launch_multiple_edge_instances(clean_driver, clean_service): - driver1 = clean_driver(service=clean_service) - driver2 = clean_driver(service=clean_service) - driver3 = clean_driver(service=clean_service) +def test_we_can_launch_multiple_edge_instances(clean_driver, clean_options, clean_service): + driver1 = clean_driver(options=clean_options, service=clean_service) + driver2 = clean_driver(options=clean_options, service=clean_service) + driver3 = clean_driver(options=clean_options, service=clean_service) driver1.quit() driver2.quit() driver3.quit() diff --git a/py/test/selenium/webdriver/edge/edge_service_tests.py b/py/test/selenium/webdriver/edge/edge_service_tests.py index 2ac1f0e2c6e2c..af449b3ddfbb7 100644 --- a/py/test/selenium/webdriver/edge/edge_service_tests.py +++ b/py/test/selenium/webdriver/edge/edge_service_tests.py @@ -23,12 +23,11 @@ import pytest from selenium.common.exceptions import SessionNotCreatedException -from selenium.webdriver.edge.options import Options from selenium.webdriver.edge.service import Service @pytest.mark.no_driver_after_test -def test_uses_edgedriver_logging(clean_driver, driver_executable) -> None: +def test_uses_edgedriver_logging(clean_driver, clean_options, driver_executable) -> None: log_file = "msedgedriver.log" service_args = ["--append-log"] @@ -47,10 +46,10 @@ def test_uses_edgedriver_logging(clean_driver, driver_executable) -> None: driver1 = None driver2 = None try: - driver1 = clean_driver(service=service1) + driver1 = clean_driver(options=clean_options, service=service1) with open(log_file) as fp: lines = len(fp.readlines()) - driver2 = clean_driver(service=service2) + driver2 = clean_driver(options=clean_options, service=service2) with open(log_file) as fp: assert len(fp.readlines()) >= 2 * lines finally: @@ -62,12 +61,12 @@ def test_uses_edgedriver_logging(clean_driver, driver_executable) -> None: @pytest.mark.no_driver_after_test -def test_log_output_as_filename(clean_driver, driver_executable) -> None: +def test_log_output_as_filename(clean_driver, clean_options, driver_executable) -> None: log_file = "msedgedriver.log" service = Service(log_output=log_file, executable_path=driver_executable) try: assert "--log-path=msedgedriver.log" in service.service_args - driver = clean_driver(service=service) + driver = clean_driver(options=clean_options, service=service) with open(log_file) as fp: assert "Starting Microsoft Edge WebDriver" in fp.readline() finally: @@ -76,12 +75,12 @@ def test_log_output_as_filename(clean_driver, driver_executable) -> None: @pytest.mark.no_driver_after_test -def test_log_output_as_file(clean_driver, driver_executable) -> None: +def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> None: log_name = "msedgedriver.log" log_file = open(log_name, "w", encoding="utf-8") service = Service(log_output=log_file, executable_path=driver_executable) try: - driver = clean_driver(service=service) + driver = clean_driver(options=clean_options, service=service) time.sleep(1) with open(log_name) as fp: assert "Starting Microsoft Edge WebDriver" in fp.readline() @@ -92,9 +91,9 @@ def test_log_output_as_file(clean_driver, driver_executable) -> None: @pytest.mark.no_driver_after_test -def test_log_output_as_stdout(clean_driver, capfd, driver_executable) -> None: +def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executable) -> None: service = Service(log_output=subprocess.STDOUT, executable_path=driver_executable) - driver = clean_driver(service=service) + driver = clean_driver(options=clean_options, service=service) out, err = capfd.readouterr() assert "Starting Microsoft Edge WebDriver" in out @@ -109,12 +108,11 @@ def test_log_output_null_default(driver, capfd) -> None: @pytest.mark.no_driver_after_test -def test_driver_is_stopped_if_browser_cant_start(clean_driver) -> None: - options = Options() - options.add_argument("--user-data-dir=/no/such/location") - service = Service() +def test_driver_is_stopped_if_browser_cant_start(clean_driver, clean_options, clean_service, driver_executable) -> None: + clean_options.add_argument("--user-data-dir=/no/such/location") + service = Service(executable_path=driver_executable) with pytest.raises(SessionNotCreatedException): - clean_driver(options=options, service=service) + clean_driver(options=clean_options, service=service) assert not service.is_connectable() assert service.process.poll() is not None