diff --git a/webdriver/tests/bidi/input/perform_actions/key.py b/webdriver/tests/bidi/input/perform_actions/key.py
index 7deb5f1fb9900b..567400c4e89957 100644
--- a/webdriver/tests/bidi/input/perform_actions/key.py
+++ b/webdriver/tests/bidi/input/perform_actions/key.py
@@ -10,6 +10,8 @@
pytestmark = pytest.mark.asyncio
+CONTEXT_LOAD_EVENT = "browsingContext.load"
+
async def test_invalid_browsing_context(bidi_session):
actions = Actions()
@@ -20,18 +22,26 @@ async def test_invalid_browsing_context(bidi_session):
async def test_key_down_closes_browsing_context(
- bidi_session, configuration, new_tab, inline
+ bidi_session, configuration, new_tab, inline, subscribe_events,
+ wait_for_event
):
url = inline("""
close
""")
- await bidi_session.browsing_context.navigate(
- context=new_tab["context"],
- url=url,
- wait="complete",
+ # Opening a new context via `window.open` is required for script to be able
+ # to close it.
+ await subscribe_events(events=[CONTEXT_LOAD_EVENT])
+ on_load = wait_for_event(CONTEXT_LOAD_EVENT)
+
+ await bidi_session.script.evaluate(
+ expression=f"window.open('{url}')",
+ target=ContextTarget(new_tab["context"]),
+ await_promise=True
)
+ # Wait for the new context to be created and get it.
+ new_context = await on_load
actions = Actions()
(
@@ -43,7 +53,7 @@ async def test_key_down_closes_browsing_context(
with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
- actions=actions, context=new_tab["context"]
+ actions=actions, context=new_context["context"]
)
diff --git a/webdriver/tests/bidi/input/perform_actions/pointer_mouse.py b/webdriver/tests/bidi/input/perform_actions/pointer_mouse.py
index ab861a90937fad..3e10b6698cf1ec 100644
--- a/webdriver/tests/bidi/input/perform_actions/pointer_mouse.py
+++ b/webdriver/tests/bidi/input/perform_actions/pointer_mouse.py
@@ -2,6 +2,7 @@
from webdriver.bidi.error import MoveTargetOutOfBoundsException, NoSuchFrameException
from webdriver.bidi.modules.input import Actions, get_element_origin
+from webdriver.bidi.modules.script import ContextTarget
from tests.support.asserts import assert_move_to_coordinates
from tests.support.helpers import filter_dict
@@ -16,18 +17,29 @@
pytestmark = pytest.mark.asyncio
+CONTEXT_LOAD_EVENT = "browsingContext.load"
+
async def test_pointer_down_closes_browsing_context(
- bidi_session, configuration, get_element, new_tab, inline
+ bidi_session, configuration, get_element, new_tab, inline, subscribe_events,
+ wait_for_event
):
url = inline("""close""")
- await bidi_session.browsing_context.navigate(
- context=new_tab["context"],
- url=url,
- wait="complete",
+
+ # Opening a new context via `window.open` is required for script to be able
+ # to close it.
+ await subscribe_events(events=[CONTEXT_LOAD_EVENT])
+ on_load = wait_for_event(CONTEXT_LOAD_EVENT)
+
+ await bidi_session.script.evaluate(
+ expression=f"window.open('{url}')",
+ target=ContextTarget(new_tab["context"]),
+ await_promise=True
)
+ # Wait for the new context to be created and get it.
+ new_context = await on_load
- element = await get_element("input", context=new_tab)
+ element = await get_element("input", context=new_context)
origin = get_element_origin(element)
actions = Actions()
@@ -41,7 +53,7 @@ async def test_pointer_down_closes_browsing_context(
with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
- actions=actions, context=new_tab["context"]
+ actions=actions, context=new_context["context"]
)
diff --git a/webdriver/tests/bidi/input/perform_actions/pointer_pen.py b/webdriver/tests/bidi/input/perform_actions/pointer_pen.py
index cfc6beaeb4b579..f79223d61a5791 100644
--- a/webdriver/tests/bidi/input/perform_actions/pointer_pen.py
+++ b/webdriver/tests/bidi/input/perform_actions/pointer_pen.py
@@ -2,6 +2,7 @@
from webdriver.bidi.error import MoveTargetOutOfBoundsException, NoSuchFrameException
from webdriver.bidi.modules.input import Actions, get_element_origin
+from webdriver.bidi.modules.script import ContextTarget
from .. import get_events
from . import (
@@ -13,18 +14,29 @@
pytestmark = pytest.mark.asyncio
+CONTEXT_LOAD_EVENT = "browsingContext.load"
+
async def test_pointer_down_closes_browsing_context(
- bidi_session, configuration, get_element, new_tab, inline
+ bidi_session, configuration, get_element, new_tab, inline, subscribe_events,
+ wait_for_event
):
url = inline("""close""")
- await bidi_session.browsing_context.navigate(
- context=new_tab["context"],
- url=url,
- wait="complete",
+
+ # Opening a new context via `window.open` is required for script to be able
+ # to close it.
+ await subscribe_events(events=[CONTEXT_LOAD_EVENT])
+ on_load = wait_for_event(CONTEXT_LOAD_EVENT)
+
+ await bidi_session.script.evaluate(
+ expression=f"window.open('{url}')",
+ target=ContextTarget(new_tab["context"]),
+ await_promise=True
)
+ # Wait for the new context to be created and get it.
+ new_context = await on_load
- element = await get_element("input", context=new_tab)
+ element = await get_element("input", context=new_context)
origin = get_element_origin(element)
actions = Actions()
@@ -38,7 +50,7 @@ async def test_pointer_down_closes_browsing_context(
with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
- actions=actions, context=new_tab["context"]
+ actions=actions, context=new_context["context"]
)
diff --git a/webdriver/tests/bidi/input/perform_actions/pointer_touch.py b/webdriver/tests/bidi/input/perform_actions/pointer_touch.py
index 4477162b322cbf..79ff52a06b8b6f 100644
--- a/webdriver/tests/bidi/input/perform_actions/pointer_touch.py
+++ b/webdriver/tests/bidi/input/perform_actions/pointer_touch.py
@@ -2,6 +2,7 @@
from webdriver.bidi.error import MoveTargetOutOfBoundsException, NoSuchFrameException
from webdriver.bidi.modules.input import Actions, get_element_origin
+from webdriver.bidi.modules.script import ContextTarget
from .. import get_events
from . import (
@@ -13,18 +14,29 @@
pytestmark = pytest.mark.asyncio
+CONTEXT_LOAD_EVENT = "browsingContext.load"
+
async def test_pointer_down_closes_browsing_context(
- bidi_session, configuration, get_element, new_tab, inline
+ bidi_session, configuration, get_element, new_tab, inline, subscribe_events,
+ wait_for_event
):
url = inline("""close""")
- await bidi_session.browsing_context.navigate(
- context=new_tab["context"],
- url=url,
- wait="complete",
+
+ # Opening a new context via `window.open` is required for script to be able
+ # to close it.
+ await subscribe_events(events=[CONTEXT_LOAD_EVENT])
+ on_load = wait_for_event(CONTEXT_LOAD_EVENT)
+
+ await bidi_session.script.evaluate(
+ expression=f"window.open('{url}')",
+ target=ContextTarget(new_tab["context"]),
+ await_promise=True
)
+ # Wait for the new context to be created and get it.
+ new_context = await on_load
- element = await get_element("input", context=new_tab)
+ element = await get_element("input", context=new_context)
origin = get_element_origin(element)
actions = Actions()
@@ -38,7 +50,7 @@ async def test_pointer_down_closes_browsing_context(
with pytest.raises(NoSuchFrameException):
await bidi_session.input.perform_actions(
- actions=actions, context=new_tab["context"]
+ actions=actions, context=new_context["context"]
)