|
| 1 | +import { Page, Locator, expect } from "@playwright/test"; |
| 2 | +import settings from "../tests/config/settings.json"; |
| 3 | +import { faker } from "@faker-js/faker/locale/en"; |
| 4 | + |
| 5 | +export class RegistrationPage { |
| 6 | + readonly page: Page; |
| 7 | + readonly firstNameInput: Locator; |
| 8 | + readonly lastNameInput: Locator; |
| 9 | + readonly dobInput: Locator; |
| 10 | + readonly streetInput: Locator; |
| 11 | + readonly postalCodeInput: Locator; |
| 12 | + readonly cityInput: Locator; |
| 13 | + readonly stateInput: Locator; |
| 14 | + readonly phoneInput: Locator; |
| 15 | + readonly emailInput: Locator; |
| 16 | + readonly passwordInput: Locator; |
| 17 | + readonly countryDropdown: Locator; |
| 18 | + readonly registerButton: Locator; |
| 19 | + readonly loginHeader: Locator; |
| 20 | + |
| 21 | + constructor(page: Page) { |
| 22 | + this.page = page; |
| 23 | + this.firstNameInput = page.locator("#first_name"); |
| 24 | + this.lastNameInput = page.locator("#last_name"); |
| 25 | + this.dobInput = page.locator("#dob"); |
| 26 | + this.streetInput = page.locator("#street"); |
| 27 | + this.postalCodeInput = page.locator("#postal_code"); |
| 28 | + this.cityInput = page.locator("#city"); |
| 29 | + this.stateInput = page.locator("#state"); |
| 30 | + this.phoneInput = page.locator("#phone"); |
| 31 | + this.emailInput = page.locator("#email"); |
| 32 | + this.passwordInput = page.locator("#password"); |
| 33 | + this.countryDropdown = page.locator("select#country"); |
| 34 | + this.registerButton = page.locator("//button[@type='submit']"); |
| 35 | + this.loginHeader = page.locator("//h3[text()='Login']"); |
| 36 | + } |
| 37 | + |
| 38 | + async navigateToRegistration() { |
| 39 | + await this.page.goto(settings.REGISTRATION_URL); |
| 40 | + } |
| 41 | + |
| 42 | + async fillRegistrationForm() { |
| 43 | + await this.firstNameInput.fill(faker.person.firstName()); |
| 44 | + await this.lastNameInput.fill(faker.person.lastName()); |
| 45 | + await this.dobInput.fill("1990-01-01"); |
| 46 | + await this.streetInput.fill(faker.location.streetAddress()); |
| 47 | + await this.postalCodeInput.fill(faker.location.zipCode()); |
| 48 | + await this.cityInput.fill(faker.location.city()); |
| 49 | + await this.stateInput.fill(faker.location.state()); |
| 50 | + await this.countryDropdown.selectOption({ label: "Canada" }); |
| 51 | + const phoneNumber = faker.string.numeric(10); |
| 52 | + await this.phoneInput.fill(phoneNumber); |
| 53 | + await this.emailInput.fill(faker.internet.email()); |
| 54 | + await this.passwordInput.fill(settings.PASSWORD); |
| 55 | + } |
| 56 | + |
| 57 | + async clickRegisterButton() { |
| 58 | + await this.registerButton.click(); |
| 59 | + } |
| 60 | + |
| 61 | + async verifyRedirectionToLogin() { |
| 62 | + await this.loginHeader.waitFor({ state: "visible", timeout: 2000 }); |
| 63 | + expect(this.page.url()).toBe(settings.LOGIN_URL); |
| 64 | + expect(await this.loginHeader.textContent()).toBe("Login"); |
| 65 | + } |
| 66 | +} |
0 commit comments