|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import usersData from "../fixtures/usersData.json"; |
| 3 | +import { POManager } from "../page_objects_ts/POManager"; |
| 4 | + |
| 5 | +test.describe("Problem user tests", () => { |
| 6 | + test("Problem user sees the same image for all products", async ({ |
| 7 | + page, |
| 8 | + }) => { |
| 9 | + const poManager = new POManager(page); |
| 10 | + const username = usersData.users[2]; // "problem_user" |
| 11 | + const password = usersData.password; |
| 12 | + |
| 13 | + // Step 1: Login |
| 14 | + await poManager.mainPage.visitMainPage(); |
| 15 | + await poManager.mainPage.fillUsername(username); |
| 16 | + await poManager.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 poManager.mainPage.loginButton(); |
| 22 | + await page.waitForURL("/inventory.html"); |
| 23 | + |
| 24 | + // Step 2: Verify all product images are visible |
| 25 | + const productItems = await page.locator(".inventory_item"); |
| 26 | + const count = await productItems.count(); |
| 27 | + |
| 28 | + for (let i = 0; i < count; i++) { |
| 29 | + const image = productItems.nth(i).locator("img"); |
| 30 | + await expect(image).toBeVisible(); |
| 31 | + } |
| 32 | + |
| 33 | + // Step 3: Assert all images have the same `src` attribute |
| 34 | + const allImageSrcs = await page.$$eval(".inventory_item img", (imgs) => |
| 35 | + imgs.map((img) => img.getAttribute("src")) |
| 36 | + ); |
| 37 | + |
| 38 | + const uniqueSrcs = new Set(allImageSrcs); |
| 39 | + expect(uniqueSrcs.size).toBe(1); // Problem user sees repeated images |
| 40 | + }); |
| 41 | + |
| 42 | + test("Problem user login, adding and remove from cart items", async ({ |
| 43 | + page, |
| 44 | + }) => { |
| 45 | + const poManager = new POManager(page); |
| 46 | + const username = usersData.users[2]; // "problem_user" |
| 47 | + const password = usersData.password; |
| 48 | + |
| 49 | + // Step 1: Login |
| 50 | + await poManager.mainPage.visitMainPage(); |
| 51 | + await poManager.mainPage.fillUsername(username); |
| 52 | + await poManager.mainPage.fillPassword(password); |
| 53 | + |
| 54 | + await expect(page.locator('input[name="user-name"]')).toHaveValue(username); |
| 55 | + await expect(page.locator('input[name="password"]')).toHaveValue(password); |
| 56 | + |
| 57 | + await poManager.mainPage.loginButton(); |
| 58 | + await page.waitForURL("/inventory.html"); |
| 59 | + await poManager.inventoryPage.addToCartFirstItem(); |
| 60 | + await expect(poManager.inventoryPage.removeButtonFirstItem).toBeVisible(); |
| 61 | + await poManager.inventoryPage.removeFirstItem(); |
| 62 | + await expect( |
| 63 | + poManager.inventoryPage.addToCartFirstButtonItem |
| 64 | + ).not.toBeVisible(); |
| 65 | + |
| 66 | + await poManager.inventoryPage.addToCart2ndItem(); |
| 67 | + await expect(poManager.inventoryPage.removeButton2ndItem).toBeVisible(); |
| 68 | + await poManager.inventoryPage.remove2ndItem(); |
| 69 | + await expect( |
| 70 | + poManager.inventoryPage.addToCartButton2ndItem |
| 71 | + ).not.toBeVisible(); |
| 72 | + |
| 73 | + await poManager.inventoryPage.addToCart3rdItem(); |
| 74 | + await expect(poManager.inventoryPage.addToCartButton3rdItem).toBeVisible(); |
| 75 | + await expect(poManager.inventoryPage.removeButton3rdItem).not.toBeVisible(); |
| 76 | + |
| 77 | + await poManager.inventoryPage.addToCart4thItem(); |
| 78 | + await expect(poManager.inventoryPage.addToCartButton4thItem).toBeVisible(); |
| 79 | + await expect(poManager.inventoryPage.removeButton4thItem).not.toBeVisible(); |
| 80 | + |
| 81 | + await poManager.inventoryPage.addToCart5thItem(); |
| 82 | + await expect(poManager.inventoryPage.removeButton5thItem).toBeVisible(); |
| 83 | + await poManager.inventoryPage.remove5thItem(); |
| 84 | + await expect( |
| 85 | + poManager.inventoryPage.addToCartButton5thItem |
| 86 | + ).not.toBeVisible(); |
| 87 | + |
| 88 | + await poManager.inventoryPage.addToCart6thItem(); |
| 89 | + await expect(poManager.inventoryPage.addToCartButton6thItem).toBeVisible(); |
| 90 | + await expect(poManager.inventoryPage.removeButton6thItem).not.toBeVisible(); |
| 91 | + |
| 92 | + await poManager.inventoryPage.ShopContainerIcon(); |
| 93 | + const itemsToRemove = [ |
| 94 | + "Sauce Labs Backpack", |
| 95 | + "Sauce Labs Bike Light", |
| 96 | + "Sauce Labs Onesie", |
| 97 | + ]; |
| 98 | + |
| 99 | + for (const item of itemsToRemove) { |
| 100 | + await poManager.cartPage.removeItemByName(item); |
| 101 | + await poManager.cartPage.assertItemRemovedByName(item); |
| 102 | + } |
| 103 | + }); |
| 104 | + test("Last name field issue that causing failure with purshase", async ({ |
| 105 | + page, |
| 106 | + }) => { |
| 107 | + const poManager = new POManager(page); |
| 108 | + const username = usersData.users[2]; |
| 109 | + const password = usersData.password; |
| 110 | + |
| 111 | + // Login to the application |
| 112 | + await poManager.mainPage.visitMainPage(); |
| 113 | + await poManager.mainPage.fillUsername(username); |
| 114 | + await poManager.mainPage.fillPassword(password); |
| 115 | + await poManager.mainPage.loginButton(); |
| 116 | + await page.waitForURL("/inventory.html"); |
| 117 | + |
| 118 | + await poManager.inventoryPage.addToCartFirstItem(); |
| 119 | + await poManager.inventoryPage.ShopContainerIcon(); |
| 120 | + await poManager.cartPage.clickCheckout(); |
| 121 | + await poManager.checkoutStepOnePage.enterCheckoutDetails( |
| 122 | + "Yulia", |
| 123 | + "Test", |
| 124 | + "34221" |
| 125 | + ); |
| 126 | + await poManager.checkoutStepOnePage.submitCheckout(); |
| 127 | + await expect(page.locator(".error-message-container")).toHaveText( |
| 128 | + "Error: Last Name is required" |
| 129 | + ); |
| 130 | + await page.waitForTimeout(1000); |
| 131 | + |
| 132 | + // Assert the user remains on the same page (URL does not change) |
| 133 | + await expect(page).toHaveURL("/checkout-step-one.html"); |
| 134 | + }); |
| 135 | +}); |
0 commit comments