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
This commit is contained in:
silverwind authored and GitHub committed 2026-11-10 20:07:28 +00:00
1 parent db23b5a192
commit d399f844e6
1 file changed
+10 -11
+10 -11
View File
@@ -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);