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

use waitForSelector instead of until #10852

Merged
merged 2 commits into from
Apr 13, 2021
Merged

Conversation

brad-decker
Copy link
Contributor

@brad-decker brad-decker commented Apr 8, 2021

This PR completes the abstraction of the until utility from Selenium.

When refactoring to use the work completed in #10844 I ran into a few cases where I believe a race condition made tests flakey at best. The waitForSelector method when passed the { state: 'detached' } options bag would try to find an element with the provided selector and wait for it to be removed from the DOM. However, in every case we used the detached flag we are triggering the close of the modal/element before we call waitForSelector. If the modal is removed from the DOM before the waitForSelector is called then it would timeout.

To fix this I have added another item into the Element API wrapper that matches the API from playwright. The new utility method is waitForElementState. It works in much the same way as the page level waitForSelector but the element handle is stable and the race condition is abated. I have left the detached support in waitForSelector because it exists in the playwright APi that it is modeled after.

@brad-decker brad-decker force-pushed the use-until-abstraction branch 2 times, most recently from 45ab932 to fed5bdb Compare April 12, 2021 22:00
@metamaskbot
Copy link
Collaborator

Builds ready [db0f57e]
Page Load Metrics (622 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint45685863
domContentLoaded40383562111756
load40483662211756
domInteractive40383562011756

@brad-decker brad-decker marked this pull request as ready for review April 12, 2021 22:29
@brad-decker brad-decker requested a review from a team as a code owner April 12, 2021 22:29
@brad-decker brad-decker requested a review from danjm April 12, 2021 22:29
case 'visible':
return await driver.wait(until.elementIsVisible(element), timeout);
default:
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Should this throw? I'm having trouble imagining how this could be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, yeah.

await driver.wait(until.elementTextMatches(balances[0], /1/u), 15000);
const balance = await balances[0].getText();

assert.equal(balance, '1');
Copy link
Member

Choose a reason for hiding this comment

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

I believe the intent of this assertion was to ensure this test doesn't pass if the balance is a number containing the digit 1 (e.g. 1.51, 100, etc.). It might be worth preserving this assertion, both here and below where a similar assertion was 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.

will do! Thanks

@Gudahtt
Copy link
Member

Gudahtt commented Apr 13, 2021

I think this is the last step in completing #10755

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 [7a49c63]
Page Load Metrics (561 ± 32 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint43735494
domContentLoaded3676175596732
load3696185616732
domInteractive3676175596732

@brad-decker brad-decker merged commit 57be0e4 into develop Apr 13, 2021
@brad-decker brad-decker deleted the use-until-abstraction branch April 13, 2021 21:36
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 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