Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webdriver-bidi] Add tests for browsingContext.locateNodes #42565

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bf298a0
[webdriver-bidi] Add tests for browsingContext.locateNodes
jimevans Oct 16, 2023
82f35d2
Split tests to align with other modules and commands
jimevans Oct 19, 2023
8635243
Adding more tests for other command properties
jimevans Oct 22, 2023
aa4adb9
Update import for browsing_context BiDi module
jimevans Oct 26, 2023
74d8255
Rename empty list start nodes test
jimevans Oct 26, 2023
35894ce
Linting fix
jimevans Oct 26, 2023
610a3d7
Add None as parameter for invalid test of locator type
jimevans Oct 26, 2023
0a9ae9d
Add non-integer parameter for testing invalid maxNodeCount values
jimevans Oct 26, 2023
57aa741
Add None as parameter for invalid test of context type
jimevans Oct 26, 2023
46f4f46
Extract navigation to page in invalid value tests
jimevans Oct 26, 2023
4c19a0f
Parameterize invalid maxNodeCount to include maxint + 1
jimevans Oct 26, 2023
ac5389e
Add tests for invalid locator values
jimevans Oct 26, 2023
a5fcb32
Move invalid tests to be in alphabetical order
jimevans Oct 26, 2023
fb511d3
Add additional tests for sandbox parameter
jimevans Oct 26, 2023
b9fa2bf
Adding additional tests for maxNodeCount
jimevans Oct 26, 2023
3f38597
Add recursive_compare for found nodes
jimevans Oct 26, 2023
aab4621
Add additional testing for startNodes
jimevans Oct 27, 2023
da3efd7
Renamed __init__ to properly have extension
jimevans Oct 27, 2023
d84bd1b
Remove 'children' nodes from expected results
jimevans Oct 27, 2023
7b9a98c
Remove 'context' check for results
jimevans Oct 27, 2023
ffd780f
Fix linting error
jimevans Oct 27, 2023
f53fd7c
Fix length of returned list
jimevans Nov 7, 2023
d8a5cbb
Update more instances of length of list
jimevans Nov 7, 2023
4afd8d6
Use result of script.evaluate directly as context nodes
jimevans Nov 7, 2023
993ccb7
Removing unneeded blank lines in files
jimevans Nov 7, 2023
64a2db8
Really fix the context nodes results from scripts
jimevans Nov 7, 2023
b3833cf
Remove whitespace from browsing_context in bidi client
jimevans Nov 7, 2023
ce43e22
Correct expected exception for invalid context value
jimevans Nov 7, 2023
2e64268
Responding to review feedback
jimevans Nov 7, 2023
c9003c6
Mark individual test as asyncio
jimevans Nov 7, 2023
bf8e898
Correct names of parameterized sets for innerText locator tests
jimevans Nov 8, 2023
a793e54
Parameterize ownership test
jimevans Nov 8, 2023
613c480
Add test for handles in different sandboxes
jimevans Nov 8, 2023
00e6257
Merge branch 'master' into webdriver-bidi-locate-nodes
jimevans Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/webdriver/webdriver/bidi/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class InvalidArgumentException(BidiException):
error_code = "invalid argument"


class InvalidSelectorError(BidiException):
error_code = "invalid selector"


class InvalidSessionIDError(BidiException):
error_code = "invalid session id"

Expand Down
34 changes: 34 additions & 0 deletions tools/webdriver/webdriver/bidi/modules/browsing_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from typing import Any, Dict, List, Mapping, MutableMapping, Optional, Union

from ._module import BidiModule, command
from .script import OwnershipModel, SerializationOptions
from ..undefined import UNDEFINED, Undefined



class ElementOptions(Dict[str, Any]):
def __init__(self, element: Mapping[str, Any]):
self["type"] = "element"
Expand Down Expand Up @@ -129,6 +131,38 @@ def handle_user_prompt(self,
params["userText"] = user_text
return params

@command
def locate_nodes(self,
context: str,
locator: Mapping[str, Any],
max_node_count: Optional[int] = None,
ownership: Optional[OwnershipModel] = None,
sandbox: Optional[str] = None,
serialization_options: Optional[SerializationOptions] = None,
start_nodes: Optional[List[Mapping[str, Any]]] = None) -> Mapping[str, Any]:
params: MutableMapping[str, Any] = {"context": context, "locator": locator}
if max_node_count is not None:
params["maxNodeCount"] = max_node_count
if ownership is not None:
params["ownership"] = ownership
if sandbox is not None:
params["sandbox"] = sandbox
if serialization_options is not None:
params["serializationOptions"] = serialization_options
if start_nodes is not None:
params["startNodes"] = start_nodes
return params

@locate_nodes.result
def _locate_nodes(self, result: Mapping[str, Any]) -> Any:
assert result["context"] is not None
assert isinstance(result["context"], str)

assert result["nodes"] is not None
assert isinstance(result["nodes"], List)

return result

@command
def navigate(self,
context: str,
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions webdriver/tests/bidi/browsing_context/locate_nodes/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
import webdriver.bidi.error as error


@pytest.mark.asyncio
async def test_params_context_invalid_value(bidi_session, inline, top_context):
url = inline("""<div>foo</div>""")
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=url, wait="complete"
)

with pytest.raises(error.NoSuchFrameException):
await bidi_session.browsing_context.locate_nodes(
context="foo", locator={ "type": "css", "value": "div" }
)
153 changes: 153 additions & 0 deletions webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import pytest
import webdriver.bidi.error as error

pytestmark = pytest.mark.asyncio


MAX_INT = 9007199254740991


async def navigate_to_page(bidi_session, inline, top_context):
url = inline("""<div>foo</div>""")
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=url, wait="complete"
)


@pytest.mark.parametrize("value", [None, False, 42, {}, []])
async def test_params_context_invalid_type(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=value, locator={"type": "css", "value": "div"}
)


@pytest.mark.parametrize("value", [None, False, 42, {}, []])
async def test_params_locator_type_invalid_type(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"], locator={ "type": value, "value": "div" }
)


@pytest.mark.parametrize("type", ["", "invalid"])
async def test_params_locator_type_invalid_value(bidi_session, inline, top_context, type):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"], locator={ "type": type, "value": "div" }
)


@pytest.mark.parametrize("type,value", [
("css", "a*b"),
("xpath", ""),
("xpath", "invalid-xpath")
("innerText", "")
])
async def test_params_locator_value_invalid_value(bidi_session, inline, top_context, type, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidSelectorException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"], locator={ "type": type, "value": value }
)


@pytest.mark.parametrize("value", [False, "string", 1.5, {}, []])
async def test_params_max_node_count_invalid_type(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "css", "value": "div" },
max_node_count=value
)


@pytest.mark.parametrize("value", [0, MAX_INT + 1])
async def test_params_max_node_count_invalid_value(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "invalid", "value": "div" },
max_node_count=value
)


@pytest.mark.parametrize("value", [False, 42, {}, []])
async def test_params_ownership_invalid_type(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "css", "value": "div" },
ownership=value
)


async def test_params_ownership_invalid_value(bidi_session, inline, top_context):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "css", "value": "div" },
ownership="foo"
)


@pytest.mark.parametrize("value", [False, 42, {}, []])
async def test_params_sandbox_invalid_type(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "css", "value": "div" },
sandbox=value
)


@pytest.mark.parametrize("value", [False, 42, "foo", []])
async def test_params_serialization_options_invalid_type(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "css", "value": "div" },
serialization_options=value
)


@pytest.mark.parametrize("value", [False, "string", 42, {}])
async def test_params_start_nodes_invalid_type(bidi_session, inline, top_context, value):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "css", "value": "div" },
start_nodes=value
)


async def test_params_start_nodes_empty_list(bidi_session, inline, top_context):
await navigate_to_page(bidi_session, inline, top_context)

with pytest.raises(error.InvalidArgumentException):
await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "invalid", "value": "div" },
start_nodes=[]
)
Loading
Loading