Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 1x 1x 1x 13x 13x 13x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // @ts-check
const { expect } = require('@playwright/test');
const { BasePage } = require('./BasePage');
const { HeaderComponent } = require('./components/HeaderComponent');
const { environment } = require('../config/environment');
/**
* SignupLoginPage POM handles user authentication and registration flows.
*/
class SignupLoginPage extends BasePage {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
super(page);
this.header = new HeaderComponent(page);
// Login Form Locators
this.loginHeading = page.locator('.login-form h2');
this.loginEmailInput = page.locator('input[data-qa="login-email"]');
this.loginPasswordInput = page.locator('input[data-qa="login-password"]');
this.loginButton = page.locator('button[data-qa="login-button"]');
this.loginErrorMessage = page.locator('.login-form p[style*="color: red"]');
// Signup Form Locators
this.signupHeading = page.locator('.signup-form h2');
this.signupNameInput = page.locator('input[data-qa="signup-name"]');
this.signupEmailInput = page.locator('input[data-qa="signup-email"]');
this.signupButton = page.locator('button[data-qa="signup-button"]');
this.signupErrorMessage = page.locator('.signup-form p[style*="color: red"]');
// Account Information Form Locators
this.accountInfoHeading = page.locator('.login-form h2:has-text("Enter Account Information")');
this.genderMrRadio = page.locator('#id_gender1');
this.genderMrsRadio = page.locator('#id_gender2');
this.passwordInput = page.locator('input[data-qa="password"]');
this.daysSelect = page.locator('select[data-qa="days"]');
this.monthsSelect = page.locator('select[data-qa="months"]');
this.yearsSelect = page.locator('select[data-qa="years"]');
this.newsletterCheckbox = page.locator('#newsletter');
this.optinCheckbox = page.locator('#optin');
// Address Details Locators
this.firstNameInput = page.locator('input[data-qa="first_name"]');
this.lastNameInput = page.locator('input[data-qa="last_name"]');
this.companyInput = page.locator('input[data-qa="company"]');
this.address1Input = page.locator('input[data-qa="address"]');
this.address2Input = page.locator('input[data-qa="address2"]');
this.countrySelect = page.locator('select[data-qa="country"]');
this.stateInput = page.locator('input[data-qa="state"]');
this.cityInput = page.locator('input[data-qa="city"]');
this.zipcodeInput = page.locator('input[data-qa="zipcode"]');
this.mobileNumberInput = page.locator('input[data-qa="mobile_number"]');
this.createAccountButton = page.locator('button[data-qa="create-account"]');
// Status Confirmation Locators
this.accountCreatedHeading = page.locator('[data-qa="account-created"]');
this.accountDeletedHeading = page.locator('[data-qa="account-deleted"]');
this.continueButton = page.locator('[data-qa="continue-button"]');
this.loggedInText = page.locator('.shop-menu').getByText('Logged in as', { exact: false });
this.deleteAccountLink = page.locator('.shop-menu a[href="/delete_account"]');
this.logoutLink = page.locator('.shop-menu a[href="/logout"]');
}
/**
* Navigates directly to /login
*/
async navigate() {
await this.goto(environment.routes.login);
await this.verifyLoaded();
}
/**
* Verifies the login page loaded with headings.
*/
async verifyLoaded() {
await expect(this.page).toHaveURL(new RegExp(`${environment.routes.login}$`));
await expect(this.loginHeading).toBeVisible();
await expect(this.loginHeading).toHaveText('Login to your account');
await expect(this.signupHeading).toBeVisible();
await expect(this.signupHeading).toHaveText('New User Signup!');
}
/**
* Performs login with email and password.
* @param {string} email
* @param {string} password
*/
async login(email, password) {
await this.loginEmailInput.fill(email);
await this.loginPasswordInput.fill(password);
await this.loginButton.click();
}
/**
* Starts signup with name and email.
* @param {string} name
* @param {string} email
*/
async initiateSignup(name, email) {
await expect(this.signupHeading).toBeVisible();
await this.signupNameInput.fill(name);
await this.signupEmailInput.fill(email);
await this.signupButton.click();
}
/**
* Fills account information section.
* @param {any} user
*/
async fillAccountInformation(user) {
await expect(this.accountInfoHeading).toBeVisible();
if (user.title === 'Mrs') {
await this.genderMrsRadio.check();
} else {
await this.genderMrRadio.check();
}
await this.passwordInput.fill(user.password);
if (user.birthDay) await this.daysSelect.selectOption(user.birthDay);
if (user.birthMonth) await this.monthsSelect.selectOption(user.birthMonth);
if (user.birthYear) await this.yearsSelect.selectOption(user.birthYear);
await this.newsletterCheckbox.check();
await this.optinCheckbox.check();
}
/**
* Fills address information section.
* @param {any} user
*/
async fillAddressDetails(user) {
await this.firstNameInput.fill(user.firstName);
await this.lastNameInput.fill(user.lastName);
await this.companyInput.fill(user.company);
await this.address1Input.fill(user.address1);
if (user.address2) await this.address2Input.fill(user.address2);
if (user.country) await this.countrySelect.selectOption(user.country);
await this.stateInput.fill(user.state);
await this.cityInput.fill(user.city);
await this.zipcodeInput.fill(user.zipcode);
await this.mobileNumberInput.fill(user.mobile);
}
/**
* Clicks 'Create Account' button.
*/
async clickCreateAccount() {
await this.createAccountButton.scrollIntoViewIfNeeded();
await this.createAccountButton.click();
}
/**
* Asserts 'ACCOUNT CREATED!' is visible.
*/
async verifyAccountCreated() {
await expect(this.accountCreatedHeading).toBeVisible();
}
/**
* Clicks 'Continue' button after account creation or deletion.
*/
async clickContinue() {
await this.continueButton.click();
}
/**
* Asserts 'Logged in as <username>' is visible in the header.
* @param {string} username
*/
async verifyLoggedInAs(username) {
await expect(this.loggedInText).toBeVisible();
await expect(this.loggedInText).toContainText(username);
}
/**
* Performs full registration workflow.
* @param {any} user
*/
async registerCompleteUser(user) {
await this.initiateSignup(user.name, user.email);
await this.fillAccountInformation(user);
await this.fillAddressDetails(user);
await this.clickCreateAccount();
await this.verifyAccountCreated();
await this.clickContinue();
await this.verifyLoggedInAs(user.name);
}
/**
* Creates an account starting directly from /login.
* @param {any} user
*/
async createAccountDirect(user) {
await this.navigate();
await this.registerCompleteUser(user);
}
/**
* Logs out the current user session.
*/
async logout() {
await this.logoutLink.click();
await expect(this.page).toHaveURL(new RegExp(`${environment.routes.login}$`));
}
/**
* Deletes the active user account and confirms.
*/
async deleteAccount() {
await this.deleteAccountLink.click();
await expect(this.accountDeletedHeading).toBeVisible();
if (await this.continueButton.isVisible()) {
await this.continueButton.click();
}
}
/**
* Asserts invalid login error message.
*/
async verifyLoginError() {
await expect(this.loginErrorMessage).toBeVisible();
await expect(this.loginErrorMessage).toContainText('Your email or password is incorrect!');
}
/**
* Asserts duplicate email signup error message.
*/
async verifySignupError() {
await expect(this.signupErrorMessage).toBeVisible();
await expect(this.signupErrorMessage).toContainText('Email Address already exist!');
}
}
module.exports = { SignupLoginPage };
|