Repository navigation
Translate locator resolution to WebDriver BiDi so locators work on Firefox - #44
Merged
Merged
Conversation
…refox
Every selector strategy that queries the page evaluates to an array of
elements and reads each one back with Runtime.getProperties, which had no
BiDi translation, so no locator, locator action or assertion could find an
element on Firefox. Adding that translation alone was not enough: the call
translation sent its object reference as { type: "handle", value } and
dropped any argument that was not a plain value, and results came back in
BiDi's typed remote value shape instead of plain JSON, so a bounding box,
a selected option list or an element passed as an argument never arrived.
Runtime.getProperties now becomes a script.callFunction that returns the
object to itself one level deep. Nodes are handed out by their BiDi shared
id, prefixed so they can be told apart from handles when they come back as
this or as an argument, which also gives an element the same id whichever
query found it. Arguments become BiDi local values, results are rebuilt as
the JSON a CDP call by value returns, and DOM.setFileInputFiles becomes
input.setFiles. A locator rooted at the main frame is now measured like a
page-level one instead of through the Chromium-only box model.
GetByRole, role= selectors and the accessible name and role assertions read
the accessibility tree, which BiDi does not expose. They stay Chromium-only
and now fail at once on Firefox with a message that says why.
Signed-off-by: Torrey Betts <torrey.betts@gmail.com>
SummarySummary
CoverageMotus - 81.6%
Motus.Abstractions - 87.7%
Motus.Analyzers - 91%
Motus.Cli - 82.2%
Motus.Codegen - 89.8%
Motus.Mcp - 91.9%
Motus.Mcp.Http - 98.6%
Motus.Recorder - 77.8%
Motus.Testing - 75.4%
Motus.Testing.MSTest - 79%
Motus.Testing.MSTest.v4 - 22.8%
Motus.Testing.xUnit - 63.6%
|
Contributor
Author
|
Tests run for this change:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Firefox no locator could find an element. Every selector strategy that queries the page evaluates its query to an array of elements and reads each one back with Runtime.getProperties, which had no WebDriver BiDi translation, so locator actions, the assertions and anything built on them failed before looking at the page. That was only the first gap on the path: the call translation sent its object reference in a shape BiDi rejects and dropped any argument that was not a plain value, and results came back as BiDi typed remote values instead of JSON, so a click never got its bounding box and an object returned from script arrived as key and value pairs.
Runtime.getProperties now becomes a script.callFunction that returns the object to itself one level deep, and each element or entry becomes a property. DOM nodes are handed out by their BiDi shared id, prefixed so they can be told apart from handles when they come back as this or as an argument, which also gives an element the same id whichever query found it, so the locator's de-duplication works as on Chromium. Call arguments become BiDi local values (elements, arrays and objects included, an empty one as undefined so later ones keep their positions), results are rebuilt as the JSON a CDP call by value returns, and DOM.setFileInputFiles translates to input.setFiles. A locator rooted at the main frame is measured like a page-level one rather than through the Chromium-only box model.
GetByRole, role= selectors and the accessible name and role assertions read the accessibility tree, which BiDi does not expose. They stay Chromium-only and now fail at once on Firefox with a message that says why. The frame context id the issue mentions needed nothing, since BiDi resolves no context ids, but a Firefox page still reports no child frames, so a locator inside an iframe has no IFrame to start from. That, ILocator.ScreenshotAsync (no Page.captureScreenshot translation) and DblClickAsync (Firefox sees two single clicks) remain open and are documented.
Behavior changes: locators, locator actions and locator assertions work on Firefox apart from the cases above. On Firefox, objects and arrays returned from script arrive as plain JSON instead of BiDi remote values. On Firefox, GetByRole and role= selectors throw NotSupportedException with a new message naming the accessibility tree, and ToHaveAccessibleNameAsync and ToHaveRoleAsync throw it before resolving the element instead of after. A locator built from page.MainFrame measures and scrolls exactly like one built from the page, and on Chromium no longer sends DOM.getBoxModel for it.
Fixes #41
Signed-off-by: Torrey Betts torrey.betts@gmail.com