Skip to content

Commit 7751648

Browse files
committed
Merge branch 'trunk' into py-use-chrome-for-remote-tests
2 parents 4e7dae7 + 1b7f3b0 commit 7751648

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

java/src/org/openqa/selenium/remote/RemoteWebDriver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,14 @@ protected Response execute(CommandPayload payload) {
572572
if (e instanceof SessionNotCreatedException) {
573573
toThrow = (WebDriverException) e;
574574
} else {
575+
// When this exception comes from a remote end, the real cause is usually hidden in the
576+
// cause. Let's try to rescue it and display it at the top level.
577+
String cause = e.getCause() != null ? " " + e.getCause().getMessage() : "";
575578
toThrow =
576579
new SessionNotCreatedException(
577580
"Possible causes are invalid address of the remote server or browser start-up"
578-
+ " failure.",
581+
+ " failure."
582+
+ cause,
579583
e);
580584
}
581585
} else if (e instanceof WebDriverException) {

py/test/selenium/webdriver/common/bidi_network_tests.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,20 @@ def callback(request: Request):
7373

7474

7575
def test_continue_request(driver, pages):
76+
exceptions = []
77+
7678
def callback(request: Request):
77-
request.continue_request()
79+
try:
80+
request.continue_request()
81+
except WebDriverException as e:
82+
exceptions.append(e)
7883

7984
callback_id = driver.network.add_request_handler("before_request", callback)
8085
assert callback_id is not None, "Request handler not added"
8186
url = pages.url("formPage.html")
8287
driver.browsing_context.navigate(context=driver.current_window_handle, url=url, wait=ReadinessState.COMPLETE)
8388
assert driver.find_element(By.NAME, "login").is_displayed(), "Request not continued"
89+
assert len(exceptions) == 0, "Exception raised when continuing request in handler callback"
8490

8591

8692
def test_continue_with_auth(driver):
@@ -99,6 +105,26 @@ def test_remove_auth_handler(driver):
99105
assert driver.network.intercepts == [], "Intercept not removed"
100106

101107

108+
def test_handler_with_classic_navigation(driver, pages):
109+
"""Verify request handlers also work with classic navigation."""
110+
browser_name = driver.caps["browserName"]
111+
if browser_name.lower() in ("chrome", "microsoftedge"):
112+
pytest.skip(reason=f"Request handlers don't yet work in {browser_name} using classic navigation")
113+
114+
exceptions = []
115+
116+
def callback(request: Request):
117+
try:
118+
request.continue_request()
119+
except WebDriverException as e:
120+
exceptions.append(e)
121+
122+
callback_id = driver.network.add_request_handler("before_request", callback)
123+
assert callback_id is not None, "Request handler not added"
124+
pages.load("formPage.html")
125+
assert len(exceptions) == 0, "Exception raised in handler callback"
126+
127+
102128
@pytest.mark.xfail_chrome(reason="Data URLs in Network requests are not implemented in Chrome yet")
103129
@pytest.mark.xfail_edge(reason="Data URLs in Network requests are not implemented in Edge yet")
104130
@pytest.mark.xfail_firefox(reason="Data URLs in Network requests are not implemented in Firefox yet")
@@ -120,4 +146,4 @@ def callback(request: Request):
120146
time.sleep(1) # give callback time to complete
121147
assert driver.find_element(By.ID, "data-url-image").is_displayed()
122148
assert len(data_requests) > 0, "BiDi event not captured"
123-
assert len(exceptions) == 0, "Exception raised when continuing request in callback"
149+
assert len(exceptions) == 0, "Exception raised when continuing request in handler callback"

0 commit comments

Comments
 (0)