From 027251d7646dc3a8d7105a7e24a5ceb2ab79bcbf Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Mon, 22 May 2023 14:05:28 +0000 Subject: [PATCH] Bug 1832028 - [wdspec] Add test for NoSuchElement error with input.ElementOrigin r=webdriver-reviewers,jgraham Depends on D178185 Differential Revision: https://phabricator.services.mozilla.com/D178186 --- .../tools/webdriver/webdriver/bidi/error.py | 4 ++ .../bidi/input/perform_actions/invalid.py | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/testing/web-platform/tests/tools/webdriver/webdriver/bidi/error.py b/testing/web-platform/tests/tools/webdriver/webdriver/bidi/error.py index 6a02e65ba5a8..21c9f720a8eb 100644 --- a/testing/web-platform/tests/tools/webdriver/webdriver/bidi/error.py +++ b/testing/web-platform/tests/tools/webdriver/webdriver/bidi/error.py @@ -39,6 +39,10 @@ class MoveTargetOutOfBoundsException(BidiException): error_code = "move target out of bounds" +class NoSuchElementException(BidiException): + error_code = "no such element" + + class NoSuchFrameException(BidiException): error_code = "no such frame" diff --git a/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/invalid.py b/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/invalid.py index b07802292c9b..2fb45cd8321e 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/invalid.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/invalid.py @@ -4,9 +4,11 @@ from webdriver.bidi.modules.input import Actions, get_element_origin from webdriver.bidi.error import ( InvalidArgumentException, MoveTargetOutOfBoundsException, + NoSuchElementException, NoSuchFrameException, NoSuchNodeException, ) +from webdriver.bidi.modules.script import ContextTarget pytestmark = pytest.mark.asyncio @@ -160,6 +162,51 @@ async def test_params_actions_origin_invalid_value_serialized_element( actions=actions, context=top_context["context"] ) +@pytest.mark.parametrize( + "expression", + [ + "document.querySelector('input#button').attributes[0]", + "document.querySelector('#with-text-node').childNodes[0]", + """document.createProcessingInstruction("xml-stylesheet", "href='foo.css'")""", + "document.querySelector('#with-comment').childNodes[0]", + "document", + "document.doctype", + "document.createDocumentFragment()", + "document.querySelector('#custom-element').shadowRoot", + ], + ids=[ + "attribute", + "text node", + "processing instruction", + "comment", + "document", + "doctype", + "document fragment", + "shadow root", + ] +) +async def test_params_actions_origin_no_such_element( + bidi_session, top_context, get_test_page, expression +): + await bidi_session.browsing_context.navigate( + context=top_context["context"], + url=get_test_page(), + wait="complete", + ) + + node = await bidi_session.script.evaluate( + expression=expression, + target=ContextTarget(top_context["context"]), + await_promise=False, + ) + + actions = Actions() + actions.add_pointer().pointer_move(x=0, y=0, origin=get_element_origin(node)) + with pytest.raises(NoSuchElementException): + await bidi_session.input.perform_actions( + actions=actions, context=top_context["context"] + ) + async def test_params_actions_origin_no_such_node(bidi_session, top_context): actions = Actions()