Skip to content

Commit d3e9a20

Browse files
committed
update e2e tests with screenshots
1 parent 817b94f commit d3e9a20

File tree

9 files changed

+25
-9
lines changed

9 files changed

+25
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"prepare": "husky",
1414
"start": "wp-scripts start",
1515
"test:e2e": "wp-scripts test-playwright",
16+
"test:e2e:debug": "wp-scripts test-playwright --ui",
1617
"test:js": "wp-scripts test-unit-js",
1718
"test:js:update": "wp-scripts test-unit-js --updateSnapshot",
1819
"test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.ts",

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig({
1717
use: {
1818
baseURL: process.env.WP_BASE_URL,
1919
trace: 'on-first-retry',
20-
permissions: ['clipboard-read'],
20+
permissions: ['clipboard-write', 'clipboard-read'],
2121
},
2222

2323
projects: [

tests/e2e/feature-flags.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ test.describe('Feature flags', () => {
9797
).toBeVisible();
9898

9999
// Check PHP Snippet clipboard details
100-
await page.getByLabel('Copy to clipboard').first().click();
100+
await page.getByRole('button').nth(1).click();
101+
102+
// await page.getByLabel('Copy to clipboard').first().click();
101103
const phpClipboardText = await page.evaluate(
102104
'navigator.clipboard.readText()'
103105
);
104106
expect(phpClipboardText).toContain(`Flag::is_enabled( '${flagName}' )`);
105107

106108
// Check JS Snippet clipboard details
107-
await page.getByLabel('Copy to clipboard').nth(1).click();
109+
await page.getByRole('button').nth(2).click();
108110
const jsClipboardText: string = await page.evaluate(
109111
'navigator.clipboard.readText()'
110112
);
17.9 KB
Loading
19.1 KB
Loading

tests/e2e/screenshots/no-flags.png

5.38 KB
Loading
20.5 KB
Loading
29.4 KB
Loading

tests/e2e/visual-comparison.spec.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
1+
import { test } from '@wordpress/e2e-test-utils-playwright';
22
import {
33
AddNewFlagAndFill,
44
CloseSdkModal,
@@ -23,7 +23,9 @@ test.describe('Visual tests', () => {
2323
});
2424

2525
test('Feature flags screen without flags', async ({ page }) => {
26-
await expect(page).toHaveScreenshot('no-flags.png');
26+
await page
27+
.locator('#codeb_feature_flags_settings_screen')
28+
.screenshot({ path: 'tests/e2e/screenshots/no-flags.png' });
2729
});
2830

2931
test('Feature flags screen with some flags', async ({ page }) => {
@@ -33,13 +35,18 @@ test.describe('Visual tests', () => {
3335
await AddNewFlagAndFill(page, 'healthCheck');
3436

3537
await SaveFlags(page);
36-
await expect(page).toHaveScreenshot('some-flags.png');
38+
39+
await page
40+
.locator('#codeb_feature_flags_settings_screen')
41+
.screenshot({ path: 'tests/e2e/screenshots/some-flags.png' });
3742
});
3843

3944
test('Toggle feature flag', async ({ page }) => {
4045
await AddNewFlagAndFill(page, 'auth0');
4146
await DisableFlag(page, true);
42-
await expect(page).toHaveScreenshot('flag-disabled.png');
47+
await page
48+
.locator('#codeb_feature_flags_settings_screen')
49+
.screenshot({ path: 'tests/e2e/screenshots/flag-disabled.png' });
4350
});
4451

4552
test('Delete flag modal', async ({ page }) => {
@@ -51,7 +58,11 @@ test.describe('Visual tests', () => {
5158
.getByLabel('Delete Flag')
5259
.click();
5360

54-
await expect(page).toHaveScreenshot('delete-flag-modal.png');
61+
await page
62+
.locator('#codeb_feature_flags_settings_screen')
63+
.screenshot({
64+
path: 'tests/e2e/screenshots/delete-flag-modal.png',
65+
});
5566

5667
await page.getByRole('button', { name: 'Yes' }).click();
5768
});
@@ -60,7 +71,9 @@ test.describe('Visual tests', () => {
6071
await AddNewFlagAndFill(page, 'drag-drop');
6172
await OpenSdkModal(page);
6273

63-
await expect(page).toHaveScreenshot('sdk-modal.png');
74+
await page
75+
.locator('#codeb_feature_flags_settings_screen')
76+
.screenshot({ path: 'tests/e2e/screenshots/sdk-modal.png' });
6477

6578
await CloseSdkModal(page);
6679
});

0 commit comments

Comments
 (0)