WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 0ebec5e

Browse files
authored
Merge pull request #19 from auto-qa-hub/po-add-to-cart-flow
po-for-cart-and-few-po-updates
2 parents 3912871 + 251b7fa commit 0ebec5e

File tree

4 files changed

+156
-23
lines changed

4 files changed

+156
-23
lines changed

page_objects_ts/CartPage.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Locator, Page } from "@playwright/test";
2+
export class CartPage {
3+
readonly page: Page;
4+
readonly cartItems: Locator;
5+
readonly removeButtons: Locator;
6+
readonly checkoutButton: Locator;
7+
readonly continueShoppingButton: Locator;
8+
readonly itemNames: Locator;
9+
readonly itemPrices: Locator;
10+
readonly itemQuantities: Locator;
11+
12+
constructor(page: Page) {
13+
this.page = page;
14+
this.cartItems = page.locator(".cart_item");
15+
this.removeButtons = page.locator(".inventory_item_price");
16+
this.checkoutButton = page.locator("#checkout");
17+
this.continueShoppingButton = page.locator("#continue-shopping");
18+
this.itemNames = page.locator(".inventory_item_name");
19+
this.itemPrices = page.locator(".inventory_item_price");
20+
this.itemQuantities = page.locator(".cart_quantity");
21+
}
22+
23+
async removeItem(index: number) {
24+
await this.removeButtons.nth(index).click();
25+
}
26+
27+
async verifyItemExists(itemName: string) {
28+
await this.page.locator(`text=${itemName}`).waitFor();
29+
}
30+
31+
async clickCheckout() {
32+
await this.checkoutButton.click();
33+
}
34+
35+
async clickContinueShopping() {
36+
await this.continueShoppingButton.click();
37+
}
38+
39+
async getCartItemsCount(): Promise<number> {
40+
return await this.cartItems.count();
41+
}
42+
43+
async getItemPrice(index: number): Promise<string> {
44+
return await this.itemPrices.nth(index).innerText();
45+
}
46+
47+
async getItemQuantity(index: number): Promise<string> {
48+
return await this.itemQuantities.nth(index).innerText();
49+
}
50+
}
51+
52+
module.exports = { CartPage };

