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 3912871

Browse files
authored
Merge pull request #16 from auto-qa-hub/tests-for-visual-user
test-for-visual-user
2 parents a625025 + ee726a6 commit 3912871

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

fixtures/usersBillingData.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"firstname": "TestName",
3+
"lastname": "TestLastName",
4+
"zip": 92618
5+
}

page_objects_ts/InventoryPage.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,36 @@ import { test, expect, Locator, Page } from "@playwright/test";
22
export class InventoryPage {
33
page: Page;
44
userMenu: Locator;
5+
crossUserMenuIcon: Locator;
56
logoutLink: Locator;
7+
addToCartFirstButtonItem: Locator;
8+
shoppingContainerIcon:Locator;
69

710
constructor(page: Page) {
811
this.page = page;
912
this.userMenu = page.locator("#react-burger-menu-btn");
13+
this.crossUserMenuIcon = page.locator("#react-burger-cross-btn");
1014
this.logoutLink = page.locator("#logout_sidebar_link");
15+
this.addToCartFirstButtonItem = page.locator("#add-to-cart-sauce-labs-backpack")
16+
this.shoppingContainerIcon = page.locator("#shopping_cart_container");
1117
}
1218

1319
async UserMenuIcon() {
1420
await this.userMenu.click();
1521
}
22+
async closeMenuIcon() {
23+
await this.crossUserMenuIcon.click();
24+
}
25+
async addToCartFirstItem(){
26+
await this.addToCartFirstButtonItem.click();
27+
}
28+
async ShopContainerIcon(){
29+
await this.shoppingContainerIcon.click();
30+
}
1631
async Logout() {
1732
await this.logoutLink.click();
1833
}
34+
1935
}
2036

2137
module.exports = { InventoryPage };

tests/visualUser.spec.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { test, expect } from "@playwright/test";
2+
import { MainPage } from "../page_objects_ts/MainPage";
3+
import usersData from "../fixtures/usersData.json";
4+
import { InventoryPage } from "../page_objects_ts/InventoryPage";
5+
import usersBillingData from "../fixtures/usersBillingData.json";
6+
7+
test.describe("Visual user tests", () => {
8+
test("Visual user issues", async ({ page }) => {
9+
const mainPage = new MainPage(page);
10+
const inventoryPage = new InventoryPage(page);
11+
const username = usersData.users[5];
12+
const password = usersData.password;
13+
14+
await mainPage.visitMainPage();
15+
await mainPage.fillUsername(username);
16+
await mainPage.fillPassword(password);
17+
18+
await expect(page.locator('input[name="user-name"]')).toHaveValue(username);
19+
await expect(page.locator('input[name="password"]')).toHaveValue(password);
20+
21+
await mainPage.loginButton();
22+
23+
await page.waitForURL("/inventory.html");
24+
await inventoryPage.UserMenuIcon();
25+
await expect(
26+
page.locator('img[class*="bm-cross visual_failure"]')
27+
).toBeVisible();
28+
await inventoryPage.closeMenuIcon();
29+
await expect(
30+
page.locator('img[class*="bm-cross visual_failure"]')
31+
).toBeVisible();
32+
33+
// Verify title class and spacing
34+
const idElementOne = page.locator(
35+
"#item_1_title_link .inventory_item_name"
36+
);
37+
await expect(idElementOne).toHaveText("Sauce Labs Bolt T-Shirt");
38+
await expect(idElementOne).toHaveClass(/inventory_item_name\s+align_right/);
39+
40+
const idElementTwo = page.locator(
41+
"#item_5_title_link .inventory_item_name"
42+
);
43+
await expect(idElementTwo).toHaveText("Sauce Labs Fleece Jacket");
44+
await expect(idElementTwo).toHaveClass(/inventory_item_name\s+align_right/);
45+
46+
//Verify shopping icon and badge
47+
const shoppingCart = page.locator("#shopping_cart_container");
48+
await expect(shoppingCart).toHaveClass(
49+
/shopping_cart_container\s+visual_failure/
50+
);
51+
await inventoryPage.addToCartFirstItem();
52+
await expect(
53+
page.locator('a span[class="shopping_cart_badge"]')
54+
).toBeVisible();
55+
56+
await inventoryPage.ShopContainerIcon();
57+
await page.goto("/cart.html");
58+
// Locate the item name using data-test attribute
59+
const itemName = page.locator('[data-test="inventory-item-name"]');
60+
61+
// Verify the item name is "Sauce Labs Backpack"
62+
await expect(itemName).toHaveText("Sauce Labs Backpack");
63+
64+
// Verify Checkout button exists and is clickable
65+
const checkoutButton = page.locator("button", { hasText: "Checkout" });
66+
await expect(checkoutButton).toBeVisible();
67+
await expect(checkoutButton).toHaveClass(
68+
/btn\s+btn_action\s+btn_medium\s+checkout_button\s+btn_visual_failure/
69+
);
70+
71+
// Click on Checkout button
72+
await checkoutButton.click();
73+
74+
await expect(shoppingCart).toHaveClass(
75+
/shopping_cart_container\s+visual_failure/
76+
);
77+
await expect(
78+
page.locator('a span[class="shopping_cart_badge"]')
79+
).toBeVisible();
80+
});
81+
});

0 commit comments

Comments
 (0)