|
22 | 22 | import pytest |
23 | 23 |
|
24 | 24 | from selenium.webdriver.common.bidi.browser import ClientWindowInfo, ClientWindowState |
| 25 | +from selenium.webdriver.common.bidi.session import UserPromptHandler, UserPromptHandlerType |
25 | 26 | from selenium.webdriver.common.by import By |
26 | 27 | from selenium.webdriver.common.proxy import Proxy, ProxyType |
27 | 28 | from selenium.webdriver.common.utils import free_port |
@@ -235,3 +236,29 @@ def test_create_user_context_with_proxy_and_accept_insecure_certs(driver): |
235 | 236 | driver.browser.remove_user_context(user_context) |
236 | 237 | fake_proxy_server.shutdown() |
237 | 238 | fake_proxy_server.server_close() |
| 239 | + |
| 240 | + |
| 241 | +def test_create_user_context_with_unhandled_prompt_behavior(driver, pages): |
| 242 | + """Test creating a user context with unhandled prompt behavior configuration.""" |
| 243 | + prompt_handler = UserPromptHandler( |
| 244 | + alert=UserPromptHandlerType.DISMISS, default=UserPromptHandlerType.DISMISS, prompt=UserPromptHandlerType.DISMISS |
| 245 | + ) |
| 246 | + |
| 247 | + user_context = driver.browser.create_user_context(unhandled_prompt_behavior=prompt_handler) |
| 248 | + assert user_context is not None |
| 249 | + |
| 250 | + # create a new browsing context with the user context |
| 251 | + bc = driver.browsing_context.create(type=WindowTypes.WINDOW, user_context=user_context) |
| 252 | + assert bc is not None |
| 253 | + |
| 254 | + driver.switch_to.window(bc) |
| 255 | + pages.load("alerts.html") |
| 256 | + |
| 257 | + # TODO: trigger an alert and test that it is dismissed automatically, currently not working, |
| 258 | + # conftest.py unhandled_prompt_behavior set to IGNORE, see if it is related |
| 259 | + # driver.find_element(By.ID, "alert").click() |
| 260 | + # # accessing title should be possible since alert is auto handled |
| 261 | + # assert driver.title == "Testing Alerts" |
| 262 | + |
| 263 | + # Clean up |
| 264 | + driver.browser.remove_user_context(user_context) |
0 commit comments