diff --git a/e2e/tests/add-to-cart.spec.ts b/e2e/tests/add-to-cart.spec.ts deleted file mode 100644 index 37355a4f..00000000 --- a/e2e/tests/add-to-cart.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { expect } from 'playwright/test'; -import { COLLECTION_NAME, COLLECTIONS_ENDPOINT, PRODUCT_NAME } from '../constants'; -import { test } from '../fixtures'; - -test.describe('Add to cart', () => { - test.beforeEach('Navigate to the Collections page', async ({ page }) => { - if (!COLLECTION_NAME) { - test.skip(!COLLECTION_NAME, 'PLAYWRIGHT_COLLECTION_NAME was not defined'); - return; - } - await page.goto(COLLECTIONS_ENDPOINT + COLLECTION_NAME); - }); - - test('User is able to add product to cart', async ({ page, collectionsPage, shoppingCart, productPage }) => { - if (!PRODUCT_NAME) { - test.skip(!PRODUCT_NAME, 'PLAYWRIGHT_PRODUCT_NAME was not defined'); - return; - } - - await collectionsPage.getProductByName(PRODUCT_NAME).click(); - await expect(page.getByLabel('Breadcrumb')).toContainText(PRODUCT_NAME); - - const productPrice = await productPage.productPrice().innerText(); - - await productPage.addToCartBtn().click(); - await expect(page.getByText('Shopping cart')).toBeVisible(); - await expect(shoppingCart.shoppingCartItems()).toHaveCount(1); - await expect(shoppingCart.shoppingCartItems()).toContainText(PRODUCT_NAME); - await expect(shoppingCart.cartTotalPrice()).toContainText(productPrice); - }); - - test('Checkout phase', async ({ page, shoppingCart, collectionsPage, productPage }) => { - if (!PRODUCT_NAME) { - test.skip(!PRODUCT_NAME, 'PLAYWRIGHT_PRODUCT_NAME was not defined'); - return; - } - - await collectionsPage.getProductByName(PRODUCT_NAME).click(); - await productPage.addToCartBtn().click(); - await expect(page.getByText('Shopping cart')).toBeVisible(); - await expect(shoppingCart.shoppingCartItems()).toContainText(PRODUCT_NAME); - - await page.goto('/?shopify_checkout_action=success'); - - await page.waitForURL('/'); - await page.getByText('Successfully checked out').waitFor(); - await expect(shoppingCart.cartItemsCount()).toContainText('0'); - }); -}); diff --git a/e2e/tests/example.spec.ts b/e2e/tests/example.spec.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/e2e/tests/shopping-cart.spec.ts b/e2e/tests/shopping-cart.spec.ts index 85e44d46..e11d0096 100644 --- a/e2e/tests/shopping-cart.spec.ts +++ b/e2e/tests/shopping-cart.spec.ts @@ -2,7 +2,6 @@ import { test } from '../fixtures'; import { COLLECTION_NAME, COLLECTIONS_ENDPOINT, - HOMEPAGE_ENDPOINT, PRODUCT_COLOR_OUTOFSTOCK, PRODUCT_NAME, PRODUCT_OUTOFSTOCK, @@ -11,8 +10,48 @@ import { import { expect } from 'playwright/test'; test.describe('Shopping cart', () => { - test.beforeEach('Navigate to the Home page', async ({ page }) => { - await page.goto(HOMEPAGE_ENDPOINT); + test.beforeEach('Navigate to the Collections page', async ({ page }) => { + if (!COLLECTION_NAME) { + test.skip(!COLLECTION_NAME, 'PLAYWRIGHT_COLLECTION_NAME was not defined'); + return; + } + await page.goto(COLLECTIONS_ENDPOINT + COLLECTION_NAME); + }); + + test('User is able to add product to cart', async ({ page, collectionsPage, shoppingCart, productPage }) => { + if (!PRODUCT_NAME) { + test.skip(!PRODUCT_NAME, 'PLAYWRIGHT_PRODUCT_NAME was not defined'); + return; + } + + await collectionsPage.getProductByName(PRODUCT_NAME).click(); + await expect(page.getByLabel('Breadcrumb')).toContainText(PRODUCT_NAME); + + const productPrice = await productPage.productPrice().innerText(); + + await productPage.addToCartBtn().click(); + await expect(page.getByText('Shopping cart')).toBeVisible(); + await expect(shoppingCart.shoppingCartItems()).toHaveCount(1); + await expect(shoppingCart.shoppingCartItems()).toContainText(PRODUCT_NAME); + await expect(shoppingCart.cartTotalPrice()).toContainText(productPrice); + }); + + test('Checkout phase', async ({ page, shoppingCart, collectionsPage, productPage }) => { + if (!PRODUCT_NAME) { + test.skip(!PRODUCT_NAME, 'PLAYWRIGHT_PRODUCT_NAME was not defined'); + return; + } + + await collectionsPage.getProductByName(PRODUCT_NAME).click(); + await productPage.addToCartBtn().click(); + await expect(page.getByText('Shopping cart')).toBeVisible(); + await expect(shoppingCart.shoppingCartItems()).toContainText(PRODUCT_NAME); + + await page.goto('/?shopify_checkout_action=success'); + + await page.waitForURL('/'); + await page.getByText('Successfully checked out').waitFor(); + await expect(shoppingCart.cartItemsCount()).toContainText('0'); }); test('Verify clicking on the cart icon opens shopping cart', async ({ shoppingCart }) => { @@ -26,9 +65,7 @@ test.describe('Shopping cart', () => { test.skip(!PRODUCT_NAME, 'PLAYWRIGHT_PRODUCT_NAME was not defined'); return; } - test.skip(!COLLECTION_NAME, 'PLAYWRIGHT_COLLECTION_NAME was not defined'); - await page.goto(COLLECTIONS_ENDPOINT + COLLECTION_NAME); await collectionsPage.getProductByName(PRODUCT_NAME).click(); await page.getByLabel('Breadcrumb').waitFor(); @@ -53,9 +90,7 @@ test.describe('Shopping cart', () => { test.skip(!PRODUCT_NAME, 'PLAYWRIGHT_PRODUCT_NAME was not defined'); return; } - test.skip(!COLLECTION_NAME, 'PLAYWRIGHT_COLLECTION_NAME was not defined'); - await page.goto(COLLECTIONS_ENDPOINT + COLLECTION_NAME); await collectionsPage.getProductByName(PRODUCT_NAME).click(); await page.getByLabel('Breadcrumb').waitFor(); @@ -84,9 +119,7 @@ test.describe('Shopping cart', () => { test.skip(!PRODUCT_SIZE_OUTOFSTOCK, 'PLAYWRIGHT_PRODUCT_SIZE_OUTOFSTOCK was not defined'); return; } - test.skip(!COLLECTION_NAME, 'PLAYWRIGHT_COLLECTION_NAME was not defined'); - await page.goto(COLLECTIONS_ENDPOINT + COLLECTION_NAME); await collectionsPage.getProductByName(PRODUCT_OUTOFSTOCK).click(); await page.getByLabel('Breadcrumb').waitFor();