|
| 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("Tests for error user", () => { |
| 6 | + test("Login, adding and remove from cart iteams", async ({ page }) => { |
| 7 | + const poManager = new POManager(page); |
| 8 | + const username = usersData.users[4]; |
| 9 | + const password = usersData.password; |
| 10 | + |
| 11 | + await poManager.mainPage.visitMainPage(); |
| 12 | + await poManager.mainPage.fillUsername(username); |
| 13 | + await poManager.mainPage.fillPassword(password); |
| 14 | + await poManager.mainPage.loginButton(); |
| 15 | + await page.waitForURL("/inventory.html"); |
| 16 | + |
| 17 | + await poManager.inventoryPage.addToCartFirstItem(); |
| 18 | + await expect(poManager.inventoryPage.removeButtonFirstItem).toBeVisible(); |
| 19 | + await poManager.inventoryPage.removeFirstItem(); |
| 20 | + await expect( |
| 21 | + poManager.inventoryPage.addToCartFirstButtonItem |
| 22 | + ).not.toBeVisible(); |
| 23 | + |
| 24 | + await poManager.inventoryPage.addToCart2ndItem(); |
| 25 | + await expect(poManager.inventoryPage.removeButton2ndItem).toBeVisible(); |
| 26 | + await poManager.inventoryPage.remove2ndItem(); |
| 27 | + await expect( |
| 28 | + poManager.inventoryPage.addToCartButton2ndItem |
| 29 | + ).not.toBeVisible(); |
| 30 | + |
| 31 | + await poManager.inventoryPage.addToCart3rdItem(); |
| 32 | + await expect(poManager.inventoryPage.addToCartButton3rdItem).toBeVisible(); |
| 33 | + await expect(poManager.inventoryPage.removeButton3rdItem).not.toBeVisible(); |
| 34 | + |
| 35 | + await poManager.inventoryPage.addToCart4thItem(); |
| 36 | + await expect(poManager.inventoryPage.addToCartButton4thItem).toBeVisible(); |
| 37 | + await expect(poManager.inventoryPage.removeButton4thItem).not.toBeVisible(); |
| 38 | + |
| 39 | + await poManager.inventoryPage.addToCart5thItem(); |
| 40 | + await expect(poManager.inventoryPage.removeButton5thItem).toBeVisible(); |
| 41 | + await poManager.inventoryPage.remove5thItem(); |
| 42 | + await expect( |
| 43 | + poManager.inventoryPage.addToCartButton5thItem |
| 44 | + ).not.toBeVisible(); |
| 45 | + |
| 46 | + await poManager.inventoryPage.addToCart6thItem(); |
| 47 | + await expect(poManager.inventoryPage.addToCartButton6thItem).toBeVisible(); |
| 48 | + await expect(poManager.inventoryPage.removeButton6thItem).not.toBeVisible(); |
| 49 | + }); |
| 50 | + |
| 51 | + test("Verify sorting error modal", async ({ page }) => { |
| 52 | + const poManager = new POManager(page); |
| 53 | + const username = usersData.users[4]; |
| 54 | + const password = usersData.password; |
| 55 | + |
| 56 | + // Login to the application |
| 57 | + await poManager.mainPage.visitMainPage(); |
| 58 | + await poManager.mainPage.fillUsername(username); |
| 59 | + await poManager.mainPage.fillPassword(password); |
| 60 | + await poManager.mainPage.loginButton(); |
| 61 | + await page.waitForURL("/inventory.html"); |
| 62 | + |
| 63 | + // Set up alert handling BEFORE triggering sorting |
| 64 | + const dialogPromise = new Promise((resolve) => { |
| 65 | + page.once("dialog", async (dialog) => { |
| 66 | + console.log("Dialog message:", dialog.message()); |
| 67 | + expect(dialog.message()).toContain("Sorting is broken!"); |
| 68 | + await dialog.dismiss(); // Clicks "OK" |
| 69 | + resolve(true); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + // Select the sorting option |
| 74 | + await page.selectOption(".product_sort_container", "za"); |
| 75 | + |
| 76 | + // Ensure the alert was handled |
| 77 | + await dialogPromise; |
| 78 | + }); |
| 79 | + |
| 80 | + test("Last name field issue that causing failure with purshase", async ({ page }) => { |
| 81 | + const poManager = new POManager(page); |
| 82 | + const username = usersData.users[4]; |
| 83 | + const password = usersData.password; |
| 84 | + |
| 85 | + // Login to the application |
| 86 | + await poManager.mainPage.visitMainPage(); |
| 87 | + await poManager.mainPage.fillUsername(username); |
| 88 | + await poManager.mainPage.fillPassword(password); |
| 89 | + await poManager.mainPage.loginButton(); |
| 90 | + await page.waitForURL("/inventory.html"); |
| 91 | + |
| 92 | + await poManager.inventoryPage.addToCartFirstItem(); |
| 93 | + await poManager.inventoryPage.ShopContainerIcon(); |
| 94 | + await poManager.cartPage.clickCheckout(); |
| 95 | + await poManager.checkoutStepOnePage.enterCheckoutDetails( |
| 96 | + "Yulia", |
| 97 | + "Test", |
| 98 | + "34221" |
| 99 | + ); |
| 100 | + await poManager.checkoutStepOnePage.submitCheckout(); |
| 101 | + await poManager.checkoutStepTwoPage.completeCheckout(); |
| 102 | + |
| 103 | + // Assert Finish button is visible and enabled (clickable) |
| 104 | + await expect(poManager.checkoutStepTwoPage.finishButton).toBeVisible(); |
| 105 | + await expect(poManager.checkoutStepTwoPage.finishButton).toBeEnabled(); |
| 106 | + |
| 107 | + await page.waitForTimeout(1000); |
| 108 | + |
| 109 | + // Assert the user remains on the same page (URL does not change) |
| 110 | + await expect(page).toHaveURL("/checkout-step-two.html"); |
| 111 | + }); |
| 112 | +}); |
0 commit comments