-
Notifications
You must be signed in to change notification settings - Fork 237
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
remove needless hovers and visibility checks from e2e #3440
Conversation
1e31830
to
b69baec
Compare
b69baec
to
7ac8e2c
Compare
7ac8e2c
to
a0f2ddd
Compare
a0f2ddd
to
004ecb5
Compare
In our e2e tests, there were many patterns like (where `x` is some Playwright locator, ie a selector query resolved by polling): ``` await x.hover() await x.click() ``` The intent of this was to give extra time for `x` to become visible. But this is unnecessary because Playwright's `.click()` already auto-waits for the locator to become [actionable (see Playwright's definition)](https://playwright.dev/docs/actionability). The effect of these 2 lines is just to double the timeout (from 3s to 6s), which is not usually necessary. If a longer timeout is indeed needed, you can use `.click({timeout: N})`, and if a longer timeout than 3s is ever needed by default, we can update `playwright.config.ts` (but I don't think that's needed). Same goes for this pattern: ``` await expect(x).toBeVisible() x.click() ``` Playwright's definition of actionability (linked above) already checks for visibility. In some cases where the intent of `await x.hover()` was to wait for something to become visible, I changed it to `await expect(x).toBeVisible()` for clarity. There should be no behavior change (other than 3s not 6s timeouts) with these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason this worked is because hover()
does not throw if the element is not found after the timeout?
@philipp-spiess It does throw. It worked (aka was harmless) because it was being used as either a visibility check or a way to give a click an extra timeout. |
I don't recall the specifics (and can't access the slack threads), but I remember having some weird issues on Windows where clicks just didn't work without a hover before them and I don't believe it was visibility related. When running some tests locally (on Windows) I could see the buttons on the screen and the test was just paused waiting to click (and eventually would time out), but if I manually moved my mouse over the button then suddenly the test would continue. It was almost like clicks didn't always work unless there had been a mouseover event first. I couldn't find any good reasons for it though, but I noticed some other tests were doing the same and passing, so I added the hovers and things passed 😞 |
In our e2e tests, there were many patterns like (where
x
is some Playwright locator, ie a selector query resolved by polling):The intent of this pattern is (except in rare cases where hovering is actually needed) to give extra time for
x
to become visible. But this is unnecessary because Playwright's.click()
already auto-waits for the locator to become actionable (see Playwright's definition). The effect of these 2 lines is just to double the timeout (from 3s to 6s), which is not usually necessary. If a longer timeout is indeed needed, you can use.click({timeout: N})
, and if a longer timeout than 3s is ever needed by default, we can updateplaywright.config.ts
(but I don't think that's needed).Same goes for this pattern:
Playwright's definition of actionability (linked above) already checks for visibility.
In some cases where the intent of
await x.hover()
was to wait for something to become visible, I changed it toawait expect(x).toBeVisible()
for clarity.There should be no behavior change (other than 3s not 6s timeouts) with these changes.
Test plan
CI