This commit is contained in:
Lukáš Kaňka
2023-08-15 18:27:27 +02:00
commit a117466599
116 changed files with 6597 additions and 0 deletions

View File

@ -0,0 +1,45 @@
// import třída modulů které budeme potřebovat
import { Locator, Page
} from "@playwright/test";
//definujeme třídy (class)
export class HomePage{
page: Page;
menu: Locator;
title: Locator;
item: Locator;
addToCart: Locator;
cardBadge: Locator;
// vytvoříme konstruktor třídy definuje proměnou page
constructor(page: Page) {
this.page = page;
this.menu = page.locator('#react-burger-menu-btn');
this.title = page.getByText('Swag Labs');
this.item = page.locator('#item_4_title_link');
this.addToCart = page.locator('#add-to-cart-sauce-labs-backpack');
this.cardBadge = page.locator('//span[@class="shopping_cart_badge"]');
}
// teď si definujeme metody na práci s elementy výše
async clickOnMenu() {
await this.menu.click();
}
async clickOnItem() {
await this.item.click();
}
async clickOnAddToCart() {
await this.addToCart.click();
}
async clickOnCardBAdge() {
await this.cardBadge.click();
}
}

View File

@ -0,0 +1,71 @@
// import třída modulů které budeme potřebovat
import { Locator, Page
} from "@playwright/test";
//definujeme třídy (class)
export class LoginPage{
page: Page;
userNameInput: Locator;
passwordInput: Locator;
loginButton: Locator;
invalidCredentialsErrorMessage: Locator;
requiredCredentialsErrorMassage: Locator;
lockedOutErrorMassage: Locator;
// vytvoříme konstruktor třídy definuje proměnou page
constructor(page: Page) {
this.page = page;
this.userNameInput = page.locator('#user-name');
this.passwordInput = page.locator('#password');
this.loginButton = page.locator('#login-button');
this.invalidCredentialsErrorMessage = page.getByText('Epic sadface: Username and password do not match any user in this service');
this.requiredCredentialsErrorMassage = page.getByText('Epic sadface: Username is required');
this.lockedOutErrorMassage = page.getByText('')
this.lockedOutErrorMassage = page.getByText('Epic sadface: Sorry, this user has been locked out.');
}
// teď si definujeme metody na práci s elementy výše this.userNameInput = page.locator('#user-name');
// metoda na přejetí na stránku s Loginem
async gotoLoginPage() {
await this.page.goto('https://www.saucedemo.com/');
}
// metoda přihlašovacího jména
// protože chceme vepsat uživatelské jmáno použijeme metodu fill
async enterValidUsername() {
await this.userNameInput.fill('standard_user');
}
async enterLockedOutUser() {
await this.userNameInput.fill('locked_out_user');
}
// alternativy k valid budou invalid
async enterInvalidUsername() {
await this.userNameInput.fill('jmeno');
}
// zde zapíšeme heslo
async enterValidPassword() {
await this.passwordInput.fill('secret_sauce');
}
async enterInvalidPassword() {
await this.passwordInput.fill('heslo');
}
// klik na login button
async clickLoginButton() {
await this.loginButton.click();
}
// valid metody na ´ůspěšné přihlášení zapozdříme tímto způsobem:
async login() {
await this.userNameInput.fill('standard_user');
await this.passwordInput.fill('secret_sauce');
await this.loginButton.click();
}
}