|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
| 18 | +import time |
18 | 19 |
|
| 20 | +import pytest |
| 21 | + |
| 22 | +from selenium.common.exceptions import WebDriverException |
19 | 23 | from selenium.webdriver.common.bidi.browsing_context import ReadinessState |
20 | 24 | from selenium.webdriver.common.bidi.network import Request |
21 | 25 | from selenium.webdriver.common.by import By |
@@ -93,3 +97,27 @@ def test_remove_auth_handler(driver): |
93 | 97 | assert callback_id is not None, "Request handler not added" |
94 | 98 | driver.network.remove_auth_handler(callback_id) |
95 | 99 | assert driver.network.intercepts == [], "Intercept not removed" |
| 100 | + |
| 101 | + |
| 102 | +@pytest.mark.xfail_chrome(reason="Data URLs in Network requests are not implemented in Chrome yet") |
| 103 | +@pytest.mark.xfail_edge(reason="Data URLs in Network requests are not implemented in Edge yet") |
| 104 | +@pytest.mark.xfail_firefox(reason="Data URLs in Network requests are not implemented in Firefox yet") |
| 105 | +def test_handler_with_data_url_request(driver, pages): |
| 106 | + data_requests = [] |
| 107 | + exceptions = [] |
| 108 | + |
| 109 | + def callback(request: Request): |
| 110 | + if request.url.startswith("data:"): |
| 111 | + data_requests.append(request) |
| 112 | + try: |
| 113 | + request.continue_request() |
| 114 | + except WebDriverException as e: |
| 115 | + exceptions.append(e) |
| 116 | + |
| 117 | + driver.network.add_request_handler("before_request", callback) |
| 118 | + url = pages.url("data_url.html") |
| 119 | + driver.browsing_context.navigate(context=driver.current_window_handle, url=url, wait=ReadinessState.COMPLETE) |
| 120 | + time.sleep(1) # give callback time to complete |
| 121 | + assert driver.find_element(By.ID, "data-url-image").is_displayed() |
| 122 | + assert len(data_requests) > 0, "BiDi event not captured" |
| 123 | + assert len(exceptions) == 0, "Exception raised when continuing request in callback" |
0 commit comments