Skip to content

Commit 44a2064

Browse files
authored
[Website] Fix flaky phpMyAdmin test (#2977)
## Motivation for the change, related issues The phpMyAdmin E2E test seems to be flaky in Firefox: ``` ✘ 32 [firefox] › packages/playground/website/playwright/e2e/website-ui.spec.ts:433:6 › Database panel › should load and open phpMyAdmin (retry #3) (42.0s) 1) [firefox] › packages/playground/website/playwright/e2e/website-ui.spec.ts:433:6 › Database panel › should load and open phpMyAdmin Error: expect(locator).toBeVisible() failed Locator: locator('form#insertForm, form[name="insertForm"]') Expected: visible Received: <element(s) not found> Timeout: 10000ms Call log: - Expect "toBeVisible" with timeout 10000ms - waiting for locator('form#insertForm, form[name="insertForm"]') 472 | 'form#insertForm, form[name="insertForm"]' 473 | ); > 474 | await expect(pmaForm).toBeVisible({ timeout: 10000 }); | ^ 475 | await expect(pmaForm).toContainText('Welcome to WordPress.'); 476 | 477 | // Update the post content at /home/runner/work/wordpress-playground/wordpress-playground/packages/playground/website/playwright/e2e/website-ui.spec.ts:474:25 Error Context: packages/playground/website/test-results/website-ui-Database-panel-should-load-and-open-phpMyAdmin-firefox/error-context.md ``` ## Implementation details The issue appears to be that phpMyAdmin handles screen navigation using custom AJAX handlers, which may ignore link clicks when another AJAX request is still in progress. This is implemented in their [AJAX module](https://github.com/phpmyadmin/phpmyadmin/blob/3925c2237701050ee34f5ba79d74fda808673d4f/resources/js/modules/ajax.ts) that is exposed globally on `window.AJAX`. I tried other approaches like waiting for a loader to disappear, but no luck. This approach seems to be the only reliable one. ## Testing Instructions (or ideally a Blueprint) See the CI passing.
1 parent 1acf498 commit 44a2064

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/playground/website/playwright/e2e/website-ui.spec.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ test.describe('Database panel', () => {
360360

361361
test('should load and open Adminer', async ({ website, context }) => {
362362
const adminerButton = website.page.getByRole('button', {
363-
name: /Open Adminer/i,
363+
name: 'Open Adminer',
364364
});
365365
await expect(adminerButton).toBeVisible();
366366
await expect(adminerButton).toBeEnabled();
@@ -432,7 +432,7 @@ test.describe('Database panel', () => {
432432

433433
test('should load and open phpMyAdmin', async ({ website, context }) => {
434434
const phpMyAdminButton = website.page.getByRole('button', {
435-
name: /Open phpMyAdmin/i,
435+
name: 'Open phpMyAdmin',
436436
});
437437
await expect(phpMyAdminButton).toBeVisible();
438438
await expect(phpMyAdminButton).toBeEnabled();
@@ -450,32 +450,43 @@ test.describe('Database panel', () => {
450450
await expect(newPage.locator('body')).toContainText('phpMyAdmin');
451451
await expect(newPage.locator('body')).toContainText('wp_posts');
452452

453+
/*
454+
* Before clicking a link in phpMyAdmin, we need to wait for any AJAX
455+
* requests to be done. This prevents flaky tests (mainly in Firefox).
456+
*
457+
* @see https://github.com/phpmyadmin/phpmyadmin/blob/3925c2237701050ee34f5ba79d74fda808673d4f/resources/js/modules/ajax.ts
458+
*/
459+
const waitForAjaxIdle = async () =>
460+
newPage.waitForFunction(() => {
461+
return (window as any).AJAX?.active === false;
462+
});
463+
453464
// Browse the "wp_posts" table
454465
const wpPostsRow = newPage
455466
.locator('tr')
456467
.filter({ hasText: 'wp_posts' })
457468
.first();
458-
await expect(wpPostsRow).toBeVisible({ timeout: 10000 });
469+
await expect(wpPostsRow).toBeVisible();
470+
await waitForAjaxIdle();
459471
await wpPostsRow.getByRole('link', { name: 'Browse' }).click();
460472
await newPage.waitForLoadState();
461473
const pmaRows = newPage.locator('table.table_results tbody tr');
462474
await expect(pmaRows.first()).toContainText('Welcome to WordPress.');
463475

464476
// Click "edit" on a row
477+
await waitForAjaxIdle();
465478
await pmaRows
466479
.first()
467480
.getByRole('link', { name: 'Edit' })
468481
.first()
469482
.click();
470483
await newPage.waitForLoadState();
471-
const pmaForm = newPage.locator(
472-
'form#insertForm, form[name="insertForm"]'
473-
);
474-
await expect(pmaForm).toBeVisible({ timeout: 10000 });
475-
await expect(pmaForm).toContainText('Welcome to WordPress.');
484+
const editForm = newPage.locator('form#insertForm');
485+
await expect(editForm).toBeVisible();
486+
await expect(editForm).toContainText('Welcome to WordPress.');
476487

477488
// Update the post content
478-
const postContentRow = pmaForm
489+
const postContentRow = editForm
479490
.locator('tr')
480491
.filter({ hasText: 'post_content' })
481492
.first();

0 commit comments

Comments
 (0)