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

Add new test for open a page and screenshot function #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

hanakonecna
Copy link

No description provided.

).toHaveText(ApplicationTexts.registrationPage.registrationButtonLabel);
});

test("verify registration form using screenshot", async ({ page }) => {

Choose a reason for hiding this comment

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

Samostatný screenshot by neměl být test. Můžeš ho ale klidně dát do testu verify registration form is displayed correctly


test.describe("Registration Page is Correctly Displayed", async () => {
test.beforeEach(async ({ page }) => {
const loginPage = new LoginPage(page);

Choose a reason for hiding this comment

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

Pro účely tohoto zadání není potřeba více page object modelů než jeden, a to RegistrationPage. Do něj se dá vložit metoda pro otevření stránky open()

});
});

test.describe("User Registration - Valid and Invalid Credentials", () => {

Choose a reason for hiding this comment

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

Myslím že není potřeba mít dva test.describe(). Jeden test.describe() by stačil.

let testEmail;

test.beforeAll(async () => {
testEmail = `testuserCzechitas+${Date.now()}@gmail.com`;

Choose a reason for hiding this comment

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

testEmail generuje vždy unikátní e-mail, protože Date.now() negeneruje jen datum, ale i čas. To znamená, že test should not register with existing email vždy failne.

Choose a reason for hiding this comment

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

Pro účely testu should not register with existing email by stačil statický, již existující e-mail (třeba da-app.admin@czechitas.cz), generováním dynamického e-mailu se vystavujeme flakiness. V takovém případě by ani nemusel být v test.beforeAll(), ale cením snahu beforeAll() nějak zakomponovat.

test("should not register with existing email", async ({ page }) => {
const registrationPage = new RegistrationPage(page);
await registrationPage.register(userFullName, testEmail, password);
await expect(registrationPage.toast).toHaveText(

Choose a reason for hiding this comment

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

Assert toHaveText() je fajn, ale mnohem důležitější assert je .isVisible() - zajišťuje totiž, že se element skutečně zobrazuje v DOMu a není třeba hidden nebo překrytý jinou komponentu. Bylo by fajn assertnout i text i visibilitu.

);
});

test("should not register with invalid password - only digits", async ({

Choose a reason for hiding this comment

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

formátování:

test("should not register with invalid password - only digits", async ({ page }) => {

@@ -0,0 +1,30 @@
export class AppPage {

Choose a reason for hiding this comment

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

Stejně jako LoginPage, ani AppPage object model tu úplně nemusí být. Vzniká totiž tzv. dead code - nevyužitý kód - funkce getToastMessage(), logout() a getCurrentUser() se nikde v rámci /test/homework.spec.js nepoužívají.


import { AppPage } from "./app.page";

export class RegistrationPage extends AppPage {

Choose a reason for hiding this comment

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

Jak jsem zmínila: RegistrationPage jako page object model dokáže pobrat všechny elementy, lokátory i funkce potřebné k pokrytí stránky registrace. LoginPage a AppPage nejsou potřeba. Struktura s víc page object modely dává smysl u testů, kde testujeme více stránek - tento úkol je ale pouze o testování stránky registrace.

@nikolikrat
Copy link

Code review done.

Merge request bohužel nebudeme moci approvnout, protože je to merge request do našeho czechitas repozitáře, namísto forku na tvém githubu.

Velmi chválím použití fixtures! Do fixtures by se daly přidat jinak i password a username test data. Chválím snahu použít test.describe, test.beforeAll, test.beforeEach, akorát někdy méně je více a v tomto rozsahu nejsou úplně potřeba. Velmi cením použití page object modelu - to bylo v zadání velmi optional, ale stačil by jen jeden page object model a vyšperkovat. Cením také snahu o dynamické testovací data (testEmail), ale zrovna v tomto případě to nemá ten efekt - nicméně určitě budou případy, kde budou dynamické testovací data potřeba! Testy jsou spustitelné (kromě test casu s již existujícím e-mailem), pojmenovávání proměnných dává smysl a je fajn, rozsah test casů je dobrý a splňuje zadání, asserty jsou přítomny ale mohlo by jich být více (hlavně isVisible() je alfa omega). Jsou tu trošku chybky ve formátování, ale s tím dokáže velmi efektivně pomoci eslint nebo jiný helper, ten to pak dělá automaticky. Celkově je to fajn, trošku péče by to ještě potřebovalo, ale určitě se s tím dá pracovat a není to vůbec špatné. Děkuji!

As testEmail must be shared across tests, ensure only one worker runs tests (npx playwright test --workers=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants