-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CART/e2etest-a-user-add-a-product-to-cart (#1046)
## 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
1 parent
149897d
commit a171790
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |