Skip to content

Commit

Permalink
Merge pull request #10 from virtualidentityag/feat/CONNECTA-297-playw…
Browse files Browse the repository at this point in the history
…right-setup

feat: playwright setup first step
  • Loading branch information
sfvcode authored Jan 27, 2025
2 parents 3c39317 + 7bf4e1b commit d7b0c51
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Playwright Tests
on:
push:
branches: [develop]
pull_request:
branches: [develop]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
env:
TEST_USERNAME: ${{ secrets.TEST_USERNAME }}
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.idea/
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@cypress/webpack-dev-server": "^3.5.1",
"@cypress/webpack-preprocessor": "^6.0.1",
"@dtsgenerator/replace-namespace": "^1.6.0",
"@playwright/test": "^1.48.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@storybook/addon-essentials": "^7.0.18",
"@storybook/addon-interactions": "^7.0.18",
Expand Down
80 changes: 80 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
import dotenv from 'dotenv';
import path from 'path';
dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/

export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry'
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] }
}

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
]

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
8 changes: 8 additions & 0 deletions tests/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const caritasRework = {
dev: 'https://dev.caritas-rework.dev.virtual-identity.net/',
stage: 'https://beratung-rework-staging.caritas.de/',
prod: 'https://beratung.caritas.de/'
};

// write util functions here in config or in another file?
// util functions being general checks in all registration pages and so on
22 changes: 22 additions & 0 deletions tests/login/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect, test } from '@playwright/test';
import { goToPage } from '../utils';

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 goToPage(page, 'login');
await page.fill('input[id="username"]', username!);
await page.fill('input[id="passwordInput"]', password!);
await loginButton.click();
await page.locator('.sessionsList__illustration__image').click();
await expect(page.locator('a[href="/profile"]')).toBeVisible();
await expect(page.locator('div[id="local-switch-wrapper"]')).toBeVisible();
await page
.locator('svg[aria-label="Log out"]')
.nth(0)
.click({ force: true });
await expect(page.locator('h1.headline--1')).toBeVisible();
await expect(page.locator('h4.headline--4')).toBeVisible();
});
41 changes: 41 additions & 0 deletions tests/registration/registration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { test, expect } from '@playwright/test';
import { goToPage, generateRandomAlphanumeric } from '../utils';

// registration is skipped until a delete user function is implemented
test.skip('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();
await page.click('a[data-cy="button-register"]');

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"]');
await page.fill('input[data-cy="input-postal-code"]', '99999');
await page.click('button[data-cy="button-next"]');
await page
.locator('input[name="agency-selection-radio-group"]')
.first()
.click();
await page.click('button[data-cy="button-next"]');

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 })
.first()
.fill(password!);
await page
.getByLabel(/(passwort\s?wiederholen|repeat\s?password)/i)
.fill(password!);
await page
.getByLabel(/Ich habe die Datenschutzerklä|I have the Privacy policy/)
.check();
await page.click('button[data-cy="button-register"]');
await page
.getByRole('button', { name: /Nachricht verfassen|Compose message/ })
.click();
});
5 changes: 5 additions & 0 deletions tests/registration/registrationAgencyLink.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '@playwright/test';

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

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

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) {
let pageLang = (await page.getAttribute('html', 'lang')) || '';

if (!['en', 'de'].includes(pageLang)) {
await page.evaluate(() => {
document.documentElement.lang = 'en';
});
pageLang = 'en';
}

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 d7b0c51

Please sign in to comment.