Skip to content

Commit 345c1be

Browse files
committed
use free_port method from utils
1 parent 5ff92bd commit 345c1be

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

py/test/selenium/webdriver/common/bidi_browser_tests.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# under the License.
1717

1818
import http.server
19-
import socket
2019
import socketserver
2120
import threading
2221

@@ -25,15 +24,10 @@
2524
from selenium.webdriver.common.bidi.browser import ClientWindowInfo, ClientWindowState
2625
from selenium.webdriver.common.by import By
2726
from selenium.webdriver.common.proxy import Proxy, ProxyType
27+
from selenium.webdriver.common.utils import free_port
2828
from selenium.webdriver.common.window import WindowTypes
2929

3030

31-
def get_free_port():
32-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
33-
s.bind(("", 0))
34-
return s.getsockname()[1]
35-
36-
3731
class FakeProxyHandler(http.server.SimpleHTTPRequestHandler):
3832
def do_GET(self):
3933
print(f"[Fake Proxy] Intercepted request to: {self.path}")
@@ -170,7 +164,7 @@ def test_create_user_context_with_direct_proxy(driver):
170164
def test_create_user_context_with_manual_proxy_all_params(driver):
171165
"""Test creating a user context with manual proxy configuration."""
172166
# Start a fake proxy server
173-
port = get_free_port()
167+
port = free_port()
174168
fake_proxy_server = start_fake_proxy(port=port)
175169

176170
proxy = Proxy()
@@ -210,7 +204,7 @@ def test_create_user_context_with_manual_proxy_all_params(driver):
210204
def test_create_user_context_with_both_params(driver):
211205
"""Test creating a user context with both acceptInsecureCerts and proxy parameters."""
212206
# Start fake proxy server
213-
port = get_free_port()
207+
port = free_port()
214208
fake_proxy_server = start_fake_proxy(port=port)
215209

216210
proxy = Proxy()

0 commit comments

Comments
 (0)