From 535ee97ef740f9fa6455038d6da782f640711684 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 2 May 2025 10:54:01 +0200 Subject: [PATCH] Selenium proxy fixes --- changedetectionio/content_fetchers/webdriver_selenium.py | 3 +-- changedetectionio/run_proxy_tests.sh | 7 ++++--- changedetectionio/tests/proxy_list/test_proxy_noconnect.py | 5 ++++- requirements.txt | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/changedetectionio/content_fetchers/webdriver_selenium.py b/changedetectionio/content_fetchers/webdriver_selenium.py index 1aafe7cf..a9a88203 100644 --- a/changedetectionio/content_fetchers/webdriver_selenium.py +++ b/changedetectionio/content_fetchers/webdriver_selenium.py @@ -76,8 +76,7 @@ class fetcher(Fetcher): for opt in CHROME_OPTIONS: options.add_argument(opt) - if self.proxy: - options.proxy = self.proxy + options.add_argument(f"--proxy-server={self.proxy}") self.driver = webdriver.Remote( command_executor=self.browser_connection_url, diff --git a/changedetectionio/run_proxy_tests.sh b/changedetectionio/run_proxy_tests.sh index 457aa451..58d109b0 100755 --- a/changedetectionio/run_proxy_tests.sh +++ b/changedetectionio/run_proxy_tests.sh @@ -101,6 +101,7 @@ docker run --network changedet-network \ bash -c 'cd changedetectionio && FAST_PUPPETEER_CHROME_FETCHER=1 PLAYWRIGHT_DRIVER_URL=ws://sockpuppetbrowser:3000 pytest tests/proxy_list/test_proxy_noconnect.py' # Selenium - todo - fix proxies -#docker run --network changedet-network \ -# test-changedetectionio \ -# bash -c 'cd changedetectionio && FAST_PUPPETEER_CHROME_FETCHER=1 PLAYWRIGHT_DRIVER_URL=ws://sockpuppetbrowser:3000 pytest tests/proxy_list/test_proxy_noconnect.py' +docker run --network changedet-network \ + -e "WEBDRIVER_URL=http://selenium:4444/wd/hub" \ + test-changedetectionio \ + bash -c 'cd changedetectionio && pytest tests/proxy_list/test_proxy_noconnect.py' diff --git a/changedetectionio/tests/proxy_list/test_proxy_noconnect.py b/changedetectionio/tests/proxy_list/test_proxy_noconnect.py index e0b8511f..f7335c3c 100644 --- a/changedetectionio/tests/proxy_list/test_proxy_noconnect.py +++ b/changedetectionio/tests/proxy_list/test_proxy_noconnect.py @@ -44,7 +44,10 @@ def test_proxy_noconnect_custom(client, live_server, measure_memory_usage): check_string = b'Proxy connection failed?' if os.getenv('PLAYWRIGHT_DRIVER_URL') or strtobool(os.getenv('FAST_PUPPETEER_CHROME_FETCHER', 'False')): - check_string = b'ERR_PROXY_CONNECTION_FAILED ' + check_string = b'ERR_PROXY_CONNECTION_FAILED' + + if os.getenv("WEBDRIVER_URL"): + check_string = b'ERR_PROXY_CONNECTION_FAILED' assert check_string in res.data diff --git a/requirements.txt b/requirements.txt index c6c0495a..01b6e30d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -53,7 +53,7 @@ lxml >=4.8.0,<6,!=5.2.0,!=5.2.1 # XPath 2.0-3.1 support - 4.2.0 broke something? elementpath==4.1.5 -selenium~=4.14.0 +selenium==4.31.0 # https://github.com/pallets/werkzeug/issues/2985 # Maybe related to pytest?