Skip to content

Commit

Permalink
CART/e2etest-a-user-add-a-product-to-cart (#1046)
Browse files Browse the repository at this point in the history
## Context:
added an e2e test. A user adds a product to his cart and then he removes
it
## Does this PR change the .vscode folder in petclinic-frontend?:
no

---------

Co-authored-by: cgerard321 <[email protected]>
  • Loading branch information
Hares-2088 and cgerard321 authored Nov 22, 2024
1 parent 149897d commit a171790
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions petclinic-frontend/tests/cartpage/productToCart.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test, expect } from '@playwright/test';

test('add product to cart from user view and then remove it', async ({ page }) => {
//go to login page
await page.goto('http://localhost:3000/users/login');
await page.getByPlaceholder('Enter your email').click();
await page.getByPlaceholder('Enter your email').fill('[email protected]');
await page.getByPlaceholder('Enter your password').click();
await page.getByPlaceholder('Enter your password').fill('pwd');
await page.getByRole('button', { name: 'Login' }).click();

//go to shop page
await page.getByRole('link', { name: 'Shop', exact: true }).click();

//find the div with product that has page.getByRole('heading', { name: 'Rabbit Hutch' })
const productDiv = await page.getByRole('heading', { name: 'Rabbit Hutch' }).locator('..');

//on the same div, find the button and click it
await productDiv.locator('button').first().click();

//make sure product is added to cart
await expect(page.locator('#root')).toContainText('Product added to cart successfully!');

//go to cart page
await page.getByRole('link', { name: 'Shopping Cart Cart has 2 items' }).click();
//make sure product is in cart with all details
await expect(page.getByText('Rabbit HutchOutdoor wooden hutch for rabbits$79.99RemoveAdd to Wishlist')).toBeVisible();

//remove product from cart
await page.getByLabel('Remove Rabbit Hutch from cart').click();

//close the page
await page.close();
});

0 comments on commit a171790

Please sign in to comment.