From b88be092f190a9c49b2605714dddbd7ef34c9874 Mon Sep 17 00:00:00 2001 From: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Date: Tue, 7 Oct 2025 09:52:42 -0400 Subject: [PATCH 1/6] [py] Fix chromedriver/msedgedriver service tests --- .../webdriver/chrome/chrome_service_tests.py | 14 ++++++++++---- .../selenium/webdriver/edge/edge_service_tests.py | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/py/test/selenium/webdriver/chrome/chrome_service_tests.py b/py/test/selenium/webdriver/chrome/chrome_service_tests.py index 53d4241f9fd1b..a5040ccf67ff5 100644 --- a/py/test/selenium/webdriver/chrome/chrome_service_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_service_tests.py @@ -69,7 +69,9 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) assert "--log-path=chromedriver.log" in service.service_args driver = clean_driver(options=clean_options, service=service) with open(log_file) as fp: - assert "Starting ChromeDriver" in fp.readline() + out = fp.read() + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() os.remove(log_file) @@ -84,7 +86,9 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N driver = clean_driver(options=clean_options, service=service) time.sleep(1) with open(log_name) as fp: - assert "Starting ChromeDriver" in fp.readline() + out = fp.read() + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() log_file.close() @@ -97,14 +101,16 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa driver = clean_driver(options=clean_options, service=service) out, err = capfd.readouterr() - assert "Starting ChromeDriver" in out + assert "Starting" in out + assert "started successfully" in out driver.quit() @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: out, err = capfd.readouterr() - assert "Starting ChromeDriver" not in out + assert "Starting" in out + assert "started successfully" in out driver.quit() diff --git a/py/test/selenium/webdriver/edge/edge_service_tests.py b/py/test/selenium/webdriver/edge/edge_service_tests.py index b0abb05f3f462..861ddf1d7f8a7 100644 --- a/py/test/selenium/webdriver/edge/edge_service_tests.py +++ b/py/test/selenium/webdriver/edge/edge_service_tests.py @@ -69,7 +69,9 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) assert "--log-path=msedgedriver.log" in service.service_args driver = clean_driver(options=clean_options, service=service) with open(log_file) as fp: - assert "Starting Microsoft Edge WebDriver" in fp.readline() + out = fp.read() + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() os.remove(log_file) @@ -84,7 +86,9 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N driver = clean_driver(options=clean_options, service=service) time.sleep(1) with open(log_name) as fp: - assert "Starting msedgedriver" in fp.readline() + out = fp.read() + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() log_file.close() @@ -97,14 +101,16 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa driver = clean_driver(options=clean_options, service=service) out, err = capfd.readouterr() - assert "Starting msedgedriver" in out + assert "Starting" in out + assert "started successfully" in out driver.quit() @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: out, err = capfd.readouterr() - assert "Starting Microsoft Edge WebDriver" not in out + assert "Starting" in out + assert "started successfully" in out driver.quit() From 6516203746b34c1100730db31a101fcb09fa07b1 Mon Sep 17 00:00:00 2001 From: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:05:30 -0400 Subject: [PATCH 2/6] [py] Move asserts out of context manager --- py/test/selenium/webdriver/chrome/chrome_service_tests.py | 8 ++++---- py/test/selenium/webdriver/edge/edge_service_tests.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/py/test/selenium/webdriver/chrome/chrome_service_tests.py b/py/test/selenium/webdriver/chrome/chrome_service_tests.py index a5040ccf67ff5..98eaccd17e7d3 100644 --- a/py/test/selenium/webdriver/chrome/chrome_service_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_service_tests.py @@ -70,8 +70,8 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) driver = clean_driver(options=clean_options, service=service) with open(log_file) as fp: out = fp.read() - assert "Starting" in out - assert "started successfully" in out + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() os.remove(log_file) @@ -87,8 +87,8 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N time.sleep(1) with open(log_name) as fp: out = fp.read() - assert "Starting" in out - assert "started successfully" in out + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() log_file.close() diff --git a/py/test/selenium/webdriver/edge/edge_service_tests.py b/py/test/selenium/webdriver/edge/edge_service_tests.py index 861ddf1d7f8a7..65f49f04f04b1 100644 --- a/py/test/selenium/webdriver/edge/edge_service_tests.py +++ b/py/test/selenium/webdriver/edge/edge_service_tests.py @@ -70,8 +70,8 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) driver = clean_driver(options=clean_options, service=service) with open(log_file) as fp: out = fp.read() - assert "Starting" in out - assert "started successfully" in out + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() os.remove(log_file) @@ -87,8 +87,8 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N time.sleep(1) with open(log_name) as fp: out = fp.read() - assert "Starting" in out - assert "started successfully" in out + assert "Starting" in out + assert "started successfully" in out finally: driver.quit() log_file.close() From ddda086fe87ceaf1e6cb6010a6827d79ff1d7c23 Mon Sep 17 00:00:00 2001 From: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:12:16 -0400 Subject: [PATCH 3/6] [py] Fix assertions --- py/test/selenium/webdriver/chrome/chrome_service_tests.py | 4 ++-- py/test/selenium/webdriver/edge/edge_service_tests.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/py/test/selenium/webdriver/chrome/chrome_service_tests.py b/py/test/selenium/webdriver/chrome/chrome_service_tests.py index 98eaccd17e7d3..818aac3dfacb5 100644 --- a/py/test/selenium/webdriver/chrome/chrome_service_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_service_tests.py @@ -109,8 +109,8 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: out, err = capfd.readouterr() - assert "Starting" in out - assert "started successfully" in out + assert "Starting" not in out + assert "started successfully" not in out driver.quit() diff --git a/py/test/selenium/webdriver/edge/edge_service_tests.py b/py/test/selenium/webdriver/edge/edge_service_tests.py index 65f49f04f04b1..d007d9d15767f 100644 --- a/py/test/selenium/webdriver/edge/edge_service_tests.py +++ b/py/test/selenium/webdriver/edge/edge_service_tests.py @@ -109,8 +109,8 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: out, err = capfd.readouterr() - assert "Starting" in out - assert "started successfully" in out + assert "Starting" not in out + assert "started successfully" not in out driver.quit() From 42734c7a11aeb3f14f098e2e94c38bde0677be42 Mon Sep 17 00:00:00 2001 From: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:19:55 -0400 Subject: [PATCH 4/6] [py] Add sleeps to wait for logging --- py/test/selenium/webdriver/chrome/chrome_service_tests.py | 4 +++- py/test/selenium/webdriver/edge/edge_service_tests.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/py/test/selenium/webdriver/chrome/chrome_service_tests.py b/py/test/selenium/webdriver/chrome/chrome_service_tests.py index 818aac3dfacb5..eefc2410dde5d 100644 --- a/py/test/selenium/webdriver/chrome/chrome_service_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_service_tests.py @@ -68,6 +68,7 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) try: assert "--log-path=chromedriver.log" in service.service_args driver = clean_driver(options=clean_options, service=service) + time.sleep(1) with open(log_file) as fp: out = fp.read() assert "Starting" in out @@ -99,7 +100,7 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N 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(options=clean_options, service=service) - + time.sleep(1) out, err = capfd.readouterr() assert "Starting" in out assert "started successfully" in out @@ -108,6 +109,7 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: + time.sleep(1) out, err = capfd.readouterr() assert "Starting" not in out assert "started successfully" not in out diff --git a/py/test/selenium/webdriver/edge/edge_service_tests.py b/py/test/selenium/webdriver/edge/edge_service_tests.py index d007d9d15767f..1f7f9c56fb601 100644 --- a/py/test/selenium/webdriver/edge/edge_service_tests.py +++ b/py/test/selenium/webdriver/edge/edge_service_tests.py @@ -68,6 +68,7 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) try: assert "--log-path=msedgedriver.log" in service.service_args driver = clean_driver(options=clean_options, service=service) + time.sleep(1) with open(log_file) as fp: out = fp.read() assert "Starting" in out @@ -99,7 +100,7 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N 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(options=clean_options, service=service) - + time.sleep(1) out, err = capfd.readouterr() assert "Starting" in out assert "started successfully" in out @@ -108,6 +109,7 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: + time.sleep(1) out, err = capfd.readouterr() assert "Starting" not in out assert "started successfully" not in out From e6a928d5042327de3859e87b5918ed3580df0b89 Mon Sep 17 00:00:00 2001 From: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Date: Tue, 7 Oct 2025 11:20:50 -0400 Subject: [PATCH 5/6] [py] Remove sleeps --- py/test/selenium/webdriver/chrome/chrome_service_tests.py | 5 ----- py/test/selenium/webdriver/edge/edge_service_tests.py | 5 ----- 2 files changed, 10 deletions(-) diff --git a/py/test/selenium/webdriver/chrome/chrome_service_tests.py b/py/test/selenium/webdriver/chrome/chrome_service_tests.py index eefc2410dde5d..87a94bd1cdaeb 100644 --- a/py/test/selenium/webdriver/chrome/chrome_service_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_service_tests.py @@ -18,7 +18,6 @@ import os import subprocess import sys -import time from unittest.mock import patch import pytest @@ -68,7 +67,6 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) try: assert "--log-path=chromedriver.log" in service.service_args driver = clean_driver(options=clean_options, service=service) - time.sleep(1) with open(log_file) as fp: out = fp.read() assert "Starting" in out @@ -85,7 +83,6 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N service = Service(log_output=log_file, executable_path=driver_executable) try: driver = clean_driver(options=clean_options, service=service) - time.sleep(1) with open(log_name) as fp: out = fp.read() assert "Starting" in out @@ -100,7 +97,6 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N 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(options=clean_options, service=service) - time.sleep(1) out, err = capfd.readouterr() assert "Starting" in out assert "started successfully" in out @@ -109,7 +105,6 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: - time.sleep(1) out, err = capfd.readouterr() assert "Starting" not in out assert "started successfully" not in out diff --git a/py/test/selenium/webdriver/edge/edge_service_tests.py b/py/test/selenium/webdriver/edge/edge_service_tests.py index 1f7f9c56fb601..b2708505ff675 100644 --- a/py/test/selenium/webdriver/edge/edge_service_tests.py +++ b/py/test/selenium/webdriver/edge/edge_service_tests.py @@ -18,7 +18,6 @@ import os import subprocess import sys -import time from unittest.mock import patch import pytest @@ -68,7 +67,6 @@ def test_log_output_as_filename(clean_driver, clean_options, driver_executable) try: assert "--log-path=msedgedriver.log" in service.service_args driver = clean_driver(options=clean_options, service=service) - time.sleep(1) with open(log_file) as fp: out = fp.read() assert "Starting" in out @@ -85,7 +83,6 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N service = Service(log_output=log_file, executable_path=driver_executable) try: driver = clean_driver(options=clean_options, service=service) - time.sleep(1) with open(log_name) as fp: out = fp.read() assert "Starting" in out @@ -100,7 +97,6 @@ def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> N 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(options=clean_options, service=service) - time.sleep(1) out, err = capfd.readouterr() assert "Starting" in out assert "started successfully" in out @@ -109,7 +105,6 @@ def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executa @pytest.mark.no_driver_after_test def test_log_output_null_default(driver, capfd) -> None: - time.sleep(1) out, err = capfd.readouterr() assert "Starting" not in out assert "started successfully" not in out From 3731b8876898f3de51cb06ba016e46b866afdbc9 Mon Sep 17 00:00:00 2001 From: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Date: Tue, 7 Oct 2025 12:53:44 -0400 Subject: [PATCH 6/6] [py] Refactor logging reuse test --- .../webdriver/chrome/chrome_service_tests.py | 23 +++++++++---------- .../webdriver/edge/edge_service_tests.py | 23 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/py/test/selenium/webdriver/chrome/chrome_service_tests.py b/py/test/selenium/webdriver/chrome/chrome_service_tests.py index 87a94bd1cdaeb..c637d879aacad 100644 --- a/py/test/selenium/webdriver/chrome/chrome_service_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_service_tests.py @@ -27,36 +27,35 @@ @pytest.mark.no_driver_after_test -def test_uses_chromedriver_logging(clean_driver, clean_options, driver_executable) -> None: +def test_reuses_chromedriver_log(clean_driver, clean_options, driver_executable) -> None: log_file = "chromedriver.log" - service_args = ["--append-log"] service1 = Service( log_output=log_file, - service_args=service_args, executable_path=driver_executable, ) service2 = Service( log_output=log_file, - service_args=service_args, + service_args=["--append-log"], executable_path=driver_executable, ) - driver1 = None - driver2 = None + driver = None try: - driver1 = clean_driver(options=clean_options, service=service1) + driver = clean_driver(options=clean_options, service=service1) with open(log_file) as fp: lines = len(fp.readlines()) - driver2 = clean_driver(options=clean_options, service=service2) + finally: + if driver: + driver.quit() + try: + driver = clean_driver(options=clean_options, service=service2) with open(log_file) as fp: assert len(fp.readlines()) >= 2 * lines finally: - if driver1: - driver1.quit() - if driver2: - driver2.quit() + if driver: + driver.quit() os.remove(log_file) diff --git a/py/test/selenium/webdriver/edge/edge_service_tests.py b/py/test/selenium/webdriver/edge/edge_service_tests.py index b2708505ff675..2cff66b53cb6e 100644 --- a/py/test/selenium/webdriver/edge/edge_service_tests.py +++ b/py/test/selenium/webdriver/edge/edge_service_tests.py @@ -27,36 +27,35 @@ @pytest.mark.no_driver_after_test -def test_uses_edgedriver_logging(clean_driver, clean_options, driver_executable) -> None: +def test_reuses_edgedriver_log(clean_driver, clean_options, driver_executable) -> None: log_file = "msedgedriver.log" - service_args = ["--append-log"] service1 = Service( log_output=log_file, - service_args=service_args, executable_path=driver_executable, ) service2 = Service( log_output=log_file, - service_args=service_args, + service_args=["--append-log"], executable_path=driver_executable, ) - driver1 = None - driver2 = None + driver = None try: - driver1 = clean_driver(options=clean_options, service=service1) + driver = clean_driver(options=clean_options, service=service1) with open(log_file) as fp: lines = len(fp.readlines()) - driver2 = clean_driver(options=clean_options, service=service2) + finally: + if driver: + driver.quit() + try: + driver = clean_driver(options=clean_options, service=service2) with open(log_file) as fp: assert len(fp.readlines()) >= 2 * lines finally: - if driver1: - driver1.quit() - if driver2: - driver2.quit() + if driver: + driver.quit() os.remove(log_file)