| 1 |
# META: timeout=long |
| 2 |
|
| 3 |
import pytest |
| 4 |
import pytest_asyncio |
| 5 |
from webdriver.bidi.modules.input import Actions |
| 6 |
from webdriver.bidi.modules.script import ContextTarget |
| 7 |
|
| 8 |
pytestmark = pytest.mark.asyncio |
| 9 |
|
| 10 |
|
| 11 |
@pytest_asyncio.fixture |
| 12 |
async def setup_beforeunload_page(url): |
| 13 |
async def setup_beforeunload_page(bidi_session, context): |
| 14 |
page_url = url("/webdriver/tests/support/html/beforeunload.html") |
| 15 |
await bidi_session.browsing_context.navigate( |
| 16 |
context=context["context"], url=page_url, wait="complete" |
| 17 |
) |
| 18 |
|
| 19 |
# Focus the input |
| 20 |
await bidi_session.script.evaluate( |
| 21 |
expression=""" |
| 22 |
const input = document.querySelector("input"); |
| 23 |
input.focus(); |
| 24 |
""", |
| 25 |
target=ContextTarget(context["context"]), |
| 26 |
await_promise=False, |
| 27 |
) |
| 28 |
|
| 29 |
actions = Actions() |
| 30 |
actions.add_key().send_keys("foo") |
| 31 |
await bidi_session.input.perform_actions( |
| 32 |
actions=actions, context=context["context"] |
| 33 |
) |
| 34 |
|
| 35 |
return page_url |
| 36 |
|
| 37 |
return setup_beforeunload_page |
| 38 |
|
| 39 |
|
| 40 |
@pytest.mark.parametrize("marionette_enabled", [False, True]) |
| 41 |
async def test_with_marionette_enabled( |
| 42 |
new_session, add_browser_capabilities, marionette_enabled |
| 43 |
): |
| 44 |
bidi_session = await new_session( |
| 45 |
capabilities={"alwaysMatch": add_browser_capabilities({})}, |
| 46 |
browser_args={"use_marionette": marionette_enabled}, |
| 47 |
) |
| 48 |
|
| 49 |
await bidi_session.browser.close() |
| 50 |
|
| 51 |
# Wait for the browser to actually close. |
| 52 |
bidi_session.current_browser.wait() |
| 53 |
|
| 54 |
assert bidi_session.current_browser.is_running is False |
| 55 |
|
| 56 |
|
| 57 |
async def test_close_all_tabs_without_beforeunload_prompt( |
| 58 |
new_session, |
| 59 |
add_browser_capabilities, |
| 60 |
setup_beforeunload_page, |
| 61 |
): |
| 62 |
bidi_session = await new_session( |
| 63 |
capabilities={"alwaysMatch": add_browser_capabilities({})} |
| 64 |
) |
| 65 |
|
| 66 |
new_tab = await bidi_session.browsing_context.create(type_hint="tab") |
| 67 |
new_window = await bidi_session.browsing_context.create(type_hint="window") |
| 68 |
|
| 69 |
await setup_beforeunload_page(bidi_session, new_tab) |
| 70 |
await setup_beforeunload_page(bidi_session, new_window) |
| 71 |
|
| 72 |
await bidi_session.browser.close() |
| 73 |
|
| 74 |
# Wait for the browser to actually close. |
| 75 |
bidi_session.current_browser.wait() |
| 76 |
|
| 77 |
assert bidi_session.current_browser.is_running is False |
| 78 |
|
| 79 |
|
| 80 |
async def test_start_session_again(new_session, add_browser_capabilities): |
| 81 |
bidi_session = await new_session( |
| 82 |
capabilities={"alwaysMatch": add_browser_capabilities({})} |
| 83 |
) |
| 84 |
first_session_id = bidi_session.session_id |
| 85 |
|
| 86 |
await bidi_session.browser.close() |
| 87 |
|
| 88 |
# Wait for the browser to actually close. |
| 89 |
bidi_session.current_browser.wait() |
| 90 |
|
| 91 |
# Try to create a session again. |
| 92 |
bidi_session = await new_session( |
| 93 |
capabilities={"alwaysMatch": add_browser_capabilities({})} |
| 94 |
) |
| 95 |
|
| 96 |
assert isinstance(bidi_session.session_id, str) |
| 97 |
assert first_session_id != bidi_session.session_id |