From 7417cd921ab1b18227aceae7cf87a1df94fad797 Mon Sep 17 00:00:00 2001 From: Cherrelle Morrison Date: Sat, 17 Dec 2022 12:32:31 -0500 Subject: [PATCH] wishlist exam submission --- cypress/e2e/page/product.details.page.js | 13 ++++ cypress/e2e/page/product.home.page.js | 28 ++++++++ cypress/e2e/page/wishlist.page.js | 24 +++++++ cypress/e2e/test/wishlist.cy.js | 89 ++++++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 cypress/e2e/page/wishlist.page.js create mode 100644 cypress/e2e/test/wishlist.cy.js diff --git a/cypress/e2e/page/product.details.page.js b/cypress/e2e/page/product.details.page.js index 1377e6c..a79e18a 100644 --- a/cypress/e2e/page/product.details.page.js +++ b/cypress/e2e/page/product.details.page.js @@ -19,6 +19,19 @@ class ProductDetailPage { get backNavigation() { return ('div.chakra-stack.css-dpkrn2') } + + get addToFavoritesBtn() { + return ('#add-to-favorite') + } + + get removeFromFavoritesBtn() { + return ('#remove-from-favorite') + } + + get alertPopUpMsg() { + return ('.chakra-alert__title.css-tidvy5') + } + //method addToCart() { cy.get(this.addToCartBtn).scrollIntoView() diff --git a/cypress/e2e/page/product.home.page.js b/cypress/e2e/page/product.home.page.js index ce51708..ddcc694 100644 --- a/cypress/e2e/page/product.home.page.js +++ b/cypress/e2e/page/product.home.page.js @@ -64,5 +64,33 @@ class ProductHomePage { return ('img[src="/images/quality-pillow.jpg"]') } + get addToFavoritesBtns() { + return ('#add-to-favorite') + } + + get removeFromFavoritesBtn() { + return ('#remove-from-favorite') + } + + get qualityMugFavoriteBtn() { + return ('#product-3 div.css-1m8iww1') + } + + get qualityPillowFavoriteBtn() { + return ('#product-4 div.css-1m8iww1') + } + + get hoodedSweatshirtFavoriteBtn() { + return ('#product-5 div.css-1m8iww1') + } + + get alertPopUpMsg() { + return ('.chakra-alert__title.css-tidvy5') + } + + get closePopUp() { + return ('button[aria-label="Close"]') + } + } export default new ProductHomePage() \ No newline at end of file diff --git a/cypress/e2e/page/wishlist.page.js b/cypress/e2e/page/wishlist.page.js new file mode 100644 index 0000000..f3cc8a0 --- /dev/null +++ b/cypress/e2e/page/wishlist.page.js @@ -0,0 +1,24 @@ +class WishListPage { + + //getters + get favoritesMenuTab() { + return ('#top-favorite') + } + + get favoritesBadge() { + return ('#top-favorite p') + } + + get hoodedSweatShirtCartBtn() { + return ('button[data-item-id="quality-sweatshirt-hooded"]') + } + + get favoriteProductTitles() { + return ('div.chakra-stack.css-1oeb4ru > p') + } + + + //methods + +} +export default new WishListPage() \ No newline at end of file diff --git a/cypress/e2e/test/wishlist.cy.js b/cypress/e2e/test/wishlist.cy.js new file mode 100644 index 0000000..d5583ea --- /dev/null +++ b/cypress/e2e/test/wishlist.cy.js @@ -0,0 +1,89 @@ +import ProductDetailsPage from "../page/product.details.page" +import ProductHomePage from "../page/product.home.page" +import WishlistPage from "../page/wishlist.page" + +describe('Wishlist', () => { + beforeEach('Visit the products home page', () =>{ + cy.visit('/products') + cy.wait(1500) + }) + + it('Confirm that each product has an add to favorite option from the products gallery home page', () =>{ + cy.get(ProductHomePage.addToFavoritesBtns).should('exist') + }) + + it('Confirm that a product can be added to favorites from the products gallery home page', () =>{ + cy.get(ProductHomePage.qualityMugFavoriteBtn, {timeout: 1000}).should('exist') + cy.get(ProductHomePage.qualityMugFavoriteBtn).click() + cy.get(ProductHomePage.alertPopUpMsg).should('include.text', 'added to favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '1') + }) + + it('Confirm that multiple products can be added to favorites from the products gallery home page', () =>{ + cy.get(ProductHomePage.qualityMugFavoriteBtn, {timeout: 1000}).should('exist') + cy.get(ProductHomePage.qualityMugFavoriteBtn).click() + cy.get(ProductHomePage.alertPopUpMsg).should('include.text', 'added to favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '1') + + + cy.get(ProductHomePage.hoodedSweatshirtFavoriteBtn, {timeout: 1000}).should('exist') + cy.get(ProductHomePage.hoodedSweatshirtFavoriteBtn).click() + cy.get(ProductHomePage.alertPopUpMsg).should('include.text', 'added to favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '2') + + + cy.get(ProductHomePage.qualityPillowFavoriteBtn, {timeout: 1000}).should('exist') + cy.get(ProductHomePage.qualityPillowFavoriteBtn).click() + cy.get(ProductHomePage.alertPopUpMsg).should('include.text', 'added to favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '3') + + }) + + it('Confirm that a product can be added to favorites from the product details page', () =>{ + cy.get(ProductHomePage.hoodedSweatshirt).scrollIntoView().click() + cy.location('pathname', { timeout: 40000 }).should('eq', '/products/quality-sweatshirt-hooded') + cy.get(ProductDetailsPage.productName, { timeout: 10000 }).should('exist') + cy.get(ProductDetailsPage.addToFavoritesBtn, {timeout: 1000}).should('exist') + cy.get(ProductDetailsPage.addToFavoritesBtn).click() + cy.get(ProductDetailsPage.alertPopUpMsg).should('include.text', 'added to favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '1') + }) + + it('Confirm that a product can be removed from favorites from the products gallery home page', () =>{ + cy.get(ProductHomePage.qualityMugFavoriteBtn, {timeout: 1000}).should('exist') + cy.get(ProductHomePage.qualityMugFavoriteBtn).click() + cy.get(ProductHomePage.alertPopUpMsg).should('include.text', 'added to favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '1') + cy.get(ProductHomePage.removeFromFavoritesBtn).click() + cy.get(ProductHomePage.alertPopUpMsg).should('include.text', 'removed from favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '0') + }) + + it('Confirm that a product can be removed from favorites from the product details page', () =>{ + cy.get(ProductHomePage.hoodedSweatshirt).scrollIntoView().click() + cy.location('pathname', { timeout: 40000 }).should('eq', '/products/quality-sweatshirt-hooded') + cy.get(ProductDetailsPage.productName, { timeout: 10000 }).should('exist') + cy.get(ProductDetailsPage.addToFavoritesBtn, {timeout: 1000}).should('exist') + cy.get(ProductDetailsPage.addToFavoritesBtn).click() + cy.get(ProductDetailsPage.alertPopUpMsg).should('include.text', 'added to favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '1') + cy.get(ProductDetailsPage.removeFromFavoritesBtn).click() + cy.get(ProductHomePage.alertPopUpMsg).should('include.text', 'removed from favorites') + cy.get(WishlistPage.favoritesBadge).should('include.text', '0') + }) + + it('Confirm that navigating to another page does not remove the product from the wishlist', () =>{ + cy.get(ProductHomePage.qualityMugFavoriteBtn, {timeout: 1000}).should('exist') + cy.get(ProductHomePage.qualityMugFavoriteBtn).click() + cy.get(WishlistPage.favoritesMenuTab).click() + cy.get(WishlistPage.favoriteProductTitles).should('exist') + cy.get(WishlistPage.favoriteProductTitles).should('include.text', 'Quality Mug') + cy.get(ProductHomePage.closePopUp).click() + cy.get(ProductHomePage.contactTab).click() + cy.get(WishlistPage.favoritesBadge).should('include.text', '1') + cy.get(WishlistPage.favoritesMenuTab).click() + cy.get(WishlistPage.favoriteProductTitles).should('exist') + cy.get(WishlistPage.favoriteProductTitles).should('include.text', 'Quality Mug') + }) + +}) \ No newline at end of file