Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domaci ukol #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"dotenv": "^16.4.5",
"eslint": "^9.9.1"
},
"scripts": {}
"scripts": {},
"dependencies": {
"uuid": "^11.0.3"
}
}
6 changes: 0 additions & 6 deletions src/tests/example.spec.js

This file was deleted.

116 changes: 116 additions & 0 deletions src/tests/homework.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { test, expect } from '@playwright/test';
const { v4: uuidv4 } = require('uuid');


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tohle jenom organizacni doporuceni. Scenare mohly byt rozdeleny do dvou describe bloku, nebo vsechny v jednom. Tady to zacina be describe bloku a pozdeji mas definovay describe blok, tak mi to prijde mene prehledne.

function getUniqueEmail() {
const guid = uuidv4();
const email = `lenka.nova${guid}@gmail123.com`;
return email
}

test('1 formular registrace', async ({ page }) => {
await test.step('navigace do formulare registrace', async () => {
await page.goto('/prihlaseni');
await page.getByRole('link', { name: 'Zaregistrujte se' }).click();
await page.locator('.col-md-10').click();
await page.locator('form div').filter({ hasText: 'Zaregistrovat' }).nth(1).click();
});

await test.step('kontrola spravneho zobrazeni', async () => {
await test.step('overeni zobrazeni vstupních poli', async () => {
await expect(page.getByLabel('Jméno a příjmení')).toBeVisible()
await expect(page.getByLabel('Email')).toBeVisible()
await expect(page.getByLabel('Heslo')).toBeVisible()
await expect(page.getByLabel('Kontrola hesla')).toBeVisible()
});

await test.step('kontrola zobrazeni oproti screenshotu', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v tomhle kroku k zadne kontrole screenshotu nedocazi, pouze se screenshot vytvari.
lepsi pouzit await expect(page).toHaveScreenshot();
https://playwright.dev/docs/test-snapshots

await page.setViewportSize({ width: 800, height: 600 });
await page.screenshot({ path: "login_page_800_600.png" });

await expect(page).toHaveScreenshot({ path: "login_page_800_600.png" });
});
});
});

test('2 validni registrace uzivatele ', async ({ page }) => {
const email = getUniqueEmail();
const fullname = 'Lenka Nová';
const password = 'Lenka123';

await test.step('registrace uzivatele', async () => {
await page.goto('/registrace');
await page.getByLabel('Jméno a příjmení').fill(fullname);
await page.getByLabel('Email').fill(email);
await page.getByLabel('Heslo').fill(password);
await page.getByLabel('Kontrola hesla').fill(password);
await page.getByRole('button', { name: 'Zaregistrovat' }).click();
});

await test.step('kontrola uspesne registrace', async () => {
await expect(page.locator('#navbarSupportedContent')).toContainText(fullname);
await page.getByText('Přihlášen').click();
await expect(page.getByText('Přihlášen')).toBeVisible();
await expect(page.locator('#navbarSupportedContent .navbar-right div.nav-item')).toContainText('Přihlášen');
await expect(page.locator(`#navbarSupportedContent a[title="${fullname}"]`)).toContainText(fullname);
});
});

test.describe('test registracniho formulare', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/registrace');
const fullname = 'Lenka Nová'

await page.getByLabel('Jméno a příjmení').fill(fullname);
});

test('3 registrace uzivatele s existujicim mailem', async ({ page }) => {

const existingEmail = `[email protected]`;
const password = 'LenkaNova123'

await page.getByLabel('Email').fill(existingEmail);
await page.getByLabel('Heslo').fill(password);
await page.getByLabel('Kontrola hesla').fill(password);
await page.getByRole('button', { name: 'Zaregistrovat' }).click();

await test.step('kongtrola stavu formulare', async () => {
const emailErrorMessage = page.locator('form span.invalid-feedback');
const count = await emailErrorMessage.count();

await expect(count).toBe(1);
await expect(emailErrorMessage).toContainText('Účet s tímto emailem již existuje');
});

await test.step('kontrola ze registrace neprobehla', async () => {
const elementLoggedIn = page.locator('div.nav-item span', { hasText: 'Přihlášen' });
await expect(elementLoggedIn).toHaveCount(0);
});
});


test('4 registrace uzivatele s nevalidnim heslem (obsahujici pouze cisla)', async ({ page }) => {

const email = getUniqueEmail();
const password = '1234567890123';

await page.getByLabel('Email').fill(email);
await page.getByLabel('Heslo').fill(password);
await page.getByLabel('Kontrola hesla').fill(password);
await page.getByRole('button', { name: 'Zaregistrovat' }).click();

await test.step('kongtrola stavu formulare', async () => {
const passwordErrorMessage = page.locator('form span.invalid-feedback');
const count = await passwordErrorMessage.count();

await expect(count).toBe(1);
await expect(passwordErrorMessage).toContainText('Heslo musí obsahovat minimálně 6 znaků, velké i malé písmeno a číslici');
});

await test.step('kontrola ze registrace neprobehla', async () => {
const elementLoggedIn = page.locator('div.nav-item span', { hasText: 'Přihlášen' });
await expect(elementLoggedIn).toHaveCount(0);
});
});
});