-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
FIX #20253 : Acceptance Flake (Docker): The Watch A Video button does not open the right page! (Docker Setup) #20273
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,6 +410,30 @@ export class BaseUser { | |
getCurrentUrlWithoutParameters(): string { | ||
return this.page.url().split('?')[0]; | ||
} | ||
|
||
/** | ||
* This function Waits for a specific text to appear in the body of the page. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "This function waits"... |
||
* This function only waits for rendered text. It does not wait for text in iframes or text that is hidden or not rendered for some reason. | ||
* The text matching is case-sensitive and space-sensitive, so it might not find the text if there are differences in case or white space. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised these lines aren't throwing lint errors -- aren't they too long? Why is prettier not running locally on your submitted code? Can you get this fixed in your development environment? |
||
* @param {string} text - The text to wait for. | ||
* @param {number} [timeout=30000] - The maximum time to wait in milliseconds. Defaults to 30000 (30 seconds). | ||
*/ | ||
async waitForText(text: string, timeout: number = 30000): Promise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. waitForTextToAppearInPageBody Change timeout to timeoutMsec -- always include units. |
||
try { | ||
await this.page.waitForSelector('body'); | ||
await this.page.waitForFunction( | ||
(textToFind: string) => { | ||
const bodyText = document.querySelector('body')?.innerText || ''; | ||
return bodyText.includes(textToFind); | ||
}, | ||
{ timeout }, | ||
text | ||
); | ||
} catch (error) { | ||
error.message = `Failed to find text "${text}" within ${timeout} ms.`; | ||
throw error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change it to: |
||
} | ||
} | ||
} | ||
|
||
export const BaseUserFactory = (): BaseUser => new BaseUser(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,10 +674,11 @@ export class LoggedInUser extends BaseUser { | |
throw new Error('The Watch A Video button does not exist!'); | ||
} | ||
await Promise.all([ | ||
this.page.waitForNavigation(), | ||
this.page.waitForNavigation({waitUntil: ['load', 'networkidle2']}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we already have this waitUntil, do we still need the new function waitForText in order to fix the flake? |
||
this.clickOn(watchAVideoButton), | ||
]); | ||
|
||
await this.waitForText('Create New Account'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we waiting for a certain text to be displayed instead of finding the relevant selector and using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @StephenYu2018 Actually, the page we’re navigating to is a Facebook page. Here, we encounter selectors such as Thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you use the text "Create New Account"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, for cases like this, I think what I would suggest is to just verify that the URL of the new page is correct and that the navigation stabilizes. The reason I suggest that is because we don't want our tests to break if Facebook (say) changes how they render their page, which is something that's out of our control. Given that, do you think it would be enough to wait for navigation to stabilize? |
||
const url = this.getCurrentUrlWithoutParameters(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Occasionally, the URL was being fetched before the page had fully loaded, leading to differences with the expected URL. Therefore, made changes to ensure the page is fully loaded before the URL is fetched. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what the URL is in the intermediate stage and what it is after the page settles down? |
||
const expectedWatchAVideoUrl = this.isViewportAtMobileWidth() | ||
? mobileWatchAVideoUrl | ||
|
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.
Why do we have this function -- why isn't "wait for text to be displayed" sufficient? This method would pick up hidden text in the body or div elements etc., which does not match with what the end user would see on the page.