Skip to content

Commit dada7a2

Browse files
committed
update steps with page object model methods
1 parent 3f7f73b commit dada7a2

File tree

3 files changed

+58
-59
lines changed

3 files changed

+58
-59
lines changed

tests/features/login.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@login
12
Feature: User Login
23

34
Scenario: Verify successful login with valid credentials

tests/steps/login.steps.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
1-
import settings from "../config/settings.json";
1+
import settings from "../config/settings.json";
22
import { Given, When, Then } from "@cucumber/cucumber";
3-
import { expect } from "@playwright/test";
43

54
Given("user navigates to the login page", async function () {
6-
await this.page.goto(settings.LOGIN_URL);
5+
await this.loginPage.navigateToLogin();
76
});
87

98
When("user enters valid username and password", async function () {
10-
console.log("Filling in username and password fields");
11-
console.log(`Using email: ${settings.EMAIL}`);
12-
console.log(`Using password: ${settings.PASSWORD}`);
9+
// console.log("Filling in username and password fields");
10+
// console.log(`Using email: ${settings.EMAIL}`);
11+
// console.log(`Using password: ${settings.PASSWORD}`);
1312

14-
// Wait for elements to be ready
15-
await this.page.waitForSelector("#email", { state: "visible" });
16-
await this.page.waitForSelector("#password", { state: "visible" });
13+
// // Wait for elements to be ready
14+
// await this.page.waitForSelector("#email", { state: "visible" });
15+
// await this.page.waitForSelector("#password", { state: "visible" });
1716

18-
await this.page.locator("#email").fill(settings.EMAIL);
19-
await this.page.locator("#password").fill(settings.PASSWORD);
17+
// await this.page.locator("#email").fill(settings.EMAIL);
18+
// await this.page.locator("#password").fill(settings.PASSWORD);
19+
await this.loginPage.enterCredentials(settings.EMAIL, settings.PASSWORD);
2020
});
2121

2222
When("user click the login button", async function () {
23-
// Use the data-test attribute - most reliable
24-
const submitButton = this.page.locator('[data-test="login-submit"]');
23+
// // Use the data-test attribute - most reliable
24+
// const submitButton = this.page.locator('[data-test="login-submit"]');
2525

26-
// Wait for button to be visible and enabled
27-
await submitButton.waitFor({ state: "visible" });
26+
// // Wait for button to be visible and enabled
27+
// await submitButton.waitFor({ state: "visible" });
2828

29-
console.log("Login button found, clicking...");
30-
await submitButton.click();
29+
// console.log("Login button found, clicking...");
30+
// await submitButton.click();
3131

32-
// Wait a moment for the login to process
33-
await this.page.waitForTimeout(3000);
32+
// // Wait a moment for the login to process
33+
// await this.page.waitForTimeout(3000);
3434

35-
console.log("Current URL after login:", this.page.url());
35+
// console.log("Current URL after login:", this.page.url());
36+
await this.loginPage.clickLoginButton();
3637
});
3738

3839
Then("user should see the user dashboard", async function () {
39-
// Wait for dashboard element to be visible
40-
await this.page.waitForSelector("h1", { state: "visible" });
41-
42-
// Get the text content of the dashboard header
43-
const headingText = await this.page.locator("h1").textContent();
44-
45-
// Assert the heading text matches expectation
46-
expect(headingText).toBe("My account");
40+
await this.loginPage.verifyDashboard();
4741
});

tests/steps/registration.steps.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
1-
import settings from "../config/settings.json"; // adjust path if needed
21
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
52

63
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();
86
});
97

108
When(
119
"the user fills the registration form with valid details",
1210
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");
2422

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();
3838
}
3939
);
4040

4141
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+
4345
});
4446

4547
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();
4852
});

0 commit comments

Comments
 (0)