-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(e2e-test): random failures on navigations
- Loading branch information
1 parent
3dead24
commit a04376f
Showing
4 changed files
with
96 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Page } from "puppeteer"; | ||
|
||
const URL_CHECKING_INTERVAL = 500; | ||
const URL_CHECKING_TIMEOUT = 10000; | ||
/** | ||
* Clicks on an element and waits until indirect navigations complete. | ||
* In case of multiple navigations performed by the application with unpredictable timings | ||
* you might want to wait for the current URL to match some string before returning. | ||
* @param page - Page instance. | ||
* @param selector - Selector of the element to click on. | ||
* @param waitFor - substring that is expected to be a part of the URL. | ||
* @returns current URL. | ||
*/ | ||
export const clickAndNavigate = async ( | ||
page: Page, | ||
selector: string, | ||
waitFor?: string | ||
) => { | ||
await Promise.all([ | ||
page.waitForNavigation({ | ||
waitUntil: ["load", "domcontentloaded", "networkidle0"], | ||
}), | ||
page.click(selector), | ||
]); | ||
let currentUrl = page.url(); | ||
if (waitFor) { | ||
for (let i = 0; i < URL_CHECKING_TIMEOUT / URL_CHECKING_INTERVAL; i++) { | ||
await page.waitForTimeout(URL_CHECKING_INTERVAL); | ||
currentUrl = page.url(); | ||
if (currentUrl.indexOf(waitFor) !== -1) { | ||
break; | ||
} | ||
} | ||
} | ||
return currentUrl; | ||
}; |