Skip to content

Commit 4fd56a1

Browse files
author
0ko
committed
tests(e2e): Various fixes to visual testing (#6569)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6569 Reviewed-by: 0ko <0ko@noreply.codeberg.org>
2 parents 909738e + e7299eb commit 4fd56a1

13 files changed

+34
-20
lines changed

tests/e2e/actions.test.e2e.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ test('workflow dispatch box not available for unauthenticated users', async ({pa
7171
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
7272

7373
await expect(page.locator('body')).not.toContainText(workflow_trigger_notification_text);
74+
await save_visual(page);
7475
});

tests/e2e/clipboard-copy.test.e2e.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// @watch end
99

1010
import {expect} from '@playwright/test';
11-
import {test} from './utils_e2e.ts';
11+
import {save_visual, test} from './utils_e2e.ts';
1212

1313
test('copy src file path to clipboard', async ({page}, workerInfo) => {
1414
test.skip(['Mobile Safari', 'webkit'].includes(workerInfo.project.name), 'Apple clipboard API addon - starting at just $499!');
@@ -19,6 +19,7 @@ test('copy src file path to clipboard', async ({page}, workerInfo) => {
1919
await page.click('[data-clipboard-text]');
2020
const clipboardText = await page.evaluate(() => navigator.clipboard.readText());
2121
expect(clipboardText).toContain('README.md');
22+
await save_visual(page);
2223
});
2324

2425
test('copy diff file path to clipboard', async ({page}, workerInfo) => {
@@ -30,4 +31,6 @@ test('copy diff file path to clipboard', async ({page}, workerInfo) => {
3031
await page.click('[data-clipboard-text]');
3132
const clipboardText = await page.evaluate(() => navigator.clipboard.readText());
3233
expect(clipboardText).toContain('README.md');
34+
await expect(page.getByText('Copied')).toBeVisible();
35+
await save_visual(page);
3336
});

tests/e2e/dashboard-ci-status.test.e2e.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @watch end
44

55
import {expect} from '@playwright/test';
6-
import {save_visual, test} from './utils_e2e.ts';
6+
import {test} from './utils_e2e.ts';
77

88
test.use({user: 'user2'});
99

@@ -23,5 +23,6 @@ test('Correct link and tooltip', async ({page}, testInfo) => {
2323
const repoStatus = page.locator('.dashboard-repos .repo-owner-name-list > li:nth-child(1) > a:nth-child(2)');
2424
await expect(repoStatus).toHaveAttribute('href', '/user2/test_workflows/actions', {timeout: 10000});
2525
await expect(repoStatus).toHaveAttribute('data-tooltip-content', /^(Error|Failure)$/);
26-
await save_visual(page);
26+
// ToDo: Ensure stable screenshot of dashboard. Known to be flaky: https://code.forgejo.org/forgejo/visual-browser-testing/commit/206d4cfb7a4af6d8d7043026cdd4d63708798b2a
27+
// await save_visual(page);
2728
});

tests/e2e/e2e_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func TestE2e(t *testing.T) {
8282

8383
runArgs := []string{"npx", "playwright", "test"}
8484

85+
_, testVisual := os.LookupEnv("VISUAL_TEST")
8586
// To update snapshot outputs
8687
if _, set := os.LookupEnv("ACCEPT_VISUAL"); set {
8788
runArgs = append(runArgs, "--update-snapshots")
@@ -105,6 +106,10 @@ func TestE2e(t *testing.T) {
105106
onForgejoRun(t, func(*testing.T, *url.URL) {
106107
defer DeclareGitRepos(t)()
107108
thisTest := runArgs
109+
// when all tests are run, use unique artifacts directories per test to preserve artifacts from other tests
110+
if testVisual {
111+
thisTest = append(thisTest, "--output=tests/e2e/test-artifacts/"+testname)
112+
}
108113
thisTest = append(thisTest, path)
109114
cmd := exec.Command(runArgs[0], thisTest...)
110115
cmd.Env = os.Environ()
@@ -114,7 +119,7 @@ func TestE2e(t *testing.T) {
114119
cmd.Stderr = os.Stderr
115120

116121
err := cmd.Run()
117-
if err != nil {
122+
if err != nil && !testVisual {
118123
log.Fatal("Playwright Failed: %s", err)
119124
}
120125
})

tests/e2e/example.test.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @watch end
66

77
import {expect} from '@playwright/test';
8-
import {test} from './utils_e2e.ts';
8+
import {save_visual, test} from './utils_e2e.ts';
99

1010
test('Load Homepage', async ({page}) => {
1111
const response = await page.goto('/');
@@ -26,6 +26,7 @@ test('Register Form', async ({page}, workerInfo) => {
2626
expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`);
2727
await expect(page.locator('.secondary-nav span>img.ui.avatar')).toBeVisible();
2828
await expect(page.locator('.ui.positive.message.flash-success')).toHaveText('Account was successfully created. Welcome!');
29+
await save_visual(page);
2930
});
3031

3132
// eslint-disable-next-line playwright/no-skipped-test

tests/e2e/explore.test.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// @watch end
88

99
import {expect} from '@playwright/test';
10-
import {test} from './utils_e2e.ts';
10+
import {save_visual, test} from './utils_e2e.ts';
1111

1212
test('Explore view taborder', async ({page}) => {
1313
await page.goto('/explore/repos');
@@ -42,4 +42,5 @@ test('Explore view taborder', async ({page}) => {
4242
}
4343
}
4444
expect(res).toBe(exp);
45+
await save_visual(page);
4546
});

tests/e2e/markup.test.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @watch end
44

55
import {expect} from '@playwright/test';
6-
import {test} from './utils_e2e.ts';
6+
import {save_visual, test} from './utils_e2e.ts';
77

88
test('markup with #xyz-mode-only', async ({page}) => {
99
const response = await page.goto('/user2/repo1/issues/1');
@@ -13,4 +13,5 @@ test('markup with #xyz-mode-only', async ({page}) => {
1313
await expect(comment).toBeVisible();
1414
await expect(comment.locator('[src$="#gh-light-mode-only"]')).toBeVisible();
1515
await expect(comment.locator('[src$="#gh-dark-mode-only"]')).toBeHidden();
16+
await save_visual(page);
1617
});

tests/e2e/repo-code.test.e2e.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ test('Line Range Selection', async ({page}) => {
4949
// out-of-bounds end line
5050
await page.goto(`${filePath}#L1-L100`);
5151
await assertSelectedLines(page, ['1', '2', '3']);
52+
await save_visual(page);
5253
});
5354

5455
test('Readable diff', async ({page}, workerInfo) => {
@@ -75,6 +76,7 @@ test('Readable diff', async ({page}, workerInfo) => {
7576
await expect(page.getByText(thisDiff.added, {exact: true})).toHaveCSS('background-color', 'rgb(134, 239, 172)');
7677
}
7778
}
79+
await save_visual(page);
7880
});
7981

8082
test.describe('As authenticated user', () => {

tests/e2e/repo-commitgraph.test.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @watch end
66

77
import {expect} from '@playwright/test';
8-
import {test} from './utils_e2e.ts';
8+
import {save_visual, test} from './utils_e2e.ts';
99

1010
test('Commit graph overflow', async ({page}) => {
1111
await page.goto('/user2/diff-test/graph');
@@ -28,4 +28,5 @@ test('Switch branch', async ({page}) => {
2828
await expect(page.locator('#loading-indicator')).toBeHidden();
2929
await expect(page.locator('#rel-container')).toBeVisible();
3030
await expect(page.locator('#rev-container')).toBeVisible();
31+
await save_visual(page);
3132
});

tests/e2e/repo-migrate.test.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ test('Migration Progress Page', async ({page, browser}, workerInfo) => {
2121
await form.locator('button.primary').click({timeout: 5000});
2222
await expect(page).toHaveURL('user2/invalidrepo');
2323
await save_visual(page);
24-
// page screenshot of unauthenticatedPage is checked automatically after the test
2524

2625
const ctx = await test_context(browser);
2726
const unauthenticatedPage = await ctx.newPage();
@@ -37,4 +36,6 @@ test('Migration Progress Page', async ({page, browser}, workerInfo) => {
3736
await save_visual(page);
3837
await deleteModal.getByRole('button', {name: 'Delete repository'}).click();
3938
await expect(page).toHaveURL('/');
39+
// checked last to preserve the order of screenshots from first run
40+
await save_visual(unauthenticatedPage);
4041
});

0 commit comments

Comments
 (0)