-
Notifications
You must be signed in to change notification settings - Fork 24
Add new test for open a page and screenshot function #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
f9f5015
1a5df60
c660fe1
f2d7d8b
6210bc8
ecb41ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
import { | ||
ApplicationTexts, | ||
invalidPassword, | ||
password, | ||
userFullName, | ||
} from "../fixtures/fixtures.js"; | ||
|
||
import { LoginPage } from "./pages/login.page.js"; | ||
import { RegistrationPage } from "./pages/registration.page.js"; | ||
|
||
test.describe("Registration Page is Correctly Displayed", async () => { | ||
test.beforeEach(async ({ page }) => { | ||
const loginPage = new LoginPage(page); | ||
await loginPage.open(); | ||
await loginPage.registrationButton.click(); | ||
await test | ||
.expect(page) | ||
.toHaveTitle(ApplicationTexts.registrationPage.title); | ||
}); | ||
|
||
test("verify registration form is displayed correctly ", async ({ page }) => { | ||
const registrationPage = new RegistrationPage(page); | ||
|
||
await expect( | ||
registrationPage.fullNameInput, | ||
"name input field should be visible" | ||
).toBeVisible(); | ||
await expect( | ||
registrationPage.fullNameInput, | ||
"name input field should be enabled" | ||
).toBeEnabled(); | ||
|
||
await expect( | ||
registrationPage.emailInput, | ||
"email input field should be visible" | ||
).toBeVisible(); | ||
await expect( | ||
registrationPage.emailInput, | ||
"email input field should be enabled" | ||
).toBeEnabled(); | ||
|
||
await expect( | ||
registrationPage.passwordInput, | ||
"password input field should be visible" | ||
).toBeVisible(); | ||
await expect( | ||
registrationPage.passwordInput, | ||
"password input field should be enabled" | ||
).toBeEnabled(); | ||
|
||
await expect( | ||
registrationPage.confirmPasswordInput, | ||
"confirm password input field should be visible" | ||
).toBeVisible(); | ||
await expect( | ||
registrationPage.confirmPasswordInput, | ||
"confirm password input field should be enabled" | ||
).toBeEnabled(); | ||
|
||
await expect( | ||
registrationPage.registrationButton, | ||
"registration button should be visible" | ||
).toBeVisible(); | ||
await expect( | ||
registrationPage.registrationButton, | ||
"login button text should have text" | ||
).toHaveText(ApplicationTexts.registrationPage.registrationButtonLabel); | ||
}); | ||
|
||
test("verify registration form using screenshot", async ({ page }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
await page.screenshot({ path: "registrationForm.png" }); | ||
}); | ||
}); | ||
|
||
//Temporarily force a single worker // | ||
test.describe("User Registration - Valid and Invalid Credentials", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pro účely testu |
||
console.log("Generated Email in beforeAll:", testEmail); | ||
}); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
const registrationPage = new RegistrationPage(page); | ||
await registrationPage.open(); | ||
await test | ||
.expect(page) | ||
.toHaveTitle(ApplicationTexts.registrationPage.title); | ||
}); | ||
|
||
test("should register with valid credentials", async ({ page }) => { | ||
const registrationPage = new RegistrationPage(page); | ||
await registrationPage.register(userFullName, testEmail, password); | ||
|
||
await expect(registrationPage.usernameDropdown).toHaveText(userFullName); | ||
}); | ||
|
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"Některé pole obsahuje špatně zadanou hodnotu" | ||
); | ||
await expect(registrationPage.fieldError).toHaveText( | ||
"Účet s tímto emailem již existuje" | ||
); | ||
}); | ||
|
||
test("should not register with invalid password - only digits", async ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formátování:
|
||
page, | ||
}) => { | ||
const testEmail2 = `testuserCzechitas+${Date.now()}@gmail.com`; | ||
const registrationPage = new RegistrationPage(page); | ||
await registrationPage.register(userFullName, testEmail2, invalidPassword); | ||
await expect(registrationPage.toast).toHaveText( | ||
"Některé pole obsahuje špatně zadanou hodnotu" | ||
); | ||
await expect(registrationPage.fieldError).toHaveText( | ||
"Heslo musí obsahovat minimálně 6 znaků, velké i malé písmeno a číslici" | ||
); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export class AppPage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stejně jako |
||
constructor(page, url) { | ||
this.url = url; | ||
this.page = page; | ||
this.toast = this.page.locator(".toast-message"); | ||
this.navbarRight = this.page.locator(".navbar-right"); | ||
this.usernameDropdown = this.navbarRight.locator( | ||
"[data-toggle='dropdown']" | ||
); | ||
this.logoutLink = this.page.locator("#logout-link"); | ||
this.fieldError = this.page.locator(".invalid-feedback"); | ||
} | ||
|
||
async open() { | ||
await this.page.goto("/" + this.url); | ||
} | ||
|
||
async getToastMessage() { | ||
return await this.toast.textContent(); | ||
} | ||
|
||
async logout() { | ||
await this.usernameDropdown.click(); | ||
await this.logoutLink.click(); | ||
} | ||
|
||
async getCurrentUser() { | ||
return await this.usernameDropdown.textContent(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//Page object describing the login page// | ||
|
||
const { AppPage } = require("./app.page"); | ||
|
||
export class LoginPage extends AppPage { | ||
constructor(page) { | ||
super(page, "prihlaseni"); | ||
this.emailField = this.page.getByLabel("Email"); | ||
this.passwordField = this.page.getByLabel("Heslo"); | ||
this.loginButton = this.page.getByRole("button", { name: "Přihlásit" }); | ||
this.registrationButton = this.page.getByRole("link", { | ||
name: "Zaregistrujte se", | ||
}); | ||
} | ||
|
||
async login(username, password) { | ||
await this.emailField.fill(username); | ||
await this.passwordField.fill(password); | ||
await this.loginButton.click(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//Page object describing the registration page// | ||
|
||
import { AppPage } from "./app.page"; | ||
|
||
export class RegistrationPage extends AppPage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jak jsem zmínila: |
||
constructor(page) { | ||
super(page, "registrace"); | ||
this.fullNameInput = this.page.getByLabel("Jméno a příjmení"); | ||
this.emailInput = this.page.getByLabel("Email"); | ||
this.passwordInput = this.page.getByLabel("Heslo"); | ||
this.confirmPasswordInput = this.page.getByLabel("Kontrola hesla"); | ||
this.registrationButton = this.page.getByRole("button", { | ||
name: "Zaregistrovat", | ||
}); | ||
} | ||
|
||
async register(userFullName, username, password) { | ||
await this.fullNameInput.fill(userFullName); | ||
await this.emailInput.fill(username); | ||
await this.passwordInput.fill(password); | ||
await this.confirmPasswordInput.fill(password); | ||
await this.registrationButton.click(); | ||
} | ||
} |
There was a problem hiding this comment.
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()