Skip to content

Commit

Permalink
feat: refined tests and util function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Florez authored and Sergio Florez committed Jan 27, 2025
1 parent 34dd332 commit 97cedae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
7 changes: 4 additions & 3 deletions tests/login/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { expect, test } from '@playwright/test';
import { caritasRework } from '../config';
import { goToPage } from '../utils';

test('Login as an advice seeker', async ({ page }) => {
test('User login', async ({ page }) => {
const username = process.env.TEST_USERNAME;
const password = process.env.TEST_PASSWORD;
const loginButton = page.locator('button.button__item.button__primary');
await page.goto(`${caritasRework.dev}`);

await goToPage(page, 'login');
await page.fill('input[id="username"]', username!);
await page.fill('input[id="passwordInput"]', password!);
await loginButton.click();
Expand Down
21 changes: 7 additions & 14 deletions tests/registration/registration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { test, expect } from '@playwright/test';
import { caritasRework } from '../config';
import { ensureLanguage, generateRandomAlphanumeric } from '../utils';
import { goToPage, generateRandomAlphanumeric } from '../utils';

// checks if the page has the home titles
test('Check registration page title and subtitle', async ({ page }) => {
await page.goto(`${caritasRework.dev}registration`);
// registration is skipped until a delete user function is implemented
test('User registration', async ({ page }) => {
const password = process.env.TEST_PASSWORD;
await goToPage(page, 'registration');
await expect(page.locator('h1.headline--1')).toBeVisible();
await expect(page.locator('h4.headline--4')).toBeVisible();
});

// registration test is skipped until a delete user account feature is implemented
test.skip('Complete registration process', async ({ page }) => {
const password = process.env.TEST_PASSWORD;
await page.goto(`${caritasRework.dev}registration`);
ensureLanguage(page);
await page.click('a[data-cy="button-register"]');

// registration form
await page.click('div[id="panel-Children, teenagers, adults and family"]');
await page.click('label[data-cy="topic-selection-radio-1"]');
await page.click('button[data-cy="button-next"]');
Expand All @@ -28,8 +20,9 @@ test.skip('Complete registration process', async ({ page }) => {
.click();
await page.click('button[data-cy="button-next"]');

// username & password
const randomUsername = `testuser_${generateRandomAlphanumeric(3)}`;

// to-do: replace getByLabel lines with locator by id when delete method is implemented
await page.getByLabel(/(user\s?name|benutzername)/i).fill(randomUsername);
await page
.getByLabel(/pass\s?(word|wort)/i, { exact: true })
Expand Down
4 changes: 2 additions & 2 deletions tests/registration/registrationAgencyLink.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@playwright/test';

test.skip('registration via agency link', async ({ page }) => {
//
test.fixme('Registration via agency link', async ({ page }) => {
// to implement
});
4 changes: 2 additions & 2 deletions tests/registration/registrationConsultantLink.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@playwright/test';

test.skip('registration via consultant link', async ({ page }) => {
//
test.fixme('Registration via consultant link', async ({ page }) => {
// to implement
});
25 changes: 16 additions & 9 deletions tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { expect, Page } from '@playwright/test';
import { caritasRework } from './config';

export function generateRandomAlphanumeric(length: number): string {
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * chars.length);
result += chars[randomIndex];
}
return result;
export async function goToPage(page: Page, path: string) {
const env = process.env.TEST_ENV || 'dev';
const baseURL = caritasRework[env];
await page.goto(`${baseURL}${path}`);
}

export async function ensureLanguage(page: Page) {
Expand All @@ -23,3 +19,14 @@ export async function ensureLanguage(page: Page) {

expect(['en', 'de']).toContain(pageLang);
}

export function generateRandomAlphanumeric(length: number): string {
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * chars.length);
result += chars[randomIndex];
}
return result;
}

0 comments on commit 97cedae

Please sign in to comment.