Skip to content

Commit

Permalink
[py] chromium service log file name should always use args
Browse files Browse the repository at this point in the history
Chrome Logging Preferences require logging to be enabled with --log-path
  • Loading branch information
titusfortner committed Sep 17, 2023
1 parent edf28c1 commit 377f832
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 41 deletions.
15 changes: 6 additions & 9 deletions py/selenium/webdriver/chromium/service.py
Expand Up @@ -16,7 +16,6 @@
# under the License.
import typing

from selenium.common import InvalidArgumentException
from selenium.types import SubprocessStdAlias
from selenium.webdriver.common import service

Expand All @@ -42,14 +41,12 @@ def __init__(
**kwargs,
) -> None:
self.service_args = service_args or []
self.log_output = log_output
if "--append-log" in self.service_args or "--readable-timestamp" in self.service_args:
if isinstance(self.log_output, str):
self.service_args.append(f"--log-path={self.log_output}")
self.log_output = None
else:
msg = "Appending logs and readable timestamps require log output to be a string representing file path"
raise InvalidArgumentException(msg)

if isinstance(log_output, str):
self.service_args.append(f"--log-path={log_output}")
self.log_output = None
else:
self.log_output = log_output

super().__init__(
executable=executable_path,
Expand Down
11 changes: 1 addition & 10 deletions py/test/selenium/webdriver/chrome/chrome_service_tests.py
Expand Up @@ -18,20 +18,10 @@
import subprocess
import time

import pytest

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service


def test_log_path_deprecated() -> None:
log_path = "chromedriver.log"
msg = "log_path has been deprecated, please use log_output"

with pytest.warns(match=msg, expected_warning=DeprecationWarning):
Service(log_path=log_path)


def test_uses_chromedriver_logging() -> None:
log_file = "chromedriver.log"
service_args = ["--append-log"]
Expand All @@ -54,6 +44,7 @@ def test_log_output_as_filename() -> None:
log_file = "chromedriver.log"
service = Service(log_output=log_file)
try:
assert "--log-path=chromedriver.log" in service.service_args
driver = Chrome(service=service)
with open(log_file) as fp:
assert "Starting ChromeDriver" in fp.readline()
Expand Down
22 changes: 0 additions & 22 deletions py/test/selenium/webdriver/firefox/firefox_service_tests.py
Expand Up @@ -23,14 +23,6 @@
from selenium.webdriver.firefox.service import Service


def test_log_path_deprecated() -> None:
log_path = "geckodriver.log"
msg = "log_path has been deprecated, please use log_output"

with pytest.warns(match=msg, expected_warning=DeprecationWarning):
Service(log_path=log_path)


def test_log_output_as_filename() -> None:
log_file = "geckodriver.log"
service = Service(log_output=log_file)
Expand Down Expand Up @@ -64,17 +56,3 @@ def test_log_output_as_stdout(capfd) -> None:
out, err = capfd.readouterr()
assert "geckodriver\tINFO\tListening" in out
driver.quit()


def test_log_output_default_deprecated() -> None:
log_name = "geckodriver.log"
msg = "Firefox will soon stop logging to geckodriver.log by default; Specify desired logs with log_output"

try:
with pytest.warns(match=msg, expected_warning=DeprecationWarning):
driver = Firefox()
with open(log_name) as fp:
assert "geckodriver\tINFO\tListening" in fp.readline()
finally:
driver.quit()
os.remove(log_name)

0 comments on commit 377f832

Please sign in to comment.