Skip to content

Commit 8faafba

Browse files
committed
add base page locators and methods
1 parent dada7a2 commit 8faafba

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

fixtures/pageFixtures.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { test as base, Page } from "@playwright/test";
2+
import { BasePage } from "../pages/BasePage";
23
import { LoginPage } from "../pages/LoginPage";
34
import { RegistrationPage } from "../pages/RegistrationPage";
45

56
type MyFixtures = {
7+
basePage: BasePage;
68
loginPage: LoginPage;
79
registrationPage: RegistrationPage;
810
//add more types here
911
};
1012

1113
export const test = base.extend<MyFixtures>({
14+
basePage: async ({ page }, use) => {
15+
await use(new BasePage(page));
16+
},
1217
loginPage: async ({ page }, use) => {
1318
await use(new LoginPage(page));
1419
},

pages/BasePage.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
//TODO
1+
import { Page, Locator, expect } from "@playwright/test";
2+
import settings from "../tests/config/settings.json";
3+
4+
export class BasePage{
5+
readonly page:Page;
6+
readonly homeLink:Locator;
7+
readonly loginLink:Locator;
8+
readonly contactLink:Locator;
9+
readonly categoriesLink:Locator;
10+
readonly categoriesDropdown:Locator;
11+
12+
constructor(page:Page) {
13+
this.page = page;
14+
this.homeLink = page.locator("//a[@data-test='nav-home']");
15+
this.loginLink = page.locator("//a[@data-test='nav-sign-in']");
16+
this.contactLink = page.locator("//a[@data-test='nav-contact']");
17+
this.categoriesLink = page.locator("//a[@data-test='nav-categories']");
18+
this.categoriesDropdown = page.locator("//ul[@aria-label='nav-categories']//a");
19+
20+
}
21+
22+
async navigateToHome(){
23+
await this.page.goto(settings.HOME_URL);
24+
}
25+
26+
async navigateToLogin(){
27+
await this.loginLink.click();
28+
}
29+
30+
async navigateToContact(){
31+
await this.contactLink.click();
32+
}
33+
34+
async navigateToCategory(categoryName:string){
35+
await this.categoriesLink.click();
36+
const categoryOption = this.page.locator(`//ul[@aria-label='nav-categories']//a[text()='${categoryName}']`);
37+
await categoryOption.click();
38+
}
39+
}

tests/features/add-to-cart.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Feature: Add items to shopping cart
2+
3+
As a user
4+
I want to add products to my shopping cart
5+
So that I can purchase them later
6+
7+
Background:
8+
Given the user is on the homepage
9+
10+
Scenario: Add single product to the cart
11+
When the user selects a product "Thor Hammer"
12+
And the user clicks the "Add to Cart" button
13+
Then the shopping cart should contain 1 item
14+
And the cart total should update accordingly
15+
16+
# Scenario: Add multiple products to the cart
17+
# When the user selects a product "Laptop"
18+
# And the user clicks the "Add to Cart" button
19+
# And the user selects another product "Headphones"
20+
# And the user clicks the "Add to Cart" button
21+
# Then the shopping cart should contain 2 items
22+
# And the cart total should reflect both products
23+
24+
# Scenario: Add a product with quantity more than 1
25+
# When the user selects a product "Smartphone"
26+
# And the user sets quantity to 3
27+
# And the user clicks the "Add to Cart" button
28+
# Then the shopping cart should contain 3 units of "Smartphone"
29+
# And the cart total should update accordingly

0 commit comments

Comments
 (0)