Skip to content

Commit 55ed141

Browse files
committed
address review comments
1 parent 11c4a2c commit 55ed141

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

py/selenium/webdriver/remote/remote_connection.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ class RemoteConnection:
143143
)
144144
_ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where()
145145

146+
system = platform.system().lower()
147+
if system == "darwin":
148+
system = "mac"
149+
146150
# Class variables for headers
147151
extra_headers = None
148-
user_agent = f"selenium/{__version__} (python {platform.system().lower()})"
152+
user_agent = f"selenium/{__version__} (python {system}"
149153

150154
@classmethod
151155
def get_timeout(cls):
@@ -200,14 +204,10 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
200204
- keep_alive (Boolean) - Is this a keep-alive connection (default: False)
201205
"""
202206

203-
system = platform.system().lower()
204-
if system == "darwin":
205-
system = "mac"
206-
207207
headers = {
208208
"Accept": "application/json",
209209
"Content-Type": "application/json;charset=UTF-8",
210-
"User-Agent": f"selenium/{__version__} (python {system})",
210+
"User-Agent": cls.user_agent,
211211
}
212212

213213
if parsed_url.username:
@@ -241,8 +241,9 @@ def _separate_http_proxy_auth(self):
241241
proxy_without_auth = protocol + no_protocol[len(auth) + 1 :]
242242
return proxy_without_auth, auth
243243

244-
def _get_connection_manager(self):
244+
def _get_connection_manager(self, **pool_manager_kwargs):
245245
pool_manager_init_args = {"timeout": self.get_timeout()}
246+
pool_manager_init_args.update(pool_manager_kwargs.get("init_args_for_pool_manager", {}))
246247

247248
if self._ignore_certificates:
248249
pool_manager_init_args["cert_reqs"] = "CERT_NONE"

py/selenium/webdriver/remote/webdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def __init__(
186186
- file_detector - Pass custom file detector object during instantiation. If None,
187187
then default LocalFileDetector() will be used.
188188
- options - instance of a driver options.Options class
189+
- locator_converter - Custom locator converter to use. Defaults to None.
189190
- web_element_cls - Custom class to use for web elements. Defaults to WebElement.
190191
"""
191192

py/selenium/webdriver/remote/webelement.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,7 @@ def find_element(self, by=By.ID, value=None) -> WebElement:
404404
405405
:rtype: WebElement
406406
"""
407-
if by == By.ID:
408-
by = By.CSS_SELECTOR
409-
value = f'[id="{value}"]'
410-
elif by == By.CLASS_NAME:
411-
by = By.CSS_SELECTOR
412-
value = f".{value}"
413-
elif by == By.NAME:
414-
by = By.CSS_SELECTOR
415-
value = f'[name="{value}"]'
416-
407+
by, value = self._parent.locator_converter.convert(by, value)
417408
return self._execute(Command.FIND_CHILD_ELEMENT, {"using": by, "value": value})["value"]
418409

419410
def find_elements(self, by=By.ID, value=None) -> List[WebElement]:
@@ -426,16 +417,7 @@ def find_elements(self, by=By.ID, value=None) -> List[WebElement]:
426417
427418
:rtype: list of WebElement
428419
"""
429-
if by == By.ID:
430-
by = By.CSS_SELECTOR
431-
value = f'[id="{value}"]'
432-
elif by == By.CLASS_NAME:
433-
by = By.CSS_SELECTOR
434-
value = f".{value}"
435-
elif by == By.NAME:
436-
by = By.CSS_SELECTOR
437-
value = f'[name="{value}"]'
438-
420+
by, value = self._parent.locator_converter.convert(by, value)
439421
return self._execute(Command.FIND_CHILD_ELEMENTS, {"using": by, "value": value})["value"]
440422

441423
def __hash__(self) -> int:

py/test/unit/selenium/webdriver/remote/remote_connection_tests.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_get_remote_connection_headers_defaults():
5555
assert headers.get("Accept") == "application/json"
5656
assert headers.get("Content-Type") == "application/json;charset=UTF-8"
5757
assert headers.get("User-Agent").startswith(f"selenium/{__version__} (python ")
58-
assert headers.get("User-Agent").split(" ")[-1] in {"windows)", "mac)", "linux)"}
58+
assert headers.get("User-Agent").split(" ")[-1] in {"windows)", "mac)", "linux)", "mac", "windows", "linux"}
5959

6060

6161
def test_get_remote_connection_headers_adds_auth_header_if_pass():
@@ -301,3 +301,13 @@ def test_get_connection_manager_ignores_certificates(monkeypatch):
301301
assert conn.connection_pool_kw["timeout"] == 10
302302
assert conn.connection_pool_kw["cert_reqs"] == "CERT_NONE"
303303
assert isinstance(conn, urllib3.PoolManager)
304+
305+
306+
def test_get_connection_manager_with_custom_args():
307+
custom_args = {"retries": 3, "block": True}
308+
remote_connection = RemoteConnection("http://remote", keep_alive=False)
309+
conn = remote_connection._get_connection_manager(init_args_for_pool_manager=custom_args)
310+
311+
assert isinstance(conn, urllib3.PoolManager)
312+
assert conn.connection_pool_kw["retries"] == 3
313+
assert conn.connection_pool_kw["block"] is True

0 commit comments

Comments
 (0)