-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from virtualidentityag/feat/CONNECTA-297-playw…
…right-setup feat: playwright setup first step
- Loading branch information
Showing
11 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
// }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |