From decb80ebb25de2f0d363735d4eebfcf50019fcaa Mon Sep 17 00:00:00 2001 From: Butch Mayhew Date: Mon, 22 Apr 2024 22:54:46 -0500 Subject: [PATCH] updating specs (#12) --- tests/scenarios/addToCart.spec.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/scenarios/addToCart.spec.ts b/tests/scenarios/addToCart.spec.ts index 4c38b60..e902777 100644 --- a/tests/scenarios/addToCart.spec.ts +++ b/tests/scenarios/addToCart.spec.ts @@ -1,13 +1,16 @@ import { test, expect } from "@playwright/test"; test("Validate cart is updated from product details page", async ({ page }) => { + const productName = "Claw Hammer with Shock Reduction Grip"; await page.goto("https://practicesoftwaretesting.com/#/"); await page.getByTestId("nav-categories").click(); await page.getByTestId("nav-hand-tools").click(); - await page.getByTestId("product-01HW1VY6EF69H453A43ZASG43C").click(); - await expect(page.getByTestId("product-name")).toContainText( - "Claw Hammer with Shock Reduction Grip" - ); + // create a playwright locator that will find a link with a child div that has text of "Claw Hammer with Shock Reduction Grip" and click the link + await page + .locator('a >> div:has-text("Claw Hammer with Shock Reduction Grip")') + .click(); + // await page.getByTestId("product-01HW4EAZ6N8RP9NNC55NT5AXPW").click(); + await expect(page.getByTestId("product-name")).toContainText(productName); await expect(page.locator("app-detail")).toContainText("Hammer"); await expect(page.getByLabel("brand")).toContainText("ForgeFlex Tools"); await page.getByTestId("increase-quantity").click(); @@ -16,7 +19,5 @@ test("Validate cart is updated from product details page", async ({ page }) => { await expect(page.getByTestId("cart-quantity")).toContainText("2"); await page.getByTestId("nav-cart").click(); await expect(page.getByRole("spinbutton")).toHaveValue("2"); - await expect(page.locator("tbody")).toContainText( - "Claw Hammer with Shock Reduction Grip" - ); + await expect(page.locator("tbody")).toContainText(productName); });