test(e2e): retry clipboard reads rejected by Firefox (#40155)

The Firefox mermaid e2e test fails intermittently with `Clipboard read
operation is not allowed.`, for example in
https://github.com/go-gitea/gitea/actions/runs/41281998298/job/124776072700.

Firefox rejects `readText()` when it overlaps the page's still pending
clipboard write, and `expect.poll` does not retry errors thrown by its
callback, so one overlapping read fails the test.
https://github.com/go-gitea/gitea/pull/39838 only removed the paste
prompt, not this rejection.

- A new `assertClipboardText` helper treats a rejected read as a
mismatch so it is polled again
- The bot token copy test had the same race and uses it too

_Written by Claude (Opus 5.5)._
This commit is contained in:
silverwind authored and GitHub committed 2026-11-06 20:44:00 +00:00
1 parent 7e18e81c7d
commit 24700dca2a
3 files changed
+16 -5

No files matched your search

+3 -3
View File
@@ -1,6 +1,6 @@
import {env} from 'node:process';
import {test, expect} from '@playwright/test';
import {clickDropdownItem, login, randomString} from './utils.ts';
import {assertClipboardText, clickDropdownItem, login, randomString} from './utils.ts';
test('create a bot and manage its access token', async ({page, request}) => {
const botName = `e2e-bot-${randomString(8)}`;
@@ -15,9 +15,9 @@ test('create a bot and manage its access token', async ({page, request}) => {
await page.getByLabel('Token Name').fill('e2e-token');
await page.getByRole('row', {name: /^user /}).getByRole('radio', {name: 'Read', exact: true}).check();
await page.getByRole('button', {name: 'Generate Token'}).click();
const token = await page.getByRole('code').textContent();
const token = (await page.getByRole('code').textContent())!;
await page.getByRole('button', {name: 'Copy', exact: true}).click();
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(token);
await assertClipboardText(page, token);
const response = await request.get('/api/v1/user', {headers: {Authorization: `token ${token}`}});
expect(await response.json()).toMatchObject({login: botName, type: 'Bot'});
+2 -2
View File
@@ -1,6 +1,6 @@
import {env} from 'node:process';
import {expect, test} from '@playwright/test';
import {apiCreateRepo, apiCreateIssue, assertNoJsError, randomString} from './utils.ts';
import {apiCreateRepo, apiCreateIssue, assertClipboardText, assertNoJsError, randomString} from './utils.ts';
test('mermaid diagram in issue', async ({page, request}) => {
const repoName = `e2e-mermaid-${randomString(8)}`;
@@ -22,7 +22,7 @@ test('mermaid diagram in issue', async ({page, request}) => {
await svg.hover();
await page.locator('.code-copy').click();
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(source);
await assertClipboardText(page, source);
await assertNoJsError(page);
});
+11
View File
@@ -247,6 +247,17 @@ export async function login(page: Page, username = env.GITEA_TEST_E2E_USER, pass
if (status !== 302 && status !== 303) throw new Error(`login as ${username} failed: HTTP ${status}`);
}
export async function assertClipboardText(page: Page, text: string) {
// Firefox rejects a read that overlaps the page's still pending clipboard write
await expect.poll(() => page.evaluate(async () => {
try {
return await navigator.clipboard.readText();
} catch {
return null;
}
})).toBe(text);
}
export async function assertNoJsError(page: Page) {
await expect(page.locator('.js-global-error')).toHaveCount(0);
}