page_objects_ts/InventoryPage.ts

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,90 @@
1-
import { test, expect, Locator, Page } from "@playwright/test";
1+
import { Locator, Page } from "@playwright/test";
22
export class InventoryPage {
33
page: Page;
4-
userMenu: Locator;
5-
crossUserMenuIcon: Locator;
6-
logoutLink: Locator;
74
addToCartFirstButtonItem: Locator;
8-
shoppingContainerIcon:Locator;
5+
removeButtonFirstItem: Locator;
6+
7+
addToCartButton2ndItem: Locator;
8+
removeButton2ndItem: Locator;
9+
10+
addToCartButton3rdItem: Locator;
11+
removeButton3rdItem: Locator;
12+
13+
addToCartButton4thItem: Locator;
14+
removeButton4thItem: Locator;
15+
16+
addToCartButton5thItem: Locator;
17+
removeButton5thItem: Locator;
18+
19+
addToCartButton6thItem: Locator;
20+
removeButton6thItem: Locator;
21+
22+
shoppingContainerIcon: Locator;
23+
shoppingCartBagde: Locator;
924

1025
constructor(page: Page) {
1126
this.page = page;
12-
this.userMenu = page.locator("#react-burger-menu-btn");
13-
this.crossUserMenuIcon = page.locator("#react-burger-cross-btn");
14-
this.logoutLink = page.locator("#logout_sidebar_link");
15-
this.addToCartFirstButtonItem = page.locator("#add-to-cart-sauce-labs-backpack")
27+
this.addToCartFirstButtonItem = page.locator("#add-to-cart-sauce-labs-backpack");
28+
this.removeButtonFirstItem = page.locator("#remove-sauce-labs-backpack");
29+
30+
this.addToCartButton2ndItem = page.locator("#add-to-cart-sauce-labs-bike-light");
31+
this.removeButton2ndItem = page.locator("#remove-sauce-labs-bike-light");
32+
33+
this.addToCartButton3rdItem = page.locator("#add-to-cart-sauce-labs-bolt-t-shirt");
34+
this.removeButton3rdItem = page.locator("#remove-sauce-labs-bolt-t-shirt");
35+
36+
this.addToCartButton4thItem = page.locator("#add-to-cart-sauce-labs-fleece-jacket");
37+
this.removeButton4thItem = page.locator("#remove-sauce-labs-fleece-jacket");
38+
39+
this.addToCartButton5thItem = page.locator("#add-to-cart-sauce-labs-onesie");
40+
this.removeButton5thItem = page.locator("#remove-sauce-labs-onesie");
41+
42+
this.addToCartButton6thItem = page.locator('[id*="add-to-cart-test.allthethings()-t-shirt-(red)"]');
43+
this.removeButton6thItem = page.locator('[id*="remove-test.allthethings()-t-shirt-(red)"]');
44+
1645
this.shoppingContainerIcon = page.locator("#shopping_cart_container");
46+
this.shoppingCartBagde = page.locator('a span[class="shopping_cart_badge"]');
1747
}
1848

19-
async UserMenuIcon() {
20-
await this.userMenu.click();
49+
async addToCartFirstItem() {
50+
await this.addToCartFirstButtonItem.click();
2151
}
22-
async closeMenuIcon() {
23-
await this.crossUserMenuIcon.click();
52+
async addToCart2ndItem() {
53+
await this.addToCartButton2ndItem.click();
2454
}
25-
async addToCartFirstItem(){
26-
await this.addToCartFirstButtonItem.click();
55+
async addToCart3rdItem() {
56+
await this.addToCartButton3rdItem.click();
2757
}
28-
async ShopContainerIcon(){
29-
await this.shoppingContainerIcon.click();
58+
async addToCart4thItem() {
59+
await this.addToCartButton4thItem.click();
60+
}
61+
async addToCart5thItem() {
62+
await this.addToCartButton5thItem.click();
63+
}
64+
async addToCart6thItem() {
65+
await this.addToCartButton6thItem.click();
66+
}
67+
async removeFirstItem() {
68+
await this.removeButtonFirstItem.click();
3069
}
31-
async Logout() {
32-
await this.logoutLink.click();
70+
async remove2ndItem() {
71+
await this.removeButton2ndItem.click();
72+
}
73+
async remove3rdItem() {
74+
await this.removeButton3rdItem.click();
75+
}
76+
async remove4thItem() {
77+
await this.removeButton4thItem.click();
78+
}
79+
async remove5thItem() {
80+
await this.removeButton5thItem.click();
81+
}
82+
async remove6thItem() {
83+
await this.removeButton6thItem.click();
84+
}
85+
async ShopContainerIcon() {
86+
await this.shoppingContainerIcon.click();
3387
}
34-
3588
}
3689

3790
module.exports = { InventoryPage };

page_objects_ts/UserMenuPage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Locator, Page } from "@playwright/test";
2+
export class UserMenuPage {
3+
page: Page;
4+
userMenu: Locator;
5+
crossUserMenuIcon: Locator;
6+
logoutLink: Locator;
7+
8+
constructor(page: Page) {
9+
this.page = page;
10+
this.userMenu = page.locator("#react-burger-menu-btn");
11+
this.crossUserMenuIcon = page.locator("#react-burger-cross-btn");
12+
this.logoutLink = page.locator("#logout_sidebar_link");
13+
}
14+
15+
async UserMenuIcon() {
16+
await this.userMenu.click();
17+
}
18+
async closeMenuIcon() {
19+
await this.crossUserMenuIcon.click();
20+
}
21+
async Logout() {
22+
await this.logoutLink.click();
23+
}
24+
}
25+
26+
module.exports = { UserMenuPage };

tests/visualUser.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { test, expect } from "@playwright/test";
22
import { MainPage } from "../page_objects_ts/MainPage";
33
import usersData from "../fixtures/usersData.json";
44
import { InventoryPage } from "../page_objects_ts/InventoryPage";
5-
import usersBillingData from "../fixtures/usersBillingData.json";
5+
import { UserMenuPage } from "../page_objects_ts/UserMenuPage";
6+
67

78
test.describe("Visual user tests", () => {
89
test("Visual user issues", async ({ page }) => {
910
const mainPage = new MainPage(page);
1011
const inventoryPage = new InventoryPage(page);
12+
const userMenuPage = new UserMenuPage(page);
1113
const username = usersData.users[5];
1214
const password = usersData.password;
1315

@@ -21,11 +23,11 @@ test.describe("Visual user tests", () => {
2123
await mainPage.loginButton();
2224

2325
await page.waitForURL("/inventory.html");
24-
await inventoryPage.UserMenuIcon();
26+
await userMenuPage.UserMenuIcon();
2527
await expect(
2628
page.locator('img[class*="bm-cross visual_failure"]')
2729
).toBeVisible();
28-
await inventoryPage.closeMenuIcon();
30+
await userMenuPage.closeMenuIcon();
2931
await expect(
3032
page.locator('img[class*="bm-cross visual_failure"]')
3133
).toBeVisible();

0 commit comments

Comments
 (0)