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

[wdspec] add context locator tests involving iframes and shadow DOM #50047

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

OrKoN
Copy link
Contributor

@OrKoN OrKoN commented Jan 13, 2025

No description provided.

@OrKoN OrKoN force-pushed the orkon/context-locator-invalid branch from 74ab0d7 to 785d8ac Compare January 13, 2025 09:47
@OrKoN OrKoN changed the title [wdspec] extend invalid context value tests and add an iframe test [wdspec] add context locator tests involving iframes and shadow DOM Jan 13, 2025
@@ -76,7 +76,7 @@ async def test_params_locator_accessability_value_invalid_type(
("xpath", ""),
("innerText", ""),
("accessibility", {}),
("context", {})
("context", {"context": ""})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should have a dedicated test as well for invalid types similar to the accessibility locator.

Note that the accessibility value the line above is wrong as well and is actually an invalid type test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@pytest.mark.asyncio
async def test_locate_by_context_invalid_context(bidi_session, inline, top_context, domain):
iframe_url_2 = inline("<div>foo</div>", domain=domain)
iframe_url_1 = inline(f"<div><iframe src='{iframe_url_2}'></iframe></div>", domain=domain)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the iframe fixture in those two lines. I assume we don't have to put it inside a div as well, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -218,3 +218,24 @@ async def test_params_start_nodes_dom_node_not_element(
locator={"type": "css", "value": "div"},
start_nodes=[remote_reference],
)


@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this invalid case I don't see the need to check cross origin. Is there a reason why you added it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it actually might make sense to check both depending on whether the implementation incorrectly relies on checking if the context is valid by checking its presence in the same renderer process (which is up to implementation).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(still lgtm though)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check the happy case for both same-process and OOPiF, while keep invalid arg test generic. I can hardly imagine significant regression here.

iframe_url_1 = inline("<div id='in-iframe'>foo</div>", domain=domain)
page_url = inline(f"<iframe src='{iframe_url_1}'></iframe>")
iframe_url_1 = inline("<div>foo</div>", domain=domain)
page_url = inline(f"<iframe id='target' src='{iframe_url_1}'></iframe>")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the iframefixture here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iframe fixture does not support custom id attributes, which is useful for assertion in this and the following tests.

@pytest.mark.parametrize("mode", ["open", "closed"])
@pytest.mark.asyncio
async def test_locate_by_context_in_shadow_dom(bidi_session, inline, top_context, domain, mode):
iframe_url_1 = inline(f"<div>foo</div>", domain=domain)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the get_test_page fixture to all the setup basically in one line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no way to opt out iframe creation in get_test_page, which makes using it in this context more indirect, as there will be 2 iframes

@sadym-chromium
Copy link
Contributor

@whimboo FYI I'm taking the PR over from @OrKoN

Copy link
Contributor Author

@OrKoN OrKoN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants