|
| 1 | +import type { Page, Locator } from '@playwright/test'; |
| 2 | + |
| 3 | +export class LoginPage { |
| 4 | + private readonly emailInput: Locator; |
| 5 | + private readonly passwordInput: Locator; |
| 6 | + private readonly confirmPasswordInput: Locator; |
| 7 | + private readonly signInButton: Locator; |
| 8 | + private readonly signUpButton: Locator; |
| 9 | + private readonly signInLink: Locator; |
| 10 | + private readonly signUpLink: Locator; |
| 11 | + |
| 12 | + constructor(public readonly page: Page) { |
| 13 | + this.emailInput = this.page.getByPlaceholder(/^Please enter your email$/); |
| 14 | + this.passwordInput = this.page.getByPlaceholder(/^Please enter your password$/); |
| 15 | + this.confirmPasswordInput = this.page.getByPlaceholder(/^Please Confirm Password$/); |
| 16 | + this.signInButton = this.page.getByRole('button', { name: 'Sign In' }); |
| 17 | + this.signUpButton = this.page.getByRole('button', { name: 'Sign Up' }); |
| 18 | + this.signUpLink = this.page.getByRole('link', { name: 'Sign In' }); |
| 19 | + this.signUpLink = this.page.getByRole('link', { name: 'Sign Up' }); |
| 20 | + } |
| 21 | + |
| 22 | + async loadPage() { |
| 23 | + await this.page.goto('/user/auth/login'); |
| 24 | + } |
| 25 | + |
| 26 | + async fillEmail(text: string) { |
| 27 | + await this.emailInput.click(); |
| 28 | + await this.emailInput.fill(text); |
| 29 | + } |
| 30 | + |
| 31 | + async fillPassword(text: string) { |
| 32 | + await this.passwordInput.click(); |
| 33 | + await this.passwordInput.fill(text); |
| 34 | + } |
| 35 | + |
| 36 | + async fillConfirmPassword(text: string) { |
| 37 | + await this.confirmPasswordInput.click(); |
| 38 | + await this.confirmPasswordInput.fill(text); |
| 39 | + } |
| 40 | + |
| 41 | + async clickSignIn() { |
| 42 | + await this.signInButton.click(); |
| 43 | + } |
| 44 | + |
| 45 | + async clickSignUp() { |
| 46 | + await this.signUpButton.click(); |
| 47 | + } |
| 48 | + |
| 49 | + async clickSignUpLink() { |
| 50 | + await this.signUpLink.click(); |
| 51 | + } |
| 52 | + |
| 53 | + async signUp(username: string, password: string, repeatPassword: string) { |
| 54 | + if (await this.signUpLink.isVisible()) { |
| 55 | + await this.clickSignUpLink(); |
| 56 | + } |
| 57 | + |
| 58 | + await this.fillEmail(username); |
| 59 | + |
| 60 | + /* disabled because the placeholder is different between sign in and sign up */ |
| 61 | + //await this.fillPassword(password); |
| 62 | + await this.page.getByPlaceholder(/^Please Enter Password$/).click(); |
| 63 | + await this.page.getByPlaceholder(/^Please Enter Password$/).fill(password); |
| 64 | + |
| 65 | + await this.fillConfirmPassword(repeatPassword); |
| 66 | + await this.clickSignUp(); |
| 67 | + } |
| 68 | + |
| 69 | + async logIn(username: string, password: string) { |
| 70 | + await this.loadPage(); |
| 71 | + await this.fillEmail(username); |
| 72 | + await this.fillPassword(password); |
| 73 | + await this.clickSignIn(); |
| 74 | + } |
| 75 | + |
| 76 | + async logOut(username: string) { |
| 77 | + await this.page.getByTitle(username, { exact: true }).click(); |
| 78 | + await this.page.getByText('Log Out').click({delay: 1000}); |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments