Skip to content

Commit

Permalink
Spsh 266 pw reset (#6)
Browse files Browse the repository at this point in the history
* test case pw-reset finished

* fix regarding new landing page

* menue.page deleted

* Variable NewPW_Username nach new_password umbenannt

* text_warning_pwReset entfernt, da bereits definiert,

* Prüfung ob Text vorhanden ist jetzt mit expect und toBeVisible anstatt locator.click

* Findings aus review behoben
  • Loading branch information
jakobmadp authored Jan 29, 2024
1 parent 66112ea commit 774efd0
Show file tree
Hide file tree
Showing 13 changed files with 445 additions and 175 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

# Oft verwendetet Konsolenbefehle

## Einen bestimmten Test ausführen:
USER="xxx" PW="xxx" npx playwright test TF0001.spec.ts
## Eine bestimmte Testfall-Datei ausführen:
USER="xxx" PW="xxx" npx playwright test login.spec.ts

## Einen bestimmten Testfall innerhalb einer Datei ausführen:
USER='xxx' PW='xxx' npx playwright test -g "SPSH-122 Angebote" --headed

## Alle Tests ausführen:
USER="xxx" PW="xxx" npx playwright test

## Umgebungsvariablen überschreiben
gitbash: USER='xxx' PW='xxx' npx playwright test TF0001.spec.ts --headed

powershell:
$env:USER="xxx"
npx playwright test 00_Authentifizierung.spec.ts --headed
npx playwright test login.spec.ts --headed

## Einen Report von der Testausführung öffnen:
npx playwright show-report results\results-2023-10-06T13_49_14_593
Expand All @@ -22,11 +22,11 @@ npx playwright show-report results\results-2023-10-06T13_49_14_593
npx playwright codegen https://test.dev.spsh.dbildungsplattform.de

## debug-mode:
git bash: PWDEBUG=1 npx playwright test 00_Authentifizierung.spec.ts --headed
git bash: PWDEBUG=1 npx playwright test login.spec.ts --headed

powershell:
PWDEBUG=1
npx playwright test 00_Authentifizierung.spec.ts --headed
npx playwright test login.spec.ts --headed

## ESLint ausführen
`npm run lint`
Expand Down
398 changes: 281 additions & 117 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"devDependencies": {
"@playwright/test": "^1.37.1",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.13.0",
"@typescript-eslint/parser": "^6.13.0",
"dotenv": "^16.3.1",
Expand All @@ -14,7 +15,8 @@
"dependencies": {
"@fast-csv/format": "^4.3.5",
"@fast-csv/parse": "^4.3.6",
"fast-csv": "^4.3.6"
"fast-csv": "^4.3.6",
"generate-password-ts": "^1.6.5"
},
"name": "schulportal-testautomatisierung",
"description": "",
Expand Down
11 changes: 11 additions & 0 deletions pages/header.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { type Locator, Page } from '@playwright/test';

export class HeaderPage{
readonly page: Page;
readonly button_logout: Locator;

constructor(page){
this.page = page;
this.button_logout = page.getByTestId('nav-logout-button');
}
}
5 changes: 4 additions & 1 deletion pages/landing.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { type Locator, Page } from '@playwright/test';
export class LandingPage{
readonly page: Page;
readonly text_h1_UeberschriftStartseite: Locator;
readonly text_Willkommen: Locator;
readonly button_Anmelden: Locator;

constructor(page){
this.page = page;
this.text_h1_UeberschriftStartseite = page.getByRole('heading', { name: 'This is gonna be a landing page' });
this.text_Willkommen = page.getByText('Willkommen im Schulportal SH.');
this.button_Anmelden = page.getByTestId('login-button');
}
}
25 changes: 22 additions & 3 deletions pages/login.page.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { expect, type Locator, Page } from '@playwright/test';
import generator from 'generate-password-ts';

export class LoginPage{
readonly page: Page;
readonly input_username: Locator;
readonly input_password: Locator;
readonly input_NewPassword: Locator;
readonly input_ConfirmPW: Locator;
readonly button_login: Locator;
readonly button_logoff: Locator;
readonly button_submitPWChange: Locator;
readonly text_h1: Locator;
readonly text_h1_updatePW: Locator;
readonly text_span_inputerror: Locator;

constructor(page){
this.page = page;
this.text_h1 = page.getByRole('heading', { name: 'Sign in to your account' });
this.input_username = page.getByLabel('Username or email');
this.input_password = page.getByLabel('Password');
this.text_h1_updatePW = page.getByText('You need to change your password to activate your account.')
this.input_username = page.locator('#username');
this.input_password = page.locator('#password');
this.input_NewPassword = page.getByLabel('New Password');
this.input_ConfirmPW = page.getByLabel('Confirm password');
this.button_login = page.getByRole('button', { name: 'Sign In' });
this.button_submitPWChange = page.getByRole('button', { name: 'Submit' });
this.text_span_inputerror = page.getByText('Invalid username or password.');
}

Expand All @@ -26,4 +34,15 @@ export class LoginPage{
await this.input_password.fill(password);
await this.button_login.click();
}

async UpdatePW(){
let new_Password = '';
new_Password = generator.generate({ length: 10, numbers: true });
await expect(this.text_h1_updatePW).toBeVisible();
await this.input_NewPassword.click();
await this.input_NewPassword.fill(new_Password);
await this.input_ConfirmPW.click();
await this.input_ConfirmPW.fill(new_Password);
await this.button_submitPWChange.click();
}
}
15 changes: 0 additions & 15 deletions pages/menue.page.ts

This file was deleted.

2 changes: 2 additions & 0 deletions pages/start.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export class StartPage{
readonly text_h2_Ueberschrift: Locator;
readonly card_item_email: Locator;
readonly card_item_itslearning: Locator;
readonly card_item_schulportal_administration: Locator;

constructor(page){
this.page = page;
this.text_h2_Ueberschrift = page.getByRole('heading', { name: 'Alle Angebote' });
this.card_item_email = page.getByTestId('provider-card-1');
this.card_item_itslearning = page.getByTestId('provider-card-2');
this.card_item_schulportal_administration = page.getByTestId('provider-card-admin');
}
}
11 changes: 11 additions & 0 deletions pages/user_management.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { type Locator, Page } from '@playwright/test';

export class UserManagementPage{
readonly page: Page;
readonly text_h2: Locator;

constructor(page){
this.page = page;
this.text_h2 = page.getByRole('heading', { name: "Benutzerverwaltung" });
}
}
23 changes: 23 additions & 0 deletions pages/user_management_detail.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { type Locator, Page } from '@playwright/test';

export class UserManagementDetailPage{
readonly page: Page;
readonly text_h2: Locator;
readonly button_pwChange: Locator;
readonly button_pwReset: Locator;
readonly text_pwResetInfo: Locator;
readonly icon_pwVisible: Locator;
readonly input_pw: Locator;
readonly button_close_pwreset: Locator;

constructor(page){
this.page = page;
this.text_h2 = page.getByRole('heading', { name: 'Benutzer bearbeiten' });
this.button_pwChange = page.getByTestId('open-password-reset-dialog-icon');
this.button_pwReset = page.getByTestId('password-reset-button');
this.text_pwResetInfo = page.getByTestId('password-reset-info-text');
this.icon_pwVisible = page.getByTestId('show-password-icon');
this.input_pw = page.locator('[data-testid="password-output-field"] input');
this.button_close_pwreset = page.getByTestId('close-password-reset-dialog-button');
}
}
20 changes: 7 additions & 13 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/login.page';
import { LandingPage } from '../pages/landing.page';
import { MenuePage } from '../pages/menue.page';
import { StartPage } from '../pages/start.page';

const PW = process.env.PW;
const USER = process.env.USER;
const URL_PORTAL = process.env.URL_PORTAL;

test.describe(`Testfälle für die Authentifizierung: Umgebung: ${process.env.UMGEBUNG}: URL: ${process.env.URL_PORTAL}:`, () => {
test('Erfolgreicher Standard Login ohne Rolle', async ({ page }) => {
test('SPSH-63 Erfolgreicher Standard Login ohne Rolle', async ({ page }) => {
const Login = new LoginPage(page);
const Landing = new LandingPage(page);
const Menue = new MenuePage(page);
const Start = new StartPage(page);

await test.step(`Anmelden mit Benutzer ${USER}`, async () => {
await page.goto(URL_PORTAL);
await expect(Landing.text_h1_UeberschriftStartseite).toBeVisible();
await Menue.button_Anmelden.click();
await expect(Landing.text_Willkommen).toBeVisible();
await Landing.button_Anmelden.click();
await Login.login(USER, PW);
await expect(Landing.text_h1_UeberschriftStartseite).toBeVisible();
await Menue.button_Startseite.click();
await expect(Start.text_h2_Ueberschrift).toBeVisible();
})
})

test('Erfolgloser Login mit falschem Passwort', async ({ page }) => {
test('SPSH-109 Erfolgloser Login mit falschem Passwort', async ({ page }) => {
const Login = new LoginPage(page);
const Landing = new LandingPage(page);
const Menue = new MenuePage(page);

await test.step(`Anmelden mit Benutzer ${USER}`, async () => {
await page.goto(URL_PORTAL);
await expect(Landing.text_h1_UeberschriftStartseite).toBeVisible();
await Menue.button_Anmelden.click();
await expect(Landing.text_Willkommen).toBeVisible();
await Landing.button_Anmelden.click();
await Login.login(USER, 'Mickeymouse');
await expect(Login.text_span_inputerror).toBeVisible();
await expect(Login.text_h1).toBeVisible();
Expand Down
18 changes: 11 additions & 7 deletions tests/logoff.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { test, expect } from '@playwright/test';
import { LandingPage } from '../pages/landing.page';
import { StartPage } from '../pages/start.page';
import { LoginPage } from '../pages/login.page';
import { MenuePage } from '../pages/menue.page';
import { HeaderPage } from '../pages/header.page';

const PW = process.env.PW;
const USER = process.env.USER;
const URL_PORTAL = process.env.URL_PORTAL;

test.describe(`Testfälle für die Authentifizierung: Umgebung: ${process.env.UMGEBUNG}: URL: ${process.env.URL_PORTAL}:`, () => {
test('Erfolgreicher Standard Logoff', async ({ page }) => {
test('SPSH-185 Erfolgreicher Standard Logoff', async ({ page }) => {
const Landing = new LandingPage(page);
const Startseite = new StartPage(page)
const Login = new LoginPage(page);
const Menue = new MenuePage(page);
const Header = new HeaderPage(page);

await test.step(`Annmelden mit Benutzer ${USER}`, async () => {
await page.goto(URL_PORTAL);
await Menue.button_Anmelden.click();
await Landing.button_Anmelden.click();
await Login.login(USER, PW);
await expect(Menue.button_Abmelden).toBeVisible();
await expect(Startseite.text_h2_Ueberschrift).toBeVisible();
})

await test.step(`Abmelden Benutzer ${USER}`, async () => {
await Menue.button_Abmelden.click();
await expect(Menue.button_Anmelden).toBeEnabled();
await Header.button_logout.click();
await expect(Landing.text_Willkommen).toBeEnabled();
})
})
})
72 changes: 62 additions & 10 deletions tests/workflow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
import { test, expect } from '@playwright/test';
import { LandingPage } from '../pages/landing.page';
import { LoginPage } from '../pages/login.page';
import { MenuePage } from '../pages/menue.page';
import { StartPage } from '../pages/start.page';
import { Email4TeacherPage } from '../pages/email4teacher.page';
import { ItsLearningPage } from '../pages/itslearning.page';
import { UserManagementPage } from '../pages/user_management.page';
import { UserManagementDetailPage } from '../pages/user_management_detail.page';
import { HeaderPage } from '../pages/header.page';

const PW = process.env.PW;
const USER = process.env.USER;
const URL_PORTAL = process.env.URL_PORTAL;

test.describe(`Testfälle für den Test von workflows: Umgebung: ${process.env.UMGEBUNG}: URL: ${process.env.URL_PORTAL}:`, () => {
test('SPSH-122 Angebote per Link öffnen', async ({ page}) => {
const Landing = new LandingPage(page);
const Login = new LoginPage(page);
const Menue = new MenuePage(page);
const Startseite = new StartPage(page);

await test.step(`Portal öffnen ${URL_PORTAL}`, async () => {
await page.goto(URL_PORTAL);
})

await test.step(`Annmelden mit Benutzer ${USER}`, async () => {
await Menue.button_Anmelden.click();
await Landing.button_Anmelden.click();
await Login.login(USER, PW);
await expect(Menue.button_Abmelden).toBeVisible();
})

await test.step(`Startseite öffnen`, async () => {
await Menue.button_Startseite.click();
await Startseite.text_h2_Ueberschrift.click();
await expect(Startseite.text_h2_Ueberschrift).toBeVisible();
})

await test.step(`Kacheln Email für Lehrkräfte und Itslearning öffnen, danach beide Kacheln wieder schließen`, async () => {
Expand All @@ -48,7 +46,61 @@ test.describe(`Testfälle für den Test von workflows: Umgebung: ${process.env.U
})

await test.step(`Prüfen, dass die Startseite noch geöffnet ist`, async () => {
await Startseite.text_h2_Ueberschrift.click();
await expect(Startseite.text_h2_Ueberschrift).toBeVisible();
})
})

test('SPSH-215 Passwort Reset', async ({ page}) => {
const Landing = new LandingPage(page);
const Login = new LoginPage(page);
const Startseite = new StartPage(page);
const UserManagement = new UserManagementPage(page);
const UserManagementDetail = new UserManagementDetailPage(page);
const Header = new HeaderPage(page);
const username_lastname = 'Max';
let new_password = '';

await test.step(`Portal öffnen ${URL_PORTAL}`, async () => {
await page.goto(URL_PORTAL);
})

await test.step(`Annmelden mit Administrator ${USER}`, async () => {
await Landing.button_Anmelden.click();
await Login.login(USER, PW);
await expect(Startseite.text_h2_Ueberschrift).toBeVisible();
})

await test.step(`Benutzerverwaltung öffnen`, async () => {
await Startseite.card_item_schulportal_administration.click();
})

await test.step(`In der Benutzerverwaltung die Zeile für Benutzer ${username_lastname} anklicken und User-Details öffnen`, async () => {
await expect(UserManagement.text_h2).toBeVisible();
await page.getByRole('cell', { name: 'Max' }).click();
})

await test.step(`In den User-Details PW-Reset Dialog starten`, async () => {
await expect(UserManagementDetail.text_h2).toBeVisible();
await UserManagementDetail.button_pwChange.click();
await expect(UserManagementDetail.text_pwResetInfo).toBeVisible();
})

await test.step(`In dem overlay den PW-Reset bestätigen, das PW kopieren und Dialog schließen`, async () => {
await UserManagementDetail.button_pwReset.click();
await expect(UserManagementDetail.text_pwResetInfo).toBeVisible();
new_password = await UserManagementDetail.input_pw.inputValue();
await UserManagementDetail.button_close_pwreset.click();
})

await test.step(`Login für Benutzer ${username_lastname} mit dem neuen PW`, async () => {
await Header.button_logout.click();
await Landing.button_Anmelden.click();
await Login.login('pwtest', new_password);
})

await test.step(`Neues PW vergeben`, async () => {
await Login.UpdatePW();
await expect(Startseite.text_h2_Ueberschrift).toBeVisible();
})
})
})

0 comments on commit 774efd0

Please sign in to comment.