Skip to content

Commit 27a9b12

Browse files
committed
Revert "Use static test identifiers instead of random strings"
This reverts commit 4851ff6.
1 parent 4851ff6 commit 27a9b12

10 files changed

Lines changed: 46 additions & 25 deletions

tests/e2e/codeeditor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {env} from 'node:process';
22
import {expect, test} from '@playwright/test';
3-
import {login, apiCreateRepo, apiDeleteRepo} from './utils.ts';
3+
import {login, apiCreateRepo, apiDeleteRepo, randomString} from './utils.ts';
44

55
test('codeeditor textarea updates correctly', async ({page, request}) => {
6-
const repoName = 'e2e-codeeditor';
6+
const repoName = `e2e-codeeditor-${randomString(8)}`;
77
await apiCreateRepo(request, {name: repoName});
88
try {
99
await login(page);

tests/e2e/events.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {test, expect} from '@playwright/test';
2-
import {loginUser, baseUrl, apiUserHeaders, apiCreateUser, apiDeleteUser, apiCreateRepo, apiCreateIssue, apiStartStopwatch, timeoutFactor} from './utils.ts';
2+
import {loginUser, baseUrl, apiUserHeaders, apiCreateUser, apiDeleteUser, apiCreateRepo, apiCreateIssue, apiStartStopwatch, timeoutFactor, randomString} from './utils.ts';
33

44
// These tests rely on a short EVENT_SOURCE_UPDATE_TIME in the e2e server config.
55
test.describe('events', () => {
66
test('notification count', async ({page, request}) => {
7-
const owner = 'ev-notif-owner';
8-
const commenter = 'ev-notif-commenter';
9-
const repoName = 'ev-notif';
7+
const id = `ev-notif-${randomString(8)}`;
8+
const owner = `${id}-owner`;
9+
const commenter = `${id}-commenter`;
10+
const repoName = id;
1011

1112
await Promise.all([apiCreateUser(request, owner), apiCreateUser(request, commenter)]);
1213

@@ -29,7 +30,7 @@ test.describe('events', () => {
2930
});
3031

3132
test('stopwatch', async ({page, request}) => {
32-
const name = 'ev-sw';
33+
const name = `ev-sw-${randomString(8)}`;
3334
const headers = apiUserHeaders(name);
3435

3536
await apiCreateUser(request, name);
@@ -51,7 +52,7 @@ test.describe('events', () => {
5152
});
5253

5354
test('logout propagation', async ({browser, request}) => {
54-
const name = 'ev-logout';
55+
const name = `ev-logout-${randomString(8)}`;
5556

5657
await apiCreateUser(request, name);
5758

tests/e2e/milestone.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {env} from 'node:process';
22
import {test, expect} from '@playwright/test';
3-
import {login, apiCreateRepo, apiDeleteRepo} from './utils.ts';
3+
import {login, apiCreateRepo, apiDeleteRepo, randomString} from './utils.ts';
44

55
test('create a milestone', async ({page}) => {
6-
const repoName = 'e2e-milestone';
6+
const repoName = `e2e-milestone-${randomString(8)}`;
77
await login(page);
88
await apiCreateRepo(page.request, {name: repoName});
99
await page.goto(`/${env.GITEA_TEST_E2E_USER}/${repoName}/milestones/new`);

tests/e2e/org.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {test, expect} from '@playwright/test';
2-
import {login, apiDeleteOrg} from './utils.ts';
2+
import {login, apiDeleteOrg, randomString} from './utils.ts';
33

44
test('create an organization', async ({page}) => {
5-
const orgName = 'e2e-org';
5+
const orgName = `e2e-org-${randomString(8)}`;
66
await login(page);
77
await page.goto('/org/create');
88
await page.getByLabel('Organization Name').fill(orgName);

tests/e2e/reactions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {env} from 'node:process';
22
import {expect, test} from '@playwright/test';
3-
import {login, apiCreateRepo, apiCreateIssue, apiDeleteRepo} from './utils.ts';
3+
import {login, apiCreateRepo, apiCreateIssue, apiDeleteRepo, randomString} from './utils.ts';
44

55
test('toggle issue reactions', async ({page, request}) => {
6-
const repoName = 'e2e-reactions';
6+
const repoName = `e2e-reactions-${randomString(8)}`;
77
const owner = env.GITEA_TEST_E2E_USER;
88
await apiCreateRepo(request, {name: repoName});
99
await Promise.all([

tests/e2e/readme.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {env} from 'node:process';
22
import {test, expect} from '@playwright/test';
3-
import {apiCreateRepo, apiDeleteRepo} from './utils.ts';
3+
import {apiCreateRepo, apiDeleteRepo, randomString} from './utils.ts';
44

55
test('repo readme', async ({page}) => {
6-
const repoName = 'e2e-readme';
6+
const repoName = `e2e-readme-${randomString(8)}`;
77
await apiCreateRepo(page.request, {name: repoName});
88
await page.goto(`/${env.GITEA_TEST_E2E_USER}/${repoName}`);
99
await expect(page.locator('#readme')).toContainText(repoName);

tests/e2e/register.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {env} from 'node:process';
22
import {test, expect} from '@playwright/test';
3-
import {login, logout, apiDeleteUser} from './utils.ts';
3+
import {login, logout, apiDeleteUser, randomString} from './utils.ts';
44

55
test.beforeEach(async ({page}) => {
66
await page.goto('/user/sign_up');
@@ -32,7 +32,7 @@ test('register with mismatched passwords shows error', async ({page}) => {
3232
});
3333

3434
test('register then login', async ({page}) => {
35-
const username = 'e2e-register';
35+
const username = `e2e-register-${randomString(8)}`;
3636
const email = `${username}@${env.GITEA_TEST_E2E_DOMAIN}`;
3737
const password = 'password123!';
3838

tests/e2e/repo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {env} from 'node:process';
22
import {test} from '@playwright/test';
3-
import {login, apiDeleteRepo} from './utils.ts';
3+
import {login, apiDeleteRepo, randomString} from './utils.ts';
44

55
test('create a repository', async ({page}) => {
6-
const repoName = 'e2e-repo';
6+
const repoName = `e2e-repo-${randomString(8)}`;
77
await login(page);
88
await page.goto('/repo/create');
99
await page.locator('input[name="repo_name"]').fill(repoName);

tests/e2e/user-settings.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {test, expect} from '@playwright/test';
2-
import {login} from './utils.ts';
2+
import {login, randomString} from './utils.ts';
33

44
test('update profile biography', async ({page}) => {
5-
const bio = 'e2e-bio';
5+
const bio = `e2e-bio-${randomString(8)}`;
66
await login(page);
77
await page.goto('/user/settings');
88
await page.getByLabel('Biography').fill(bio);

tests/e2e/utils.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import {env} from 'node:process';
22
import {expect} from '@playwright/test';
3-
import type {APIRequestContext, Page} from '@playwright/test';
3+
import type {APIRequestContext, Locator, Page} from '@playwright/test';
44

55
export const timeoutFactor = Number(env.GITEA_TEST_E2E_TIMEOUT_FACTOR) || 1;
66

7+
/** Generate a random alphanumerical string. */
8+
export function randomString(length: number): string {
9+
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
10+
let result = '';
11+
for (let idx = 0; idx < length; idx++) {
12+
result += chars.charAt(Math.floor(Math.random() * chars.length));
13+
}
14+
return result;
15+
}
16+
717
export function baseUrl() {
818
return env.GITEA_TEST_E2E_URL?.replace(/\/$/g, '');
919
}
@@ -62,8 +72,13 @@ export async function apiDeleteOrg(requestContext: APIRequestContext, name: stri
6272
}), 'apiDeleteOrg');
6373
}
6474

65-
/** Password shared by all test users — used for both API user creation and browser login. */
66-
const testUserPassword = 'e2e-password!aA1';
75+
/** Generate a random password that satisfies the complexity requirements. */
76+
function generatePassword() {
77+
return `${randomString(12)}!aA1`;
78+
}
79+
80+
/** Random password shared by all test users — used for both API user creation and browser login. */
81+
const testUserPassword = generatePassword();
6782

6883
export function apiUserHeaders(username: string) {
6984
return apiAuthHeader(username, testUserPassword);
@@ -82,6 +97,11 @@ export async function apiDeleteUser(requestContext: APIRequestContext, username:
8297
}), 'apiDeleteUser');
8398
}
8499

100+
export async function clickDropdownItem(page: Page, trigger: Locator, itemText: string) {
101+
await trigger.click();
102+
await page.getByText(itemText).click();
103+
}
104+
85105
export async function loginUser(page: Page, username: string) {
86106
return login(page, username, testUserPassword);
87107
}

0 commit comments

Comments
 (0)