0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-02-23 06:25:09 +01:00

Pass e2e credentials via environment variables

Remove login_user helper and LOGIN_PASSWORD constant, pass E2E_USER
and E2E_PASSWORD from the test script to playwright via env vars.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-02-15 11:20:46 +01:00
parent f76c0acf59
commit 625e46d033
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
3 changed files with 8 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import {test, expect} from '@playwright/test';
import {login, logout, login_user} from './utils.ts';
import {login, logout} from './utils.ts';
test('homepage', async ({page}) => {
const response = await page.goto('/');
@ -8,8 +8,9 @@ test('homepage', async ({page}) => {
});
test('logged in user', async ({browser}) => {
const context = await login_user(browser, 'e2e');
const context = await browser.newContext();
const page = await context.newPage();
await login(page, 'e2e');
const response = await page.goto('/');
expect(response?.status()).toBe(200);
});

View File

@ -1,12 +1,10 @@
import {expect} from '@playwright/test';
import type {Browser, Page} from '@playwright/test';
import type {Page} from '@playwright/test';
const LOGIN_PASSWORD = 'password';
export async function login(page: Page, user: string = 'e2e') {
export async function login(page: Page, user: string = process.env.E2E_USER) {
await page.goto('/user/login');
await page.getByLabel('Username or Email Address').fill(user);
await page.getByLabel('Password').fill(LOGIN_PASSWORD);
await page.getByLabel('Password').fill(process.env.E2E_PASSWORD);
await page.getByRole('button', {name: 'Sign In'}).click();
await expect(page.getByRole('link', {name: 'Sign In'})).toBeHidden();
}
@ -15,10 +13,3 @@ export async function logout(page: Page) {
await page.getByText('Sign Out').dispatchEvent('click');
await expect(page.getByRole('link', {name: 'Sign In'})).toBeVisible();
}
export async function login_user(browser: Browser, user: string) {
const context = await browser.newContext();
const page = await context.newPage();
await login(page, user);
return context;
}

View File

@ -44,4 +44,6 @@ if ! curl -sf --max-time 5 "$GITEA_TEST_SERVER_URL/api/v1/users/$E2E_USER" > /de
fi
export GITEA_TEST_SERVER_URL
export E2E_USER
export E2E_PASSWORD
exec pnpm exec playwright test "$@"