From d399f844e6ecb6a5b25ae670d998f3f4183c6c1e Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 10 Nov 2026 20:07:28 +0000 Subject: [PATCH] test: fix the login tab order e2e test in macOS WebKit (#40316) The login tab order test fails in WebKit on macOS, so `make test-e2e` fails locally on every Mac. CI on Linux is unaffected. - macOS WebKit moves Tab focus only between text fields, plus buttons and checkboxes when the system keyboard navigation setting is on, and never to links, like Safari. Option+Tab reaches every element there and acts as Tab in Linux WebKit, so the test presses Alt+Tab in WebKit. - Headless WebKit applies the username `autofocus` late, which pulled focus back from the password field. The test now waits for the autofocus first, which also covers it. Follow-up to https://github.com/go-gitea/gitea/pull/40081 Assisted-by: Claude Code:claude-opus-5-5 --- tests/e2e/login.test.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/e2e/login.test.ts b/tests/e2e/login.test.ts index 7b1389b30ce..c746a584b87 100644 --- a/tests/e2e/login.test.ts +++ b/tests/e2e/login.test.ts @@ -8,20 +8,19 @@ test('homepage', async ({page}) => { await expect(page.getByRole('img', {name: 'Logo'})).toHaveAttribute('src', '/assets/img/logo.svg'); }); -test('login form in tab order and logout', async ({page}) => { +test('login form in tab order and logout', async ({page, browserName}) => { + const tabKey = {chromium: 'Tab', firefox: 'Tab', webkit: 'Alt+Tab'}[browserName]; await page.goto('/user/login'); - await page.getByLabel('Username or Email Address').fill(env.GITEA_TEST_E2E_USER); - await page.keyboard.press('Tab'); + const username = page.getByLabel('Username or Email Address'); + await expect(username).toBeFocused(); + await username.fill(env.GITEA_TEST_E2E_USER); const password = page.getByLabel('Password'); - await expect(password).toBeFocused(); - await password.fill(env.GITEA_TEST_E2E_PASSWORD); - await page.keyboard.press('Tab'); - await expect(page.getByLabel('Remember This Device')).toBeFocused(); - await page.keyboard.press('Tab'); const signIn = page.getByRole('button', {name: 'Sign In', exact: true}); - await expect(signIn).toBeFocused(); - await page.keyboard.press('Tab'); - await expect(page.getByRole('link', {name: 'Forgot password?'})).toBeFocused(); + for (const element of [password, page.getByLabel('Remember This Device'), signIn, page.getByRole('link', {name: 'Forgot password?'})]) { + await page.keyboard.press(tabKey); + await expect(element).toBeFocused(); + } + await password.fill(env.GITEA_TEST_E2E_PASSWORD); await signIn.click(); await expect(page.getByRole('link', {name: 'Sign In'})).toBeHidden(); await logout(page);