Skip to content

Instantly share code, notes, and snippets.

@nadvolod
Created January 13, 2023 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadvolod/11cf28a741c58f211edde74065bf483b to your computer and use it in GitHub Desktop.
Save nadvolod/11cf28a741c58f211edde74065bf483b to your computer and use it in GitHub Desktop.
import { expect, Locator, Page } from '@playwright/test';
const userNameFieldLoc = '[id="user-name"]'
const passwordFieldLoc = '[id="password"]'
const loginButtonLoc = '[id="login-button"]'
const errorloc = '[data-test="error"]'
const headerLoc = '[class="title"]'
const burgerMenue = '[id="react-burger-menu-btn"]'
const aboutButtonLoc = '[id="about_sidebar_link"]'
export default class LoginPage{
constructor(public page: Page){
}
async goToBaseURL(){
await this.page.goto('/')
}
async userNameFill(value: string){
await this.page.locator(userNameFieldLoc).fill(value);
}
async userPasswordFill(value: string){
await this.page.locator(passwordFieldLoc).fill(value);
}
async loginButtonClick(){
await this.page.locator(loginButtonLoc).click();
}
async expectErrorToHaveText(text: string){
await expect(this.page.locator(errorloc)).toHaveText(text);
}
async expectHeaderToHaveText(text: string){
await expect(this.page.locator(headerLoc)).toHaveText(text);
}
async burgerMenuClick() {
await this.page.locator(burgerMenue).click()
}
async aboutButtClick(){
await this.page.locator(aboutButtonLoc).click()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment