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

add abstraction for waitForSelector #10844

Merged
merged 1 commit into from
Apr 8, 2021
Merged

add abstraction for waitForSelector #10844

merged 1 commit into from
Apr 8, 2021

Conversation

brad-decker
Copy link
Contributor

Adds an abstraction for waitForSelector, a method that exists in the playwright API. This abstraction aims to eventually become a paper-thin abstraction over the playwright version. In the meantime until is used behind the scenes to mimick the behavior.

Included is a refactor of metamask-ui.spec.js which served as a robustness check for the utility.

// Providing a text prop, and optionally a tag or css prop, will use
// xpath to look for an element with the tag that has matching text.
if (locator.css) {
// When providing css prop we use cssToXPath to build a xpath string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A majority of our usage of until.elementMatchesText was using a css selector then waiting until the returned element had matching text. Building an xpath combining CSS selection and text selection more closely mimics Playwright's API (page.waitForSelector('.hello >> text="hi"'). XPath IS slower than CSS selectors, BUT in the case of searching for text, it is not possible without XPath. Combining them into XPath is likely faster than issuing two statements looking for both a CSS selector AND then waiting for text to match.

In the end, though, this entire method (buildLocator) will go away and we will use the much more powerful and expressive playwright selector API.

@metamaskbot
Copy link
Collaborator

Builds ready [a3c1468]
Page Load Metrics (645 ± 34 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint47725874
domContentLoaded4287576437034
load4317586457034
domInteractive4287576437034

@brad-decker brad-decker marked this pull request as ready for review April 7, 2021 19:33
@brad-decker brad-decker requested a review from a team as a code owner April 7, 2021 19:33
@brad-decker brad-decker requested review from shanejonas and Gudahtt and removed request for shanejonas April 7, 2021 19:33
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

This looks fantastic! This seems like a very good way of abstracting this functionality. I just had a couple of questions about the metamask-ui.spec.js changes.

test/e2e/metamask-ui.spec.js Outdated Show resolved Hide resolved
test/e2e/metamask-ui.spec.js Show resolved Hide resolved
test/e2e/metamask-ui.spec.js Outdated Show resolved Hide resolved
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [71870f4]
Page Load Metrics (586 ± 43 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint46685773
domContentLoaded3506685858943
load3526695868943
domInteractive3506685848943

@brad-decker brad-decker merged commit 9079fb8 into develop Apr 8, 2021
@brad-decker brad-decker deleted the until-abstraction branch April 8, 2021 15:41
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants