|
| 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