Skip to content

Commit d0e865a

Browse files
test(e2e): wait for navigation to be ready to avoid flaky failures
Ensure tests wait for navigation/UI readiness before proceeding to assertions, reducing flakiness.
1 parent 89ed45a commit d0e865a

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

test/integration/utils.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { Page } from '@playwright/test';
33

44
export const BASE_URL = `http://localhost:${process.env.WORDPRESS_PORT}`;
55

6-
export async function uploadMedia(page: Page, file: string) {
6+
export async function uploadMedia(page: Page, file: string): Promise<string> {
77
await page.goto('/wp-admin/media-new.php?browser-uploader');
88
const fileChooserPromise = page.waitForEvent('filechooser');
99
await page.getByLabel('Upload').click();
1010
const fileChooser = await fileChooserPromise;
1111
await fileChooser.setFiles(path.join(__dirname, `../fixtures/${file}`));
12-
await page.locator('#html-upload').click();
12+
await Promise.all([
13+
page.waitForURL('**/wp-admin/upload.php**', { waitUntil: 'load' }),
14+
page.locator('#html-upload').click(),
15+
]);
16+
1317
await page.goto('/wp-admin/upload.php?mode=list');
1418

1519
const row = await page.locator('table.wp-list-table tbody > tr').first();
@@ -19,10 +23,12 @@ export async function uploadMedia(page: Page, file: string) {
1923

2024
const rowID = await row.getAttribute('id');
2125
const attachmentID = rowID?.split('-')[1];
22-
await page.goto(`/wp-admin/post.php?post=${attachmentID}&action=edit`);
26+
await Promise.all([
27+
page.waitForURL(new RegExp(`/wp-admin/post\\.php\\?post=${attachmentID}&action=edit$`), { waitUntil: 'load' }),
28+
page.goto(`/wp-admin/post.php?post=${attachmentID}&action=edit`),
29+
]);
2330

24-
const imageURL = await page.locator('input[name="attachment_url"]').inputValue();
25-
return imageURL;
31+
return page.locator('input[name="attachment_url"]').inputValue();
2632
}
2733

2834
export async function clearMediaLibrary(page: Page) {

0 commit comments

Comments
 (0)