|
1 | | -import settings from "../config/settings.json"; // adjust path if needed |
2 | 1 | import { Given, When, Then } from "@cucumber/cucumber"; |
3 | | -import { expect } from "@playwright/test"; |
4 | | -import { faker } from "@faker-js/faker/locale/en"; // Import faker with a specific locale |
5 | 2 |
|
6 | 3 | Given("the user is on the registration page", async function () { |
7 | | - await this.page.goto(settings.REGISTRATION_URL); |
| 4 | + // await this.page.goto(settings.REGISTRATION_URL); |
| 5 | + await this.registrationPage.navigateToRegistration(); |
8 | 6 | }); |
9 | 7 |
|
10 | 8 | When( |
11 | 9 | "the user fills the registration form with valid details", |
12 | 10 | async function () { |
13 | | - let firstName = this.page.locator("#first_name"); |
14 | | - let lastName = this.page.locator("#last_name"); |
15 | | - let dob = this.page.locator("#dob"); |
16 | | - let street = this.page.locator("#street"); |
17 | | - let postalCode = this.page.locator("#postal_code"); |
18 | | - let city = this.page.locator("#city"); |
19 | | - let state = this.page.locator("#state"); |
20 | | - let phone = this.page.locator("#phone"); |
21 | | - let email = this.page.locator("#email"); |
22 | | - let password = this.page.locator("#password"); |
23 | | - let countryDropdown = this.page.locator("select#country"); |
| 11 | + // let firstName = this.page.locator("#first_name"); |
| 12 | + // let lastName = this.page.locator("#last_name"); |
| 13 | + // let dob = this.page.locator("#dob"); |
| 14 | + // let street = this.page.locator("#street"); |
| 15 | + // let postalCode = this.page.locator("#postal_code"); |
| 16 | + // let city = this.page.locator("#city"); |
| 17 | + // let state = this.page.locator("#state"); |
| 18 | + // let phone = this.page.locator("#phone"); |
| 19 | + // let email = this.page.locator("#email"); |
| 20 | + // let password = this.page.locator("#password"); |
| 21 | + // let countryDropdown = this.page.locator("select#country"); |
24 | 22 |
|
25 | | - //fill in form details |
26 | | - await firstName.fill(faker.person.firstName()); |
27 | | - await lastName.fill(faker.person.lastName()); |
28 | | - await dob.fill("1990-01-01"); |
29 | | - await street.fill(faker.location.streetAddress()); |
30 | | - await postalCode.fill(faker.location.zipCode()); |
31 | | - await city.fill(faker.location.city()); |
32 | | - await state.fill(faker.location.state()); |
33 | | - await countryDropdown.selectOption({ label: "Canada" }); |
34 | | - const phoneNumber = faker.string.numeric(10); // generates a string exactly 10 digits long |
35 | | - await phone.fill(phoneNumber); |
36 | | - await email.fill(faker.internet.email()); |
37 | | - await password.fill(settings.PASSWORD); |
| 23 | + // //fill in form details |
| 24 | + // await firstName.fill(faker.person.firstName()); |
| 25 | + // await lastName.fill(faker.person.lastName()); |
| 26 | + // await dob.fill("1990-01-01"); |
| 27 | + // await street.fill(faker.location.streetAddress()); |
| 28 | + // await postalCode.fill(faker.location.zipCode()); |
| 29 | + // await city.fill(faker.location.city()); |
| 30 | + // await state.fill(faker.location.state()); |
| 31 | + // await countryDropdown.selectOption({ label: "Canada" }); |
| 32 | + // const phoneNumber = faker.string.numeric(10); // generates a string exactly 10 digits long |
| 33 | + // await phone.fill(phoneNumber); |
| 34 | + // await email.fill(faker.internet.email()); |
| 35 | + // await password.fill(settings.PASSWORD); |
| 36 | + |
| 37 | + await this.registrationPage.fillRegistrationForm(); |
38 | 38 | } |
39 | 39 | ); |
40 | 40 |
|
41 | 41 | When("clicks the register button", async function () { |
42 | | - await this.page.locator("//button[@type='submit']").click(); |
| 42 | + //await this.page.locator("//button[@type='submit']").click(); |
| 43 | + await this.registrationPage.clickRegisterButton(); |
| 44 | + |
43 | 45 | }); |
44 | 46 |
|
45 | 47 | Then("the user should be redirected to the login page", async function () { |
46 | | - expect(this.page.url()).toBe(settings.LOGIN_URL); |
47 | | - expect(await this.page.locator("h3").textContent()).toBe("Login"); |
| 48 | + // await this.page.locator("//h3[text()='Login']").waitFor({ state: "visible", timeout: 2000 }); // wait for redirection |
| 49 | + // expect(this.page.url()).toBe(settings.LOGIN_URL); |
| 50 | + // expect(await this.page.locator("h3").textContent()).toBe("Login"); |
| 51 | + await this.registrationPage.verifyRedirectionToLogin(); |
48 | 52 | }); |
0 commit comments