Skip to content
7 changes: 3 additions & 4 deletions py/test/selenium/webdriver/chrome/chrome_service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import subprocess
import time
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -125,8 +126,6 @@ def test_uses_path_from_env_variable(self, service):
assert "chromedriver" in service.path

def test_updates_path_after_setting_env_variable(self, service):
new_path = "/foo/bar"
os.environ["SE_CHROMEDRIVER"] = new_path
service.executable_path = self.service_path # Simulating the update

assert "chromedriver" in service.executable_path
with patch.dict("os.environ", {"SE_CHROMEDRIVER": "/foo/bar"}):
assert "chromedriver" in service.executable_path
15 changes: 5 additions & 10 deletions py/test/selenium/webdriver/chrome/proxy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

import os
from unittest.mock import patch

import pytest
import urllib3
Expand All @@ -25,20 +25,15 @@

@pytest.mark.no_driver_after_test
def test_bad_proxy_doesnt_interfere(clean_driver, clean_service):
# these values should be ignored if ignore_local_proxy_environment_variables() is called.
os.environ["https_proxy"] = "bad"
os.environ["http_proxy"] = "bad"
# 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}
driver = clean_driver(**chrome_kwargs)

with patch.dict("os.environ", {"http_proxy": "bad", "https_proxy": "bad"}):
driver = clean_driver(**chrome_kwargs)
assert hasattr(driver, "command_executor")
assert hasattr(driver.command_executor, "_proxy_url")
assert isinstance(driver.command_executor._conn, urllib3.PoolManager)
os.environ.pop("https_proxy")
os.environ.pop("http_proxy")
driver.quit()
7 changes: 3 additions & 4 deletions py/test/selenium/webdriver/edge/edge_service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import subprocess
import time
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -125,8 +126,6 @@ def test_uses_path_from_env_variable(self, service):
assert "msedgedriver" in service.path

def test_updates_path_after_setting_env_variable(self, service):
new_path = "/foo/bar"
os.environ["SE_EDGEDRIVER"] = new_path
service.executable_path = self.service_path # Simulating the update

assert "msedgedriver" in service.executable_path
with patch.dict("os.environ", {"SE_EDGEDRIVER": "/foo/bar"}):
assert "msedgedriver" in service.executable_path
7 changes: 3 additions & 4 deletions py/test/selenium/webdriver/firefox/firefox_service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
import os
import subprocess
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -79,8 +80,6 @@ def test_uses_path_from_env_variable(self, service):
assert "geckodriver" in service.path

def test_updates_path_after_setting_env_variable(self, service):
new_path = "/foo/bar"
os.environ["SE_GECKODRIVER"] = new_path
service.executable_path = self.service_path # Simulating the update

assert "geckodriver" in service.executable_path
with patch.dict("os.environ", {"SE_GECKODRIVER": "/foo/bar"}):
assert "geckodriver" in service.executable_path
7 changes: 3 additions & 4 deletions py/test/selenium/webdriver/safari/safari_service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import os
from unittest.mock import patch

import pytest

Expand All @@ -41,11 +42,9 @@ def test_uses_path_from_env_variable(self, service):
assert "safaridriver" in service.path

def test_updates_path_after_setting_env_variable(self, service):
new_path = "/foo/bar"
os.environ["SE_SAFARIDRIVER"] = new_path
service.executable_path = self.service_path # Simulating the update

assert "safaridriver" in service.executable_path
with patch.dict("os.environ", {"SE_SAFARIDRIVER": "/foo/bar"}):
assert "safaridriver" in service.executable_path


def test_enable_logging():
Expand Down
24 changes: 11 additions & 13 deletions py/test/unit/selenium/webdriver/remote/remote_connection_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

import os
from unittest.mock import patch
from urllib import parse

Expand Down Expand Up @@ -168,18 +167,17 @@ def test_get_proxy_direct_via_client_config():


def test_get_proxy_system_matches_no_proxy_via_client_config():
os.environ["HTTP_PROXY"] = "http://admin:admin@system_proxy.com:8080"
os.environ["NO_PROXY"] = "localhost,127.0.0.1"
client_config = ClientConfig(
remote_server_addr="http://localhost:4444", proxy=Proxy({"proxyType": ProxyType.SYSTEM})
)
remote_connection = RemoteConnection(client_config=client_config)
conn = remote_connection._get_connection_manager()
assert isinstance(conn, urllib3.PoolManager)
proxy_url = remote_connection._client_config.get_proxy_url()
assert proxy_url is None
os.environ.pop("HTTP_PROXY")
os.environ.pop("NO_PROXY")
with patch.dict(
"os.environ", {"HTTP_PROXY": "http://admin:admin@system_proxy.com:8080", "NO_PROXY": "localhost,127.0.0.1"}
):
client_config = ClientConfig(
remote_server_addr="http://localhost:4444", proxy=Proxy({"proxyType": ProxyType.SYSTEM})
)
remote_connection = RemoteConnection(client_config=client_config)
conn = remote_connection._get_connection_manager()
assert isinstance(conn, urllib3.PoolManager)
proxy_url = remote_connection._client_config.get_proxy_url()
assert proxy_url is None


def test_get_proxy_url_none(mock_proxy_settings_missing):
Expand Down
Loading