STF_03.spec.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import { expect, test } from "@playwright/test";
  2. import {
  3. addCurrentProductToCart,
  4. clickOnRandomProductElement,
  5. getCurrentProductPrice,
  6. openCart,
  7. selectRandomAvailableVariant,
  8. } from "./utils";
  9. test("STF_03: Check if price are calculating correctly", async ({ page }) => {
  10. await page.goto("/");
  11. const product = await clickOnRandomProductElement({ page });
  12. await selectRandomAvailableVariant({ page });
  13. const price = await getCurrentProductPrice({ page });
  14. await expect(page.getByTestId("CartNavItem")).toContainText("0 items");
  15. await addCurrentProductToCart({ page });
  16. await expect(page.getByTestId("CartNavItem")).toContainText("1 item");
  17. await addCurrentProductToCart({ page });
  18. await expect(page.getByTestId("CartNavItem")).toContainText("2 items");
  19. await openCart({ page });
  20. const totalPrice = (price * 2).toFixed(2);
  21. const productInCart = page.getByTestId("CartProductList").getByRole("listitem");
  22. await expect(productInCart).toHaveCount(1);
  23. await expect(productInCart).toContainText(product.name);
  24. await expect(productInCart).toContainText(`Qty: 2`);
  25. await expect(productInCart).toContainText(totalPrice);
  26. });