Skip to content

Commit 33df34e

Browse files
committed
add test
1 parent cae51c1 commit 33df34e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

py/selenium/webdriver/common/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ def __init__(
6565
else:
6666
self.log_output = log_output
6767

68-
self._path = executable_path
6968
self.port = port or utils.free_port()
7069
# Default value for every python subprocess: subprocess.Popen(..., creationflags=0)
7170
self.popen_kw = kwargs.pop("popen_kw", {})
7271
self.creation_flags = self.popen_kw.pop("creation_flags", 0)
7372
self.env = env or os.environ
7473
self.DRIVER_PATH_ENV_KEY = driver_path_env_key
74+
self._path = self.env_path() or executable_path
7575

7676
@property
7777
def service_url(self) -> str:

py/test/selenium/webdriver/firefox/firefox_service_tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
import os
1818
import subprocess
19+
import pytest
1920

2021
from selenium.webdriver import Firefox
2122
from selenium.webdriver.firefox.service import Service
@@ -54,3 +55,27 @@ def test_log_output_as_stdout(capfd) -> None:
5455
out, err = capfd.readouterr()
5556
assert "geckodriver\tINFO\tListening" in out
5657
driver.quit()
58+
59+
@pytest.fixture
60+
def service():
61+
return Service()
62+
63+
@pytest.mark.usefixtures("service")
64+
class TestGeckoDriverService:
65+
service_path = "/path/to/geckodriver"
66+
67+
@pytest.fixture(autouse=True)
68+
def setup_and_teardown(self):
69+
os.environ['SE_GECKODRIVER'] = self.service_path
70+
yield
71+
os.environ.pop('SE_GECKODRIVER', None)
72+
73+
def test_uses_path_from_env_variable(self, service):
74+
assert 'geckodriver' in service.path
75+
76+
def test_updates_path_after_setting_env_variable(self, service):
77+
new_path = "/foo/bar"
78+
os.environ['SE_GECKODRIVER'] = new_path
79+
service.executable_path = self.service_path # Simulating the update
80+
81+
assert 'geckodriver' in service.executable_path

0 commit comments

Comments
 (0)