|
| 1 | +import settings from "../config/settings.json"; // adjust path if needed |
| 2 | +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 | + |
| 6 | +Given("the user is on the registration page", async function () { |
| 7 | + await this.page.goto(settings.REGISTRATION_URL); |
| 8 | +}); |
| 9 | + |
| 10 | +When( |
| 11 | + "the user fills the registration form with valid details", |
| 12 | + 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"); |
| 24 | + |
| 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); |
| 38 | + } |
| 39 | +); |
| 40 | + |
| 41 | +When("clicks the register button", async function () { |
| 42 | + await this.page.locator("//button[@type='submit']").click(); |
| 43 | +}); |
| 44 | + |
| 45 | +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 | +}); |
0 commit comments