Skip to content

Commit

Permalink
.env file configured
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmadp committed Oct 11, 2023
1 parent a5d86fc commit b966396
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 73 deletions.
8 changes: 7 additions & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
FOO="bar100"
FOO="bar100"
UMGEBUNG="dev"
PW=""
USER=""
URL_PORTAL="https://portal.qs.schule-sh.de/univention/portal/#/"
URL_COOKIE_PORTAL="https://portal.qs.schule-sh.de"
URL_COOKIE_UCS="https://ucs-sso.qs.schule-sh.de"
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Playwright Tests
on:
workflow_dispatch:
push:
branches: [ main, master ]
branches: [ main, master, dev ]
#pull_request:
#branches: [ main, master ]
jobs:
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# toDo
# Schulportal Playwright, Doku für lokale Ausführung von den Tests

## Zu installierende Node.js-Pakete
npm install dotenv
npm install otpauth
npm install jimp
npm install qrcode-reader

## Oft verwendetet Konsolenbefehle

# Einen bestimmten Test ausführen:
npx playwright test TF0001.spec.ts

# Umgebungsvariablen überschreiben
gitbash: TIMEOUT="" npx playwright test TF0001.spec.ts --headed

powershell:
$env:TIMEOUT=""
npx playwright test TF0001.spec.ts --headed

# Einen Report von der Testausführung öffnen:
npx playwright show-report results\results-2023-10-06T13_49_14_593

# Code-Generator starten:
npx playwright codegen https://portal.qs.schule-sh.de/univention/portal/#/

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

powershell:
PWDEBUG=1
npx playwright test TF0001.spec.ts --headed
35 changes: 5 additions & 30 deletions pages/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,21 @@ const { expect } = require("@playwright/test");

exports.LoginPage = class LoginPage{

constructor(page, Direkteinstieg){
constructor(page){
this.page = page;
this.Direkteinstieg = Direkteinstieg; //Einstieg über das Portal, bei true ist der Einstieg direkt über die Loginseite(ohne tabs bzw. framelocator)

this.url = 'https://portal.qs.schule-sh.de/univention/portal'; //depricated
if(this.Direkteinstieg == true) {
this.button_cookieOK = page.getByRole('button', { name: 'Akzeptieren' });
this.button_openLoginPage = page.getByRole('link', { name: 'Anmelden Gleicher Tab' });
this.input_username = page.locator("[id='umcLoginUsername']");
this.input_password = page.locator("#umcLoginPassword");
this.button_login = page.getByRole('button', { name: 'Anmelden' });
this.text_PasswortAbgelaufen = page.getByText('Das Passwort ist abgelaufen und muss erneuert werden.');
this.input_neuesPasswort = page.getByLabel('Neues Passwort', { exact: true });
this.input_neuesPasswortWiederholen = page.getByLabel('Neues Passwort (wiederholen)');
this.button_passwortAendern = page.getByRole('button', { name: 'Passwort setzen' });
}
else{
this.button_cookieOK = page.getByRole('button', { name: 'Akzeptieren' });
this.button_openLoginPage = page.getByRole('link', { name: 'Anmelden Gleicher Tab' });
this.input_username = page.locator("[id='umcLoginUsername']");
this.input_password = page.locator("#umcLoginPassword");
this.button_login = page.getByRole('button', { name: 'Anmelden' });
this.text_PasswortAbgelaufen = page.getByText('Das Passwort ist abgelaufen und muss erneuert werden.');
this.input_neuesPasswort = page.getByLabel('Neues Passwort', { exact: true });
this.input_neuesPasswortWiederholen = page.getByLabel('Neues Passwort (wiederholen)');
this.button_passwortAendern = page.getByRole('button', { name: 'Passwort ändern' });
}
this.button_openLoginPage = page.getByRole('link', { name: 'Anmelden Gleicher Tab' });
this.input_username = page.locator("[id='umcLoginUsername']");
this.input_password = page.locator("#umcLoginPassword");
this.button_login = page.getByRole('button', { name: 'Anmelden' });
}

async login(username, password, url){
await this.page.goto(url);
await this.button_cookieOK.click();
await this.button_openLoginPage.click();
//await this.button_cookieOK.click();
await this.input_username.click();
await this.input_username.fill(username);
await this.input_password.click();
await this.input_password.fill(password);
await this.button_login.click();
}


}
29 changes: 5 additions & 24 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
import { defineConfig, devices } from '@playwright/test';
require("dotenv").config({ path: "./.env.local" });

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Maximum time one test can run for. */
//timeout: 30 * 1000,
timeout: 30 * 1000,
//timeout: 300 * 1000,
retries: 0,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 10000
},
expect: { timeout: 10000 },
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
Expand Down Expand Up @@ -58,10 +41,10 @@ export default defineConfig({
use: { ...devices['Desktop Chrome']},
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
/*
{
name: 'webkit',
Expand Down Expand Up @@ -100,5 +83,3 @@ export default defineConfig({


});

console.log(process.env.FOO); // prints "bar"
25 changes: 14 additions & 11 deletions tests/TF_001_Login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/login';

test.describe('Erfolgreicher Standard Login', () => {
test('Login Test', async ({ context, page }) => {
const server = 'portal';
const url = 'https://' + server + '.qs.schule-sh.de/univention/login/#/';
const PW = process.env.PW;
const USER = process.env.USER;
const URL_PORTAL = process.env.URL_PORTAL;
const URL_COOKIE_PORTAL = process.env.URL_COOKIE_PORTAL;
const URL_COOKIE_UCS = process.env.URL_COOKIE_UCS;

test.describe(`Start Test in der Umgebung: ${process.env.UMGEBUNG} und Server: ${process.env.URL_PORTAL}`, () => {
test('Erfolgreicher Standard Login', async ({ context, page }) => {
const Login = new LoginPage(page);

await test.step('Hier passiert nichts', async () => {
await test.step("Vorab die Browser-Cookies setzen (Simulation, dass der Benutzer in der Vergangen schon mal auf der Seite war)", async () => {
context.addCookies([{name:"schuposh-consent", value: "do-not-change-me", url: URL_COOKIE_PORTAL}]);
context.addCookies([{name:"schuposh-consent", value: "do-not-change-me", url: URL_COOKIE_UCS}]);
})

await test.step('Negativer login', async () => {
await Login.login('xxxxxxxx', 'xxxxxxx', url);
await Login.login('xxxxxxxx', 'yyyyyyyy', URL_PORTAL);
})
// await page.pause();
})
})



//await page.pause();
})
5 changes: 0 additions & 5 deletions tests/test1.spec.ts

This file was deleted.

0 comments on commit b966396

Please sign in to comment.