-
Notifications
You must be signed in to change notification settings - Fork 79
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
e2e-test: more notebook fixes #5154
Conversation
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.
LGTM!
// basic CSS selection doesn't support frames (or nested frames) | ||
const frame = this.code.driver.getFrame(OUTER_FRAME).frameLocator(INNER_FRAME); | ||
const element = frame.locator(`${MARKDOWN_TEXT} ${tag}`); | ||
const text = await element.textContent(); |
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.
just an example, but this is what was problematic. the text is being retrieved immediately, which means it might grab the content before it’s fully rendered or updated, causing the assertion to happen before the text is actually correct/ready... which would def lead to flakes.
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.
LGTM! And thanks for the tip on how to assert the text!
Intent
Make the
notebookCreate.test.ts
more stable / less flakey.Approach
The main issue I noticed with the notebook creation test was that we weren’t properly asserting the text content of locators. We were fetching the locator and then immediately verifying its text. This works fine for non-async code, but since we are dealing with asynchronous behavior, this approach isn’t reliable. Instead, we should leverage Playwright’s built-in retry mechanism in the expect methods, which will automatically keep checking the locator until its text matches the expected value or the timeout is reached.
I'm hoping some of the fixes help other tests that rely on executing code, etc. 🤞
Examples
Don't Do This
This approach fails immediately if the element’s text is not ready.
Do This
Playwright will retry until the element contains the expected text, making it more resilient.
Tip
Your
await
should always precede theexpect
and never be "inside" it (like in the first example).