Skip to content

Commit

Permalink
refactor test specs
Browse files Browse the repository at this point in the history
  • Loading branch information
PollySt committed Jan 24, 2024
1 parent 8fdb21e commit 2ba8364
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 58 deletions.
49 changes: 0 additions & 49 deletions e2e/tests/add-to-cart.spec.ts

This file was deleted.

Empty file removed e2e/tests/example.spec.ts
Empty file.
51 changes: 42 additions & 9 deletions e2e/tests/shopping-cart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { test } from '../fixtures';
import {
COLLECTION_NAME,
COLLECTIONS_ENDPOINT,
HOMEPAGE_ENDPOINT,
PRODUCT_COLOR_OUTOFSTOCK,
PRODUCT_NAME,
PRODUCT_OUTOFSTOCK,
Expand All @@ -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 }) => {
Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 2ba8364

Please sign in to comment.