From f5dfd1bcb5aef48119ec214da1467ff706881c08 Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 10:55:36 +0200 Subject: [PATCH 01/17] chore: refactor cart tests --- cypress/fixtures/luma/selectors/cart.json | 42 +++++++++---------- cypress/integration/luma/cart/cart.spec.js | 48 ++++++++++------------ 2 files changed, 41 insertions(+), 49 deletions(-) diff --git a/cypress/fixtures/luma/selectors/cart.json b/cypress/fixtures/luma/selectors/cart.json index 473d582..8cff5f2 100644 --- a/cypress/fixtures/luma/selectors/cart.json +++ b/cypress/fixtures/luma/selectors/cart.json @@ -1,25 +1,21 @@ { - "url": { - "cartUrl": "checkout/cart/", - "product1Url": "/didi-sport-watch.html", - "product2Url": "/affirm-water-bottle.html" - }, - "product": { - "addToCartButton": "#product-addtocart-button", - "messageToast": "div.message-success", - "productPrice": ".price" - }, - "cartSummaryTable": ".totals .title", - "qtyInputField": ".input-text.qty", - "deleteProductButton": ".cart.item .action.action-delete", - "emptyCartTextField": ".cart-empty", - "couponCode": "H20", - "couponDropdownSelector": "#block-discount > .title", - "couponInputField": "#coupon_code", - "addCouponButton": "#block-discount .action.apply.primary", - "messageToast": ".message-error", - "product1Price": ".price", - "product1Subtotal": ":nth-child(3) > .md\\:justify-end > .sm\\:items-center > .flex > .block > span", - "product2Subtotal": ":nth-child(4) > .md\\:justify-end > .sm\\:items-center > .flex > .block > span", - "grandTotal": ".py-2 > .w-5\\/12" + "cartUrl": "checkout/cart/", + "product": { + "addToCartButton": "#product-addtocart-button", + "messageToast": "div.message-success", + "productPrice": ".price" + }, + "cartSummaryTable": ".totals .title", + "qtyInputField": ".input-text.qty", + "deleteProductButton": ".cart.item .action.action-delete", + "emptyCartTextField": ".cart-empty", + "couponCode": "H20", + "couponDropdownSelector": "#block-discount > .title", + "couponInputField": "#coupon_code", + "addCouponButton": "#block-discount .action.apply.primary", + "messageToast": ".message-error", + "product1Price": ".price", + "product1Subtotal": ":nth-child(3) > .md\\:justify-end > .sm\\:items-center > .flex > .block > span", + "product2Subtotal": ":nth-child(4) > .md\\:justify-end > .sm\\:items-center > .flex > .block > span", + "grandTotal": ".py-2 > .w-5\\/12" } diff --git a/cypress/integration/luma/cart/cart.spec.js b/cypress/integration/luma/cart/cart.spec.js index 7063871..670157f 100644 --- a/cypress/integration/luma/cart/cart.spec.js +++ b/cypress/integration/luma/cart/cart.spec.js @@ -1,23 +1,24 @@ -import { Cart } from '../../../page-objects/luma/cart'; +import {Cart} from '../../../page-objects/luma/cart'; import cartLuma from '../../../fixtures/luma/selectors/cart'; +import productLuma from '../../../fixtures/luma/product.json'; +import {Magento2RestApi} from '../../../support/magento2-rest-api' +import {shouldHaveErrorMessage, shouldHaveSuccessMessage} from '../../../support/utils' describe('Isolated test for adding a product to the cart', () => { it('Can add a product to the cart', () => { - Cart.addProductToCart(cartLuma.url.product1Url); - cy.get(cartLuma.product.messageToast) - .should( - 'include.text', - 'You added Didi Sport Watch to your shopping cart.' - ) - .should('be.visible'); + Cart.addProductToCart(productLuma.simpleProductUrl); + shouldHaveSuccessMessage(`You added ${productLuma.simpleProductName} to your shopping cart.`) }); }); describe('Cart tests', () => { beforeEach(() => { - Cart.addProductToCart(cartLuma.url.product1Url); - cy.visit(cartLuma.url.cartUrl); - cy.wait(3000); + cy.intercept('**/rest/*/V1/guest-carts/*/totals-information') + .as('totalsInformation') + + Cart.addProductToCart(productLuma.simpleProductUrl); + cy.visit(cartLuma.cartUrl); + cy.wait('@totalsInformation') }); it('Can change the quantity in the cart', () => { @@ -34,22 +35,17 @@ describe('Cart tests', () => { }); it('Can add a coupon to the cart', () => { - Cart.addProductToCart(cartLuma.url.product2Url); - Cart.addCouponCode(); - cy.get(cartLuma.cartSummaryTable) - .should('include.text', 'Discount') - .should('be.visible'); + Magento2RestApi.createRandomCouponCode() + .then(coupon => { + Cart.addCouponCode(coupon) + cy.get(cartLuma.cartSummaryTable) + .should('include.text', 'Discount') + .should('be.visible') + }) }); - it('cannot add a non existing coupon', () => { - cy.get(cartLuma.couponDropdownSelector).click(); - cy.get(cartLuma.couponInputField).type('wrong coupon code'); - cy.get(cartLuma.addCouponButton).click(); - cy.get(cartLuma.messageToast) - .should( - 'include.text', - 'The coupon code "wrong coupon code" is not valid.' - ) - .should('be.visible'); + it('Cannot add a non existing coupon', () => { + Cart.addCouponCode('wrong coupon code') + shouldHaveErrorMessage('The coupon code "wrong coupon code" is not valid.') }); }); From ca13e1b8174a598cc163b8ce12295d688bdfb547 Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 10:57:07 +0200 Subject: [PATCH 02/17] chore: refactor minicart tests --- .../integration/luma/cart/minicart.spec.js | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/cypress/integration/luma/cart/minicart.spec.js b/cypress/integration/luma/cart/minicart.spec.js index 92f41b5..21215b7 100644 --- a/cypress/integration/luma/cart/minicart.spec.js +++ b/cypress/integration/luma/cart/minicart.spec.js @@ -1,15 +1,15 @@ -import minicart from "../../../fixtures/minicart" -import selectors from "../../../fixtures/luma/selectors/minicart" +import selectors from '../../../fixtures/luma/selectors/minicart' +import product from '../../../fixtures/luma/product' +import {Cart} from '../../../page-objects/luma/cart' +import {shouldHavePageTitle, shouldHaveSuccessMessage} from '../../../support/utils' describe('Mini cart tests', () => { beforeEach(() => { cy.removeLocalStorage(); cy.clearCookies(); - cy.visit(minicart.didiSportWatch) - cy.get(selectors.addToCartButton).click() - cy.wait(5000) + Cart.addProductToCart(product.simpleProductUrl); + shouldHaveSuccessMessage(`You added ${product.simpleProductName} to your shopping cart.`) cy.get(selectors.miniCartButton).click() - cy.wait(2000) }) it('Can delete an item from the cart slider', () => { @@ -28,22 +28,18 @@ describe('Mini cart tests', () => { }) }) - it('can navigate to the cart with a link in the mini-cart', () => { + it('Can navigate to the cart with a link in the mini-cart', () => { cy.get(selectors.miniCartViewCartLink).click() - cy.get(selectors.pageTitle).should('contain.text', 'Shopping Cart').should('be.visible') + shouldHavePageTitle('Shopping Cart') }) - it('can navigate to the checkout with a link in the slider', () => { + it('Can navigate to the checkout with a link in the slider', () => { cy.get(selectors.miniCartCheckoutButton).click() - cy.url().should('contain', 'checkout') + cy.url() + .should('contain', 'checkout') }) -}) -describe('Test without added product', () => { it('Can check if the items and prices in the slider are displayed correctly', () => { - cy.visit(minicart.waterBottle) - cy.get(selectors.addToCartButton).click() - cy.wait(5000) cy.get(selectors.productPrice).then(($productPrice) => { cy.get(selectors.miniCartButton).click() const productPrice = $productPrice[0].textContent.trim() @@ -53,12 +49,11 @@ describe('Test without added product', () => { cy.get(selectors.firstProductAmount).invoke('data', 'item-qty').then(($qty) => { const qty = $qty cy.get(selectors.miniCartSubtotal).then(($total) => { - const total = parseInt($total[0].textContent.trim().slice(1)) + const total = parseFloat($total[0].textContent.trim().slice(1)) cy.get(selectors.miniCartFirstProductPrice).then(($productPriceMiniCart) => { const productPriceMiniCart = $productPriceMiniCart[0].textContent.trim().slice(1) console.log(productPriceMiniCart, '$productPriceMiniCart') const subTotal = (parseFloat(productPriceMiniCart) * parseFloat(qty)) - cy.log(subTotal) expect(subTotal).to.equal(total) }) }) From 03f84c956175b275a0948011552e51b924218a5f Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:00:24 +0200 Subject: [PATCH 03/17] chore: refactor category tests --- cypress/fixtures/category.json | 2 + cypress/fixtures/luma/selectors/category.json | 5 ++- .../luma/products/category.spec.js | 45 ++++++++++--------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/cypress/fixtures/category.json b/cypress/fixtures/category.json index 0bf9954..d589aff 100644 --- a/cypress/fixtures/category.json +++ b/cypress/fixtures/category.json @@ -2,5 +2,7 @@ "categoryUrl": "/women/tops-women.html", "category": "Women", "subCategory": "Tops", + "filterBy": "Color", + "filterQueryParam": "color", "selectByPrice": "Price" } diff --git a/cypress/fixtures/luma/selectors/category.json b/cypress/fixtures/luma/selectors/category.json index 0f61a59..0a8723a 100644 --- a/cypress/fixtures/luma/selectors/category.json +++ b/cypress/fixtures/luma/selectors/category.json @@ -12,5 +12,8 @@ "viewToggle": "#mode-list", "pageNavigation": "ul.pages-items li", "pageLink": "a.page", - "secondPageItem": "ul.pages-items > li:nth-child(3) > .page" + "secondPageItem": "ul.pages-items > li:nth-child(3) > .page", + "filterTitle": ".filter-options-title", + "filterOption": ".filter-options-filter", + "filterByLabel": ".filter-options-content ol.items > li:nth-child(1) > a > label" } diff --git a/cypress/integration/luma/products/category.spec.js b/cypress/integration/luma/products/category.spec.js index 237f107..4f80ac1 100644 --- a/cypress/integration/luma/products/category.spec.js +++ b/cypress/integration/luma/products/category.spec.js @@ -1,37 +1,42 @@ -import {Product} from "../../../page-objects/product"; - -import product from '../../../fixtures/luma/product' +import category from '../../../fixtures/category' import selectors from '../../../fixtures/luma/selectors/category' -import {isMobile} from "../../../support/utils"; +import {isMobile} from '../../../support/utils' describe('Category page tests', () => { beforeEach(() => { - cy.visit(Product.routes.category) - cy.wait(3000) + cy.visit(category.categoryUrl) + cy.get('#page-title-heading .base') + .should('contain.text', category.category) }) - it('Can visit the category page and filters on color red', () => { - if(isMobile()) { + it(`Can visit the category page and filters on ${category.filterBy}`, () => { + if (isMobile()) { cy.contains('Shop By').click() } - cy.contains('.filter-options-title', 'Color').click() - cy.get(selectors.selectColorRed).click({force: true}) - cy.url().should('contain', '?color=') + cy.contains(selectors.filterTitle, category.filterBy) + .should('exist') + cy.get(selectors.filterOption) + .contains(category.filterBy) + .get(selectors.filterByLabel) + .first() + .click({force: true}) // Only visible when hovering + cy.url() + .should('contain', `?${category.filterQueryParam}=`) }) it('Can sort products on price from lowest to highest', () => { - cy.get(selectors.sortBySelect).first().select(product.selectByPrice); + cy.get(selectors.sortBySelect).first().select(category.selectByPrice); cy.get(selectors.productPriceDataAtt).eq(0).invoke('data', 'price-amount') .then((firstPrice) => { - cy.get(selectors.productPriceDataAtt).eq(1).invoke('data', 'price-amount') - .then((secondPrice) => { - expect(firstPrice).to.be.lessThan(secondPrice); - }); + cy.get(selectors.productPriceDataAtt) + .eq(1) + .invoke('data', 'price-amount') + .should('be.lte', firstPrice) }); }) it('Can change the number of products to be displayed', () => { - cy.get(selectors.highestNumberOfProductsShowOption).find('option').last().invoke('val') + cy.get(selectors.highestNumberOfProductsShowOption).find('option').eq(1).invoke('val') .then((numberOfProducts) => { cy.get(selectors.numberOfProductsSelect).select(numberOfProducts, {force: true}); cy.get(selectors.numberOfShownItems).first().should('have.text', numberOfProducts); @@ -42,12 +47,12 @@ describe('Category page tests', () => { it('Can see the correct breadcrumbs', () => { cy.get(selectors.breadcrumbsItem).first().should('contain.text', 'Home') - cy.get(selectors.breadcrumbsItem).eq(1).should('contain.text', `${product.category}`) - cy.get(selectors.breadcrumbsItem).eq(2).should('contain.text', `${product.subCategory}`) + cy.get(selectors.breadcrumbsItem).eq(1).should('contain.text', 'Products') + cy.get(selectors.breadcrumbsItem).eq(2).should('contain.text', category.category) }) if(!isMobile()) { - it('Can switch between list and crid view', () => { + it('Can switch between list and grid view', () => { cy.get(selectors.categoryProductGridWrapper).should('be.visible') cy.get(selectors.viewToggle).click() cy.get(selectors.categoryProductListWrapper).should('be.visible') From 30e94d9b8b736f492a517e2c3f686080d1f2960b Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:01:52 +0200 Subject: [PATCH 04/17] chore: refactor product tests --- .../integration/luma/products/product.spec.js | 81 +++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/cypress/integration/luma/products/product.spec.js b/cypress/integration/luma/products/product.spec.js index b64d363..ea46687 100644 --- a/cypress/integration/luma/products/product.spec.js +++ b/cypress/integration/luma/products/product.spec.js @@ -1,13 +1,14 @@ -import {Account} from "../../../page-objects/luma/account" - -import product from "../../../fixtures/luma/product" -import account from "../../../fixtures/account" -import selectors from "../../../fixtures/luma/selectors/product" +import product from '../../../fixtures/luma/product' +import selectors from '../../../fixtures/luma/selectors/product' +import checkout from '../../../fixtures/checkout' +import {shouldHaveErrorMessage, shouldHaveSuccessMessage} from '../../../support/utils' describe('Simple Product test suite', () => { beforeEach(() => { + cy.intercept('**/customer/section/load/?sections=*') + .as('loadSections') cy.visit(product.simpleProductUrl) - cy.wait(2000) + cy.wait('@loadSections') }) it('Can see a title and image for the product', () => { @@ -31,8 +32,7 @@ describe('Simple Product test suite', () => { it('Can add a product to the cart from the product page', () => { cy.get(selectors.addToCartButton).click() - cy.get(selectors.successMessage) - .contains(`You added ${product.simpleProductName} to your shopping cart.`) + shouldHaveSuccessMessage(`You added ${product.simpleProductName} to your shopping cart.`) // Requires a wait for the product count to update cy.wait(1000) cy.get('.showcart').click() @@ -52,25 +52,10 @@ describe('Simple Product test suite', () => { }) it('Can\'t add a product to a wishlist when the user in not logged in', () => { - cy.get(selectors.addToWishlistButtonGuest).click() - cy.wait(2000) - cy.get(selectors.errorMessage) - .should('exist') - .should("contain.text", 'You must login or register to add items to your wishlist.') - }) - - it('Can add a product to the wishlist when customer is logged in', () => { - const customerMail = Date.now() + account.customer.customer.email - cy.visit(account.routes.accountCreate) - Account.createNewCustomer(account.customer.customer.firstname, account.customer.customer.lastname, customerMail, account.customer.password) - cy.visit(product.simpleProductUrl) - cy.wait(3000) - cy.get(selectors.addToWishlistButton).click().then(() => { - cy.wait(3000) - cy.get(selectors.successMessage) - .should('include.text', `${product.simpleProductName} has been added to your Wish List.`) - .should('be.visible') - }) + cy.get(selectors.addToWishlistButtonGuest) + .first() + .click() + shouldHaveErrorMessage('You must login or register to add items to your wishlist.') }) it('Can see product review score and the individual reviews', () => { @@ -115,27 +100,28 @@ describe('Simple Product test suite', () => { .should('contain.text', 'In stock') }) - it('Can increment the product quantity on the pdp', () => { + it('Can increment the product quantity on the product detail page', () => { cy.get(selectors.productQty) .type('{uparrow}') .should('have.value', '2') }) -}) - -describe('Configurable products test suite', () => { - beforeEach(() => { - cy.visit(product.configurableProductUrl) - cy.wait(1000) - }) - it('can find products in the related products list', () => { - // Configurable product has related products + it('Can find products in the related products list', () => { cy.get(selectors.relatedProductsTitle) .should('exist') .should('contain.text', 'Related Products') cy.get(selectors.relatedProductsCard) .should('have.length.gte', 3) }) +}) + +describe('Configurable products test suite', () => { + beforeEach(() => { + cy.intercept('**/customer/section/load/?sections=*') + .as('loadSections') + cy.visit(product.configurableProductUrl) + cy.wait('@loadSections') + }) it('Can\'t add a configurable product to the cart when no configuration is selected', () => { cy.get(selectors.addToCartButton) @@ -144,16 +130,27 @@ describe('Configurable products test suite', () => { .should('exist') }) - it('Can select product attributes', () => { - cy.get(selectors.productAttributeSelector) + it('Can select swatch product attributes', () => { + cy.get(selectors.productSwatchAttributeSelector) .eq(0).find('div').first().click() - cy.get(selectors.productAttributeSelector) + cy.get(selectors.productSwatchAttributeSelector) .eq(0).find('div').first() .should('have.class', 'selected') - cy.get(selectors.productAttributeSelector) + cy.get(selectors.productSwatchAttributeSelector) .eq(1).find('div').first().click() - cy.get(selectors.productAttributeSelector) + cy.get(selectors.productSwatchAttributeSelector) .eq(1).find('div').first() .should('have.class', 'selected') }) + + it('Can select product options', () => { + cy.get('#product-options-wrapper .field.configurable select') + .first() + .select(product.configurableOption) + cy.get(selectors.addToCartButton).click() + shouldHaveSuccessMessage(`You added ${product.configurableProductName} to your shopping cart.`) + cy.visit(checkout.cartUrl) + cy.get('#shopping-cart-table') + .should('contain.text', product.configurableOption) + }) }) From 101438679ce4ea9cbaa99c972ae40238f0c1caf6 Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:03:46 +0200 Subject: [PATCH 05/17] chore: refactor product search tests --- cypress/fixtures/luma/search.json | 4 +- .../luma/search/product-searches.spec.js | 57 ++++++++++++------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/cypress/fixtures/luma/search.json b/cypress/fixtures/luma/search.json index 0ed7727..b4f8d5f 100644 --- a/cypress/fixtures/luma/search.json +++ b/cypress/fixtures/luma/search.json @@ -1,7 +1,5 @@ { - "productCategory": "hoodie", - "singleProduct": "Didi", - "singleProductName": "Didi Sport Watch", + "searchTerm": "Didi", "noResults": "1234abcd", "getHint": "didi", "hintResult": "Didi" diff --git a/cypress/integration/luma/search/product-searches.spec.js b/cypress/integration/luma/search/product-searches.spec.js index 9676705..e6a6d3b 100644 --- a/cypress/integration/luma/search/product-searches.spec.js +++ b/cypress/integration/luma/search/product-searches.spec.js @@ -1,46 +1,59 @@ -import { Search } from "../../../page-objects/luma/search" -import searchLuma from "../../../fixtures/luma/search" -import selectorsLuma from "../../../fixtures/luma/selectors/search" -import {isMobile} from "../../../support/utils"; - +import {Search} from '../../../page-objects/luma/search' +import searchLuma from '../../../fixtures/luma/search' +import selectors from '../../../fixtures/luma/selectors/search' +import product from '../../../fixtures/luma/product' +import {isMobile} from '../../../support/utils' +import homepage from '../../../fixtures/luma/homepage.json' describe('Perform searches', () => { beforeEach(() => { - cy.visit('/') + cy.visit(homepage.homePageUrl) + }) + + it('Can perform search from the homepage', () => { + if(isMobile()) { + cy.get(selectors.headerSearchIcon).click() + } + cy.get(selectors.headerSearchIcon) + .should('be.visible') + .type(`${product.simpleProductName}{enter}`) + cy.get(selectors.pageHeader) + .should('contain.text', product.simpleProductName) }) it('Can perform search with multiple hits', () => { - Search.search(searchLuma.productCategory) - cy.get(selectorsLuma.pageHeader) - .should('have.text', `Search results for: '${searchLuma.productCategory}'`) + Search.search(searchLuma.searchTerm) + cy.get(selectors.pageHeader) + .should('have.text', `Search results for: '${searchLuma.searchTerm}'`) + cy.get(`${selectors.resultContainer} ${selectors.resultItem}`) + .should('have.length.gt', 0) }) it('Can find a single product', () => { - Search.search(searchLuma.singleProduct) - cy.get(selectorsLuma.toolbarNumber) - .should('be.visible') - .should('contain.text', '1') + Search.search(product.simpleProductName) + cy.get(selectors.resultContainer) + .should('contain.text', product.simpleProductName) }) it('Can perform search with no search results', () => { Search.search(searchLuma.noResults) - cy.get(selectorsLuma.pageHeader) + cy.get(selectors.pageHeader) .should('be.visible') - .should("contain.text", `Search results for: '${searchLuma.noResults}'`) - cy.get(selectorsLuma.noResultsMessage) + .should('contain.text', `Search results for: '${searchLuma.noResults}'`) + cy.get(selectors.noResultsMessage) .should('be.visible') .should('contain.text', 'Your search returned no results.') }) it('Can see suggestions when entering search terms', () => { - if(isMobile()) { - cy.get(selectorsLuma.headerSearchIconMobile).click() + if (isMobile()) { + cy.get(selectors.headerSearchIconMobile).click() } - cy.get(selectorsLuma.headerSearchIcon).click() - cy.get(selectorsLuma.headerSearchField) + cy.get(selectors.headerSearchIcon).click() + cy.get(selectors.headerSearchField) .should('be.visible') - .type(`${searchLuma.getHint}`) - cy.get(selectorsLuma.searchSuggestions) + .type(`${searchLuma.searchTerm}`) + cy.get(selectors.searchSuggestions) .should('be.visible') .should('contain.text', searchLuma.hintResult) }) From fb9426a8eb44123b2bbbffaa41dc08349e137c96 Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:05:21 +0200 Subject: [PATCH 06/17] chore: refactor account tests --- cypress/integration/luma/user/account.spec.js | 133 ++++++++---------- 1 file changed, 60 insertions(+), 73 deletions(-) diff --git a/cypress/integration/luma/user/account.spec.js b/cypress/integration/luma/user/account.spec.js index 8b63421..9901089 100644 --- a/cypress/integration/luma/user/account.spec.js +++ b/cypress/integration/luma/user/account.spec.js @@ -1,50 +1,22 @@ import {Account} from '../../../page-objects/luma/account' -import {Magento2RestApi} from '../../../support/magento2-rest-api' import account from '../../../fixtures/account' import product from '../../../fixtures/luma/product' import checkout from '../../../fixtures/checkout' import selectorsLuma from '../../../fixtures/luma/selectors/account' import checkoutSelectors from '../../../fixtures/luma/selectors/checkout' -import {isMobile} from "../../../support/utils"; +import {shouldHaveSuccessMessage} from '../../../support/utils' describe('Account test creation', () => { it('Can create an account', () => { cy.visit(account.routes.accountCreate) Account.createNewCustomer(account.customer.customer.firstname, account.customer.customer.lastname, Date.now() + account.customer.customer.email, account.customer.password) - cy.contains('Thank you for registering with Main Website Store.').should('exist') - cy.wait(2000) - Account.logout() + cy.contains('Thank you for registering with').should('exist') }) }) describe('Account activities', () => { beforeEach(() => { - cy.wait(2500) - }) - - before(() => { - cy.wait(2500) - Magento2RestApi.createCustomerAccount(account.customer) - Account.login(account.customer.customer.email, account.customer.password) - Account.createAddress(account.customerInfo) - // We need to logout or the beforeEach will fail - if(isMobile()) { - cy.wait(2000) - } - cy.wait(2500) - }) - - after(() => { - // Remove the added address - cy.wait(2500) - Account.login(account.customer.customer.email, account.customer.password) - cy.visit('/customer/address') - cy.wait(4000) - cy.get('.additional-addresses a.delete').eq(0).click({force: true}) - cy.wait(1000) - cy.get('.modal-content').contains('Are you sure you want to delete this address?') - cy.get('.action-primary').click() - cy.wait(2500) + Account.ensureLoggedIn(account.customer.customer.email, account.customer.password) }) it('Can check your profile', () => { @@ -68,12 +40,10 @@ describe('Account activities', () => { }) it('Can change the profile values', () => { - Account.login(account.customer.customer.email, account.customer.password) let fn = account.tempCustomerInfo.firstname, ln = account.tempCustomerInfo.lastname cy.visit(account.routes.accountEdit) Account.changeProfileValues(account.tempCustomerInfo.firstname, account.tempCustomerInfo.lastname) - cy.wait(4000) Account.goToProfile() cy.get(selectorsLuma.accountFirstnameInputSelector).should('have.value', fn) cy.get(selectorsLuma.accountLastnameInputSelector).should('have.value', ln) @@ -102,61 +72,76 @@ describe('Account activities', () => { }) it('Can add an address', () => { - cy.visit(account.routes.accountAddAddress) - Account.createAddress(account.customerInfo) - cy.wait(2000) - cy.contains(selectorsLuma.addNewAddressButton, 'Add New Address').click() - cy.get(selectorsLuma.newAddressStreetInput).type(account.customerInfo.streetAddress) - cy.get(selectorsLuma.newAddressCityInput).type(account.customerInfo.city) - cy.get(selectorsLuma.newAddressTelInput).type(account.customerInfo.phone) - cy.get(selectorsLuma.newAddressZipcodeInput).type(account.customerInfo.zip) - cy.get(selectorsLuma.newAddressCountryInput).select(account.customerInfo.country) - cy.contains('Save Address').click() + cy.visit(account.routes.accountAddresses) + cy.wait(5000) // For whatever reason, clicks on the damn button don't work until all the things™ are loaded. + cy.get(selectorsLuma.addNewAddressButton) + .contains('Add New Address') + .click() + cy.get('h1.page-title') + .contains('Add New Address') + .should('exist') + Account.createAddress(account.customerInfo, false) }) it('Can change an address', () => { + cy.intercept('**/customer/section/load/?*') + .as('stateRequest') + + Account.createAddress(account.customerInfo, false) + const timeStamp = Date.now().toString() cy.visit(account.routes.accountAddresses) cy.get(selectorsLuma.editAddress).first().click() - cy.get(selectorsLuma.addressEditStreetInput).eq(0).type(timeStamp) + cy.get(selectorsLuma.addressEditStreetInput).eq(0).type(timeStamp + 'street') + cy.wait('@stateRequest') cy.get(selectorsLuma.saveAddressButton).contains('Save Address').click() cy.contains('You saved the address.').should('exist') }) it('Can add an address automatically from saved address', () => { + Account.createAddress(account.customerInfo) // There needs to be an item in the cart for this to work, and there needs to be a saved address cy.visit(product.simpleProductUrl) cy.contains('Add to Cart').click() - cy.wait(3000) cy.visit(checkout.checkoutUrl) + // TODO: Replace with cy.intercept cy.wait(7000) // this shouldn't be needed but for some reason it doesn't work without cy.get('.shipping-address-item.selected-item').should('have.length', 1) }) it('Can remove an address', () => { - Account.login(account.customer.customer.email, account.customer.password) Account.createAddress(account.customerInfo) - cy.visit(account.routes.accountAddresses) - cy.wait(4000) - cy.get(selectorsLuma.deleteAddressButton).eq(0).click({force: true}) - // An confirm alert pops up asking if you are sure - cy.contains('.modal-content', 'Are you sure you want to delete this address?') - cy.get('.action-primary').click() - cy.contains('You deleted the address.').should('exist') + cy.visit('/customer/address') + // For some reason, the delete button is only clickable after a while. + // It looks like this is not related to any xhr request happening so cy.intercept won't do any good. + cy.wait(1000) + cy.get('.additional-addresses a.delete') + .first() + .click() + cy.get('.modal-content').contains('Are you sure you want to delete this address?') + cy.get('.action-primary') + .first() + .click() }) it('Can change the newsletter subscription', () => { - Account.login(account.customer.customer.email, account.customer.password) cy.visit(account.routes.manageNewsletter) cy.contains('General Subscription') cy.get('#subscription').should('be.checked') }) - it('Can add a product the a wishlist', () => { + it('Can add a product to the wishlist', () => { + cy.intercept('**/customer/section/load/?*') + .as('stateRequest') + cy.visit(product.simpleProductUrl) - cy.wait(2000) - cy.get(selectorsLuma.addToWishlistButton).eq(0).click({force: true}) - cy.get(selectorsLuma.wishlistTitle).should('contain.text', 'My Wish List').should('exist') + cy.wait('@stateRequest') + cy.contains('Add to Wish List') + .click() + shouldHaveSuccessMessage('has been added to your Wish List') + cy.get(selectorsLuma.wishlistTitle) + .should('contain.text', 'My Wish List') + .should('exist') cy.visit(account.routes.wishlist).then(() => { cy.get('.toolbar-number').should('exist') cy.contains(product.simpleProductName).should('exist') @@ -164,16 +149,15 @@ describe('Account activities', () => { }) it('Can log out', () => { - cy.get(selectorsLuma.accountIcon).click({force: true}) - cy.get(selectorsLuma.accountMenu).contains('Sign Out').click({force: true}) - cy.get(selectorsLuma.signedOutHeader).should('contain.text', 'You are signed out') + cy.visit(account.routes.accountUrl) cy.wait(2000) + Account.logout() }) }) describe('Guest user test', () => { beforeEach(() => { - cy.wait(2500) + Account.ensureLoggedOut() }) it('Can login from cart', () => { @@ -187,23 +171,26 @@ describe('Guest user test', () => { // If the login fails the test will still pass without this line cy.get(selectorsLuma.messageContents).should('not.exist') cy.get(checkoutSelectors.miniCartIcon).click() - cy.get(checkoutSelectors.productQuantityField).and(($input) => { - // Could pass when I should fail? - expect($input[0].valueAsNumber).to.be.at.least(1) - }) + cy.get('#minicart-content-wrapper') + .should('contain.text', 'Cart Subtotal') cy.contains(product.simpleProductName).should('exist') }) it('Can login from checkout', () => { + cy.intercept('**/rest/*/V1/customers/isEmailAvailable') + .as('emailAvailable') + cy.intercept('**/rest/*/V1/guest-carts/*/estimate-shipping-methods') + .as('estimateShipping') + cy.visit(product.simpleProductUrl) - cy.wait(4000) - cy.get(checkoutSelectors.addToCartButton).should('contain.text', 'Add to Cart').click() + cy.get(checkoutSelectors.addToCartButton) + .contains( 'Add to Cart') + .click() cy.visit(checkout.checkoutUrl) - cy.wait(5000) + cy.wait('@estimateShipping') cy.get(checkoutSelectors.checkoutEmailLabel).type(account.customer.customer.email) - cy.wait(4000) - cy.get(checkoutSelectors.checkoutPasswordLabel).type(account.customer.password) - cy.wait(1000) - cy.get('button[data-action="checkout-method-login"]').click() + cy.wait('@emailAvailable') + cy.get('.billing-address-form') + .should('contain.text', 'You already have an account with us. Sign in or continue as guest.') }) }) From 8feab5e4c882d76e6cbc5e94f57788b2c235a5e5 Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:06:18 +0200 Subject: [PATCH 07/17] chore: refactor home page test --- cypress/integration/luma/homepage.spec.js | 28 ++++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/cypress/integration/luma/homepage.spec.js b/cypress/integration/luma/homepage.spec.js index 6ee6e9c..e47acc6 100644 --- a/cypress/integration/luma/homepage.spec.js +++ b/cypress/integration/luma/homepage.spec.js @@ -1,8 +1,8 @@ -import homepage from "../../fixtures/luma/homepage" -import selectors from "../../fixtures/selectors/luma/homepage" -import product from "../../fixtures/luma/product" -import account from "../../fixtures/account" -import {isMobile} from "../../support/utils"; +import homepage from '../../fixtures/luma/homepage' +import selectors from '../../fixtures/luma/selectors/homepage' +import globalSelectors from '../../fixtures/globalSelectors' +import account from '../../fixtures/account' +import {shouldHaveErrorMessage, shouldHaveSuccessMessage} from '../../support/utils' describe('Home page tests', () => { beforeEach(() => { @@ -16,19 +16,9 @@ describe('Home page tests', () => { .should('have.length.gte', 1) }) - it('Can perform search from homepage', () => { - if(isMobile()) { - cy.get(selectors.searchIconMobile).click() - } - cy.get(selectors.searchIcon) - .should('be.visible') - .type(`${product.simpleProductName}{enter}`) - cy.get(selectors.mainHeading) - .should('contain.text', product.simpleProductName) - }) - it('Can open category', () => { cy.get(selectors.headerNavSubCategory) + .first() .click({force: true}) cy.get(selectors.mainHeading) .should('contain.text', homepage.subCategoryName) @@ -39,10 +29,10 @@ describe('Home page tests', () => { cy.get(selectors.newsletterSubscribeButton).click() cy.wait(2000) cy.get('.page.messages').then(($messageSection) => { - if (!$messageSection.find(selectors.failedMessage).text().trim()) { - cy.get(selectors.successMessage).should('contain.text', homepage.subscriptionSuccess) + if (!$messageSection.find(globalSelectors.errorMessage).text().trim()) { + shouldHaveSuccessMessage(homepage.subscriptionSuccess) } else { - cy.get(selectors.failedMessage).should('contain.text', homepage.subscriptionFail) + shouldHaveErrorMessage(homepage.subscriptionFail) } }) }) From a572fd294718e9f1a3e1034daaf6f3c6cff29c9b Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:10:01 +0200 Subject: [PATCH 08/17] chore: refactor checkout test --- cypress/fixtures/luma/selectors/checkout.json | 92 +++--- .../luma/checkout/checkout.spec.js | 281 +++++++++++++++--- 2 files changed, 272 insertions(+), 101 deletions(-) diff --git a/cypress/fixtures/luma/selectors/checkout.json b/cypress/fixtures/luma/selectors/checkout.json index 470be67..df517c6 100644 --- a/cypress/fixtures/luma/selectors/checkout.json +++ b/cypress/fixtures/luma/selectors/checkout.json @@ -1,58 +1,38 @@ { - "companyField": "#shipping-new-address-form [name=\"company\"]", - "customerEmailField": "#customer-email", - "firstNameField": "#shipping-new-address-form [name=\"firstname\"]", - "lastNameField": "#shipping-new-address-form [name=\"lastname\"]", - "addressField": "#shipping-new-address-form [name=\"street[0]\"]", - "postCodeField": "#shipping-new-address-form [name=\"postcode\"]", - "cityField": "#shipping-new-address-form [name=\"city\"]", - "countryField": "#shipping-new-address-form [name=\"country_id\"]", - "regionField": "#shipping-new-address-form [name=\"region\"]", - "stateField": "", - "telephoneField": "#shipping-new-address-form [name=\"telephone\"]", - "saveAddressBtn": "#shipping_address div.flex.items-center > button", - "shippingMethodForm": "#shipping_method", - "shippingMethodField": "#shippingMethod_flatrate__flatrate", - "addToCartButton": "#product-addtocart-button", - "checkoutLoginToggle": "#login div.py-2 > div.py-3.text-sm.text-center.text-black.underline.cursor-pointer", - "checkoutEmailField": "#login.email", - "checkoutEmailLabel": "#customer-email", - "checkoutPasswordField": "#login.password", - "checkoutPasswordLabel": "#customer-password", - "checkoutLoginButton": "button[data-action=\"checkout-method-login\"]", - "checkoutLoggedInEmail": "#login div > span > span:nth-child(2)", - "openApplyDiscount": "div > div > div.text-left > span > span", - "couponField": "#coupon_code", - "applyDiscountButton": "#discount-coupon-form button", - "paymentForm": "#payment_method", - "moneyOrderPaymentMethodSelector": "#checkmo", - "placeOrderBtn": ".action.primary.checkout", - "addressSelectedSvg": "#shipping_address div:nth-child(1) > div.card div:nth-child(1) > svg", - "addressSelected": ".shipping-address-item.selected-item", - "addAddressButton": "#shipping_address div:nth-child(1) div.card + div > button", - "productPrice": ".price", - "cartPrice": ".cart-price .price", - "cartSummeryDiscount": ".totals .title", - "shippingMethodSelect": ".table-checkout-shipping-method .col-method input", - "submitShippingButton": "#shipping-method-buttons-container button", - "orderNumber": "#maincontent p:nth-child(1) > a > strong", - "cartSubtotalPrice": "#react-checkout div.sticky div.card div.pb-2.space-y-3 div:nth-child(2)", - "cartDiscountPrice": "#react-checkout div.sticky div.card div.pb-2.space-y-3.border-b > div:nth-child(3) > div:nth-child(2)", - "cartShippingPrice": "#react-checkout div.sticky div.card div.pb-2.space-y-3.border-b > div:nth-child(2) > div:nth-child(2)", - "cartTotalPrice": "#react-checkout div.sticky div.card div.pb-2 div:nth-child(2)", - "miniCartIcon": ".showcart", - "cartDrawerEditLink": ".action.viewcart", - "productQuantityField": ".input-text.qty", - "currency": "$", - "checkoutPrice": ".totals.sub .price", - "checkoutPriceMobile": ".estimated-price", - "checkoutShippingPrice": ".totals.shipping .price", - "totalPrice": ".grand.totals .price", - "checkoutDiscountPrice": ".totals.discount .price", - "cartDiscount": ":nth-child(2) > .amount", - "checkoutContainer": "#checkout", - "checkoutBtn": ".button.action.continue.primary", - "orderConfirmationOrderNumber": ".checkout-success strong", - "accountViewOrder": ".items > :nth-child(2) > a", - "orderHistoryOrderNumber": ".orders-history tbody > :nth-child(1) > .id" + "shippingContainer": "#shipping-new-address-form", + "billingContainer": ".billing-address-form form", + "companyField": "[name=\"company\"]", + "customerEmailField": "#customer-email", + "firstNameField": "[name=\"firstname\"]", + "lastNameField": "[name=\"lastname\"]", + "addressField": "[name=\"street[0]\"]", + "postCodeField": "[name=\"postcode\"]", + "cityField": "[name=\"city\"]", + "countryField": "[name=\"country_id\"]", + "regionField": "[name=\"region\"]", + "telephoneField": "[name=\"telephone\"]", + "emailValidationErrorField": "fieldset#customer-email-fieldset .control div[for=customer-email].mage-error", + "addToCartButton": "#product-addtocart-button", + "checkoutEmailLabel": "#customer-email", + "moneyOrderPaymentMethodSelector": "#checkmo", + "moneOrderAgreement1": "#agreement_checkmo_1", + "moneOrderAgreement2": "#agreement_checkmo_2", + "placeOrderBtn": ".payment-method-content .actions-toolbar .primary .action.primary.checkout", + "addressSelected": ".shipping-address-item.selected-item", + "productPrice": ".price", + "miniCartIcon": ".showcart", + "checkoutPrice": ".totals.sub .price", + "checkoutShippingPrice": ".totals.shipping .price", + "totalPrice": ".grand.totals .price", + "taxesPrice": ".table-totals .totals-tax-summary td .price", + "checkoutDiscountPrice": ".totals.discount .price", + "cartDiscount": ":nth-child(3) > .amount", + "checkoutBtn": ".button.action.continue.primary", + "orderConfirmationOrderNumber": ".checkout-success strong", + "checkoutSuccess": ".checkout-success", + "orderHistoryOrderNumber": ".orders-history tbody > :nth-child(1) > .id", + "proceedToCheckout": "button[data-role=\"proceed-to-checkout\"]", + "checkoutGuestCheckbox": "#checkout_method_guest", + "checkoutGuestContinue": "#newcustomer .actions-toolbar .primary .action.create.primary", + "sameBillingAsShipping": "label[for=billing-address-same-as-shipping]" } diff --git a/cypress/integration/luma/checkout/checkout.spec.js b/cypress/integration/luma/checkout/checkout.spec.js index 13d8910..136efc6 100644 --- a/cypress/integration/luma/checkout/checkout.spec.js +++ b/cypress/integration/luma/checkout/checkout.spec.js @@ -1,28 +1,98 @@ -import {Checkout} from "../../../page-objects/luma/checkout"; -import {Account} from "../../../page-objects/luma/account"; +import {Checkout} from '../../../page-objects/luma/checkout' +import {Account} from '../../../page-objects/luma/account' import account from '../../../fixtures/account' import product from '../../../fixtures/luma/product' import checkout from '../../../fixtures/checkout' import selectors from '../../../fixtures/luma/selectors/checkout' -import {isMobile} from "../../../support/utils"; +import {isMobile, shouldHavePageTitle, shouldHaveSuccessMessage} from '../../../support/utils' +import {Cart} from '../../../page-objects/luma/cart' +import {Magento2RestApi} from '../../../support/magento2-rest-api' +import cartLuma from '../../../fixtures/luma/selectors/cart' +import productLuma from '../../../fixtures/luma/product' +import minicart from '../../../fixtures/luma/selectors/minicart' +import global from '../../../fixtures/globalSelectors' + +function setupGuestCheckoutInterceptors() { + cy.intercept('**/customer/section/load/?sections=*') + .as('sectionLoad') + cy.intercept('**/rest/*/V1/guest-carts/*/estimate-shipping-methods') + .as('estimateShipping') + cy.intercept('**/rest/*/V1/guest-carts/*/totals-information') + .as('totalsInformation') + cy.intercept('**/rest/*/V1/customers/isEmailAvailable') + .as('emailAvailable') + cy.intercept('**/rest/*/V1/guest-carts/*/payment-information') + .as('paymentInformation') +} + +function chooseMoneyOrderPaymentAndPlaceOrder() { + cy.get(selectors.checkoutBtn).click() + cy.wait('@sectionLoad') + cy.get(selectors.moneyOrderPaymentMethodSelector).check({force: true}) + cy.get(selectors.moneyOrderPaymentMethodSelector).should('be.checked') + cy.get(selectors.moneOrderAgreement1).check() + cy.get(selectors.moneOrderAgreement2).check() +} + +function addProductToCartAndVerifyItWasAdded() { + Cart.addProductToCart(product.simpleProductUrl) + cy.wait('@sectionLoad') + shouldHaveSuccessMessage(`You added ${product.simpleProductName} to your shopping cart.`) +} + +function addAProductToCartAndEnterBillingAddressInCheckout() { + Cart.addProductToCart(product.simpleProductUrl) + cy.wait('@sectionLoad') + shouldHaveSuccessMessage(`You added ${product.simpleProductName} to your shopping cart.`) + cy.get(minicart.miniCartButton) + .click() + cy.get(minicart.miniCartViewCartLink) + .click() + cy.url() + .should('contain', checkout.cartUrl) + cy.wait('@sectionLoad') + cy.wait('@estimateShipping') + cy.wait('@totalsInformation') + cy.get(selectors.proceedToCheckout) + .click() + + cy.get(global.pageTitle) + .should('contain.text', 'Customer Login') + cy.get(selectors.checkoutGuestCheckbox) + .check({force: true}) + cy.wait(1000) // FIXME: This wait should not be nessecary + cy.get(selectors.checkoutGuestContinue) + .click() + + cy.wait('@estimateShipping') + Checkout.enterBillingAddress(checkout.billingAddress) + cy.wait('@emailAvailable') +} describe('Checkout tests', () => { it('Can see the correct product price and shipping costs', () => { - cy.visit(product.simpleProductUrl) - cy.get(selectors.addToCartButton).click() + setupGuestCheckoutInterceptors() + cy.intercept('**/rest/*/V1/carts/mine/shipping-information') + .as('shippingInformation') + + Cart.addProductToCart(product.simpleProductUrl) + cy.wait('@sectionLoad') + cy.get(selectors.productPrice).then(($PDPprice) => { - expect($PDPprice).to.be.contain(selectors.currency) + expect($PDPprice).to.be.contain(product.currency) const PDPPrice = $PDPprice[0].innerText.trim() - cy.wait(3000) + cy.visit(checkout.checkoutUrl) - cy.wait(5000) + cy.wait('@estimateShipping') Checkout.enterShippingAddress(checkout.shippingAddress) - cy.wait(3000) + cy.wait('@sectionLoad') cy.get('.button.action.continue.primary').click() - cy.wait(7000) - if(isMobile()) { + cy.wait('@sectionLoad') + + if (isMobile()) { cy.get('.action.showcart').click() } + cy.get(selectors.checkoutPrice).then(($checkoutPrice) => { const checkoutPrice = $checkoutPrice[0].innerText.trim() expect($checkoutPrice[0].innerText.trim()).to.equal(PDPPrice) @@ -30,7 +100,10 @@ describe('Checkout tests', () => { const shippingPrice = $shippingPrice[0].innerText.trim() cy.get(selectors.totalPrice).then(($totalPrice) => { const totalPrice = $totalPrice[0].innerText.trim().slice(1) - expect((parseFloat(checkoutPrice.slice(1))) + (parseFloat(shippingPrice.slice(1)))).to.equal(parseFloat(totalPrice)) + cy.get(selectors.taxesPrice).then($taxesPrice => { + const taxes = $taxesPrice[0].innerText.trim().slice(1) + expect(parseFloat(checkoutPrice.slice(1)) + parseFloat(shippingPrice.slice(1)) + parseFloat(taxes)).to.equal(parseFloat(totalPrice)) + }) }) }) }) @@ -38,48 +111,67 @@ describe('Checkout tests', () => { }) it('Can see coupon discount in checkout', () => { - Checkout.addProductToCart(product.couponProductUrl) - cy.wait(3000) - Checkout.addCoupon(product.couponCode) - cy.wait(5000) - cy.get(selectors.cartDiscount).then(($cartDiscount) => { - const cartDiscount = parseFloat($cartDiscount[0].innerText.trim().slice(2)) - cy.visit(checkout.checkoutUrl) - cy.wait(7000) - Checkout.enterShippingAddress(checkout.shippingAddress) - cy.wait(3000) - cy.get('.button.action.continue.primary').click() - cy.wait(10000) - if(isMobile()) { - cy.get('.action.showcart').click() - } - cy.get(selectors.checkoutDiscountPrice).then(($discount) => { - const discount = parseFloat($discount[0].innerText.trim().slice(2)) - expect(discount).to.equal(cartDiscount) + setupGuestCheckoutInterceptors() + + Cart.addProductToCart(productLuma.simpleProductUrl) + cy.visit(cartLuma.cartUrl) + cy.wait('@totalsInformation') + + Magento2RestApi.createRandomCouponCode() + .then(coupon => { + Cart.addCouponCode(coupon) + cy.wait('@estimateShipping') + cy.wait('@sectionLoad') + cy.get(cartLuma.cartSummaryTable) + .should('include.text', 'Discount') + .should('be.visible') + cy.get(selectors.cartDiscount).then(($cartDiscount) => { + const cartDiscount = parseFloat($cartDiscount.last().text().trim().slice(2)) + cy.visit(checkout.checkoutUrl) + cy.wait('@estimateShipping') + Checkout.enterBillingAddress(checkout.billingAddress) + cy.get('.button.action.continue.primary').click() + cy.wait('@sectionLoad') + cy.wait('@sectionLoad') + if (isMobile()) { + cy.get('.action.showcart').click() + } + cy.get(selectors.checkoutDiscountPrice).then(($discount) => { + const discount = parseFloat($discount[0].innerText.trim().slice(2)) + expect(discount).to.equal(cartDiscount) + }) + }) }) - }) }) - it('can find and order in the customer order history after having placed an order', () => { - cy.visit(product.simpleProductUrl) - cy.get(selectors.addToCartButton).click() - cy.wait(3000) + it('Can find and order in the customer order history after having placed an order', () => { + setupGuestCheckoutInterceptors() + cy.intercept('**/rest/*/V1/carts/mine/shipping-information') + .as('shippingInformation') + cy.intercept('**/rest/*/V1/carts/mine/payment-information') + .as('paymentInformation') + + Cart.addProductToCart(product.simpleProductUrl) + cy.wait('@sectionLoad') + shouldHaveSuccessMessage(`You added ${product.simpleProductName} to your shopping cart.`) Account.login(account.customer.customer.email, account.customer.password) + Account.createAddress(account.customerInfo) + cy.visit(checkout.checkoutUrl) - cy.wait(5000) + cy.wait('@sectionLoad') cy.get(selectors.addressSelected).should('exist') - cy.get(selectors.checkoutBtn).click() - cy.wait(4000) - cy.get(selectors.moneyOrderPaymentMethodSelector).check({force: true}) - cy.get(selectors.moneyOrderPaymentMethodSelector).should('be.checked') - cy.wait(3000) - cy.contains('Place Order').should('be.visible').click({force: true}) - cy.wait(7000) + + chooseMoneyOrderPaymentAndPlaceOrder() + cy.get(selectors.placeOrderBtn) + .last() + .should('be.visible') + .click() + cy.wait('@paymentInformation') + cy.get(selectors.orderConfirmationOrderNumber).then(($orderNr) => { const orderNr = $orderNr[0].innerText.trim() - cy.log(orderNr) cy.visit(checkout.orderHistoryUrl) - cy.wait(3000) + shouldHavePageTitle('My Orders') cy.get(selectors.orderHistoryOrderNumber).then(($orderHistoryOrderNr) => { const orderNrHistory = $orderHistoryOrderNr[0].innerText.trim() cy.log(orderNrHistory) @@ -87,4 +179,103 @@ describe('Checkout tests', () => { }) }) }) + + it('Can do a checkout as guest', () => { + setupGuestCheckoutInterceptors() + + addAProductToCartAndEnterBillingAddressInCheckout() + + chooseMoneyOrderPaymentAndPlaceOrder() + cy.get(selectors.placeOrderBtn) + .last() + .should('be.visible') + .click() + cy.wait('@paymentInformation') + + cy.get(selectors.checkoutSuccess) + .should('contain.text', 'Thank you for order!') + }) + + it('Can do a checkout as guest with a different shipping address', () => { + setupGuestCheckoutInterceptors() + + addAProductToCartAndEnterBillingAddressInCheckout() + + cy.get(selectors.sameBillingAsShipping) + .click() + Checkout.enterShippingAddress(checkout.shippingAddress) + + chooseMoneyOrderPaymentAndPlaceOrder() + + cy.get('.shipping-information .ship-to .shipping-information-content') + .should('contain.text', checkout.shippingAddress.companyname) + .should('contain.text', checkout.shippingAddress.firstname) + .should('contain.text', checkout.shippingAddress.lastname) + .should('contain.text', checkout.shippingAddress.street) + .should('contain.text', checkout.shippingAddress.city) + + cy.get(selectors.placeOrderBtn) + .last() + .should('be.visible') + .click() + cy.wait('@paymentInformation') + + cy.get(selectors.checkoutSuccess) + .should('contain.text', 'Thank you for order!') + }) + + it('Should add shipping costs again when the subtotal goes below free shipping threshhold', () => { + setupGuestCheckoutInterceptors() + + Cart.addProductToCart(productLuma.simpleProductUrl) + cy.visit(cartLuma.cartUrl) + cy.wait('@totalsInformation') + + cy.get(selectors.checkoutShippingPrice) + .should('contain.text', `${product.currency}0.00`) + + Magento2RestApi.createRandomCouponCode(80) + .then(coupon => { + Cart.addCouponCode(coupon) + cy.wait('@estimateShipping') + cy.wait('@sectionLoad') + cy.get(cartLuma.cartSummaryTable) + .should('include.text', 'Discount') + .should('be.visible') + cy.get(selectors.checkoutShippingPrice) + .should('not.contain.text', `${product.currency}0.00`) + }) + }) + + describe('Validate email address in checkout', () => { + beforeEach(() => { + setupGuestCheckoutInterceptors() + + addProductToCartAndVerifyItWasAdded() + + cy.visit(checkout.checkoutUrl) + cy.wait('@estimateShipping') + }) + + it('Enters a correct email address', () => { + cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`) + .type('john.doe@example.com') + }) + + it('Enters an incorrect email address', () => { + cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`) + .type('John') + .blur() + cy.get(selectors.emailValidationErrorField) + .should('contain.text', 'Please enter a valid email address') + }) + + it('Enters another incorrect email address', () => { + cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`) + .type('john.doe#example.com') + .blur() + cy.get(selectors.emailValidationErrorField) + .should('contain.text', 'Please enter a valid email address') + }) + }) }) From d867bf36236f873c2941abb417badd0bd1d58a18 Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:12:37 +0200 Subject: [PATCH 09/17] chore: refactor page objects --- cypress/fixtures/luma/selectors/account.json | 59 +++++++------------- cypress/page-objects/luma/account.js | 39 +++++++++---- cypress/page-objects/luma/cart.js | 23 ++++---- cypress/page-objects/luma/checkout.js | 33 +++++++---- 4 files changed, 81 insertions(+), 73 deletions(-) diff --git a/cypress/fixtures/luma/selectors/account.json b/cypress/fixtures/luma/selectors/account.json index e64a87a..f5ae105 100644 --- a/cypress/fixtures/luma/selectors/account.json +++ b/cypress/fixtures/luma/selectors/account.json @@ -1,42 +1,21 @@ { - "changePasswordFormSelector": "#form-validate", - "addAddressFormSelector": "#form-validate", - "accountFirstnameInputSelector": "#firstname", - "accountLastnameInputSelector": "#lastname", - "currentPasswordInputSelector": "#current-password", - "newPasswordInputSelector": "#password", - "newPasswordConfirmationInputSelector": "#password-confirmation", - "accountEmailInputSelector": "#email_address", - "loginEmailInputSelector": "#email", - "loginPasswordInputSelector": "#pass", - "myAccountHeaderSelector": "[data-ui-id=\"page-title-wrapper\"]", - "defaultBillingAddress": "#primary_billing", - "defaultShippingAddress": "#primary_shipping", - "editAddress": ".box-address-shipping > .box-actions > .action > span", - "addressEditStreetInput": "input[id^=\"street\"]", - "addNewAddressButton": ".action.primary.add", - "newAddressStreetInput": "#street_1", - "newAddressCityInput": "#city", - "newAddressTelInput": "#telephone", - "newAddressZipcodeInput": "#zip", - "newAddressCountryInput": "#country", - "newAddressBillingInput": "#primary_billing", - "newAddressShippingInput": "#primary_shipping", - "saveAddressButton": "button[data-action=\"save-address\"]", - "deleteAddressButton": ".additional-addresses a.delete", - "addToWishlistButton": "[data-action=\"add-to-wishlist\"]", - "wishlistItemCommentField": "[id^=\"product-item-comment\"]", - "wishlistQtyField": ".form-input.qty", - "wishlistUpdateButton": "#wishlist-view-form .update", - "wishlistShareButton": "button.share", - "wishlistShareTitle": "h1.page-title", - "wishlistTitle": ".base", - "wishlistShareBackLink": ".form.wishlist.share .back", - "wishlistRemoveItemButton": "[title=\"Remove Item\"]", - "successMessage": ".message.success span", - "accountIcon": ":nth-child(2) > .customer-welcome > .customer-name > .action", - "accountMenu": ":nth-child(2) > .customer-welcome > .customer-menu > .header > .authorization-link > a", - "signedOutHeader": ".base", - "successMessageCartLink": ".message-success > div > a", - "messageContents": ".message span" + "changePasswordFormSelector": "#form-validate", + "addAddressFormSelector": "#form-validate", + "accountFirstnameInputSelector": "#firstname", + "accountLastnameInputSelector": "#lastname", + "currentPasswordInputSelector": "#current-password", + "newPasswordInputSelector": "#password", + "newPasswordConfirmationInputSelector": "#password-confirmation", + "changePasswordSave": "button.action.save.primary", + "accountEmailInputSelector": "input#email_address", + "loginEmailInputSelector": "input#email", + "loginPasswordInputSelector": "input#pass", + "myAccountHeaderSelector": "[data-ui-id=\"page-title-wrapper\"]", + "editAddress": ".box-address-shipping > .box-actions > .action > span", + "addressEditStreetInput": "input[id^=\"street\"]", + "addNewAddressButton": ".action.primary.add", + "saveAddressButton": "button[data-action=\"save-address\"]", + "wishlistTitle": "h1.page-title .base", + "successMessageCartLink": ".message-success > div > a", + "messageContents": ".message span" } diff --git a/cypress/page-objects/luma/account.js b/cypress/page-objects/luma/account.js index f4fbfc0..fd0d352 100644 --- a/cypress/page-objects/luma/account.js +++ b/cypress/page-objects/luma/account.js @@ -1,13 +1,16 @@ import selectors from '../../fixtures/luma/selectors/account' import account from '../../fixtures/account' -import {isMobile} from "../../support/utils"; +import {isMobile} from '../../support/utils' export class Account { static login(user, pw) { cy.visit(account.routes.accountIndex); - cy.wait(2000) cy.get(selectors.loginEmailInputSelector).type(user) - cy.get(selectors.loginPasswordInputSelector).type(`${pw}{enter}`) + cy.get(selectors.loginPasswordInputSelector) + .first() + .type(pw) + cy.get('button[type=submit]') + .contains('Sign In').click() } static isLoggedIn() { @@ -18,7 +21,9 @@ export class Account { if(isMobile()) { cy.get('.sidebar-main > .block > .title').click() } - cy.get('#block-collapsible-nav').contains('Account Information').click() + cy.get('#account-nav') + .contains('Account Information') + .click() } static checkAllProfileSpecs() { @@ -32,7 +37,8 @@ export class Account { cy.get(selectors.changePasswordFormSelector).within(($from) => { cy.get(selectors.currentPasswordInputSelector).type(pwd) cy.get(selectors.newPasswordInputSelector).type(newPwd) - cy.get(selectors.newPasswordConfirmationInputSelector).type(`${newPwd}{enter}`) + cy.get(selectors.newPasswordConfirmationInputSelector).type(newPwd) + cy.get(selectors.changePasswordSave).click() }) } @@ -50,7 +56,6 @@ export class Account { cy.get(selectors.accountEmailInputSelector).type(email) cy.get(selectors.newPasswordInputSelector).type(passwd) cy.get(selectors.newPasswordConfirmationInputSelector).type(passwd) - cy.wait(3000) cy.get('.form-create-account button').click() } @@ -58,15 +63,27 @@ export class Account { if(isMobile()) { cy.get('.nav-toggle').click() cy.get('[aria-controls="store.links"]').click() - } else { - cy.get(':nth-child(2) > .customer-welcome > .customer-name > .action').click() } - cy.contains('Sign Out').click({force: true}) + cy.contains('Sign Out').click() + // TODO: Wait for page load + cy.contains('You are signed out') + .should('exist') + } + + static ensureLoggedOut() { + cy.visit('/customer/account/logout/') + } + + static ensureLoggedIn(username, password) { + this.ensureLoggedOut() + this.login(username, password) } /** Create an address that is used with other tests */ - static createAddress(customerInfo) { - cy.visit(account.routes.accountAddAddress) + static createAddress(customerInfo, goToPage = true) { + if(goToPage) { + cy.visit(account.routes.accountAddAddress) + } cy.get(selectors.addAddressFormSelector).then(($form) => { if ($form.find('#primary_billing').length) { cy.get('#primary_billing').check() diff --git a/cypress/page-objects/luma/cart.js b/cypress/page-objects/luma/cart.js index 0ec37db..3839de4 100644 --- a/cypress/page-objects/luma/cart.js +++ b/cypress/page-objects/luma/cart.js @@ -1,20 +1,21 @@ -import cart from "../../fixtures/luma/selectors/cart" +import cart from '../../fixtures/luma/selectors/cart' export class Cart { static addProductToCart(url) { cy.visit(url) - cy.wait(5000) - cy.get(cart.product.addToCartButton).click() - cy.wait(5000) + cy.get(cart.addToCartButton).click() } - static addCouponCode() { - cy.visit(cart.url.cartUrl) - cy.wait(3000) - cy.get(cart.couponDropdownSelector).click({force: true}) - cy.get(cart.couponInputField).type(cart.couponCode) - cy.get(cart.addCouponButton).click() - cy.wait(3000) + static addCouponCode(code) { + cy.intercept('**/rest/*/V1/guest-carts/*/totals-information') + .as('totalsInformation') + + cy.visit(cart.cartUrl) + cy.wait('@totalsInformation') + cy.get(cart.couponDropdownSelector).click() + cy.get(cart.couponInputField).type(code, {force: true}) + cy.get(cart.addCouponButton).click({force: true}) + cy.wait('@totalsInformation') } } diff --git a/cypress/page-objects/luma/checkout.js b/cypress/page-objects/luma/checkout.js index 1431bff..76085b6 100644 --- a/cypress/page-objects/luma/checkout.js +++ b/cypress/page-objects/luma/checkout.js @@ -1,5 +1,5 @@ -import selectors from "../../fixtures/luma/selectors/checkout" -import checkout from "../../fixtures/checkout" +import selectors from '../../fixtures/luma/selectors/checkout' +import checkout from '../../fixtures/checkout' export class Checkout { @@ -10,15 +10,26 @@ export class Checkout { } static enterShippingAddress(shippingAddress) { - cy.get(selectors.customerEmailField).type(shippingAddress.email) - cy.get(selectors.firstNameField).type(shippingAddress.firstname) - cy.get(selectors.lastNameField).type(shippingAddress.lastname) - cy.get(selectors.companyField).type(shippingAddress.companyname) - cy.get(selectors.addressField).eq(0).type(shippingAddress.street) - cy.get(selectors.cityField).type(shippingAddress.city) - cy.get(selectors.postCodeField).type(shippingAddress.postcode) - cy.get(selectors.countryField).select('United Kingdom') - cy.get(selectors.telephoneField).type(shippingAddress.tel) + cy.get(`${selectors.shippingContainer} ${selectors.firstNameField}`).type(shippingAddress.firstname) + cy.get(`${selectors.shippingContainer} ${selectors.lastNameField}`).type(shippingAddress.lastname) + cy.get(`${selectors.shippingContainer} ${selectors.companyField}`).type(shippingAddress.companyname) + cy.get(`${selectors.shippingContainer} ${selectors.addressField}`).eq(0).type(shippingAddress.street) + cy.get(`${selectors.shippingContainer} ${selectors.cityField}`).type(shippingAddress.city) + cy.get(`${selectors.shippingContainer} ${selectors.postCodeField}`).type(shippingAddress.postcode) + cy.get(`${selectors.shippingContainer} ${selectors.countryField}`).select('United Kingdom') + cy.get(`${selectors.shippingContainer} ${selectors.telephoneField}`).type(shippingAddress.tel) + } + + static enterBillingAddress(shippingAddress) { + cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`).type(shippingAddress.email) + cy.get(`${selectors.billingContainer} ${selectors.firstNameField}`).type(shippingAddress.firstname) + cy.get(`${selectors.billingContainer} ${selectors.lastNameField}`).type(shippingAddress.lastname) + cy.get(`${selectors.billingContainer} ${selectors.companyField}`).type(shippingAddress.companyname) + cy.get(`${selectors.billingContainer} ${selectors.addressField}`).eq(0).type(shippingAddress.street) + cy.get(`${selectors.billingContainer} ${selectors.cityField}`).type(shippingAddress.city) + cy.get(`${selectors.billingContainer} ${selectors.postCodeField}`).type(shippingAddress.postcode) + cy.get(`${selectors.billingContainer} ${selectors.countryField}`).select('United Kingdom') + cy.get(`${selectors.billingContainer} ${selectors.telephoneField}`).type(shippingAddress.tel) } static addProductToCart(productUrl) { From b4f467fd33f3230e6a947244487bca02373cf9ad Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 11:15:13 +0200 Subject: [PATCH 10/17] fix(checkout): correctly set shipping address --- cypress/integration/luma/checkout/checkout.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/integration/luma/checkout/checkout.spec.js b/cypress/integration/luma/checkout/checkout.spec.js index 136efc6..c674de5 100644 --- a/cypress/integration/luma/checkout/checkout.spec.js +++ b/cypress/integration/luma/checkout/checkout.spec.js @@ -65,7 +65,7 @@ function addAProductToCartAndEnterBillingAddressInCheckout() { .click() cy.wait('@estimateShipping') - Checkout.enterBillingAddress(checkout.billingAddress) + Checkout.enterShippingAddress(checkout.billingAddress) cy.wait('@emailAvailable') } @@ -129,7 +129,7 @@ describe('Checkout tests', () => { const cartDiscount = parseFloat($cartDiscount.last().text().trim().slice(2)) cy.visit(checkout.checkoutUrl) cy.wait('@estimateShipping') - Checkout.enterBillingAddress(checkout.billingAddress) + Checkout.enterShippingAddress(checkout.billingAddress) cy.get('.button.action.continue.primary').click() cy.wait('@sectionLoad') cy.wait('@sectionLoad') From 81bc4b4828a9c2824a37f18ef8e11667c5691a76 Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 13:01:14 +0200 Subject: [PATCH 11/17] feat(account): actually log in from checkout --- cypress/fixtures/luma/selectors/checkout.json | 1 + cypress/integration/luma/user/account.spec.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cypress/fixtures/luma/selectors/checkout.json b/cypress/fixtures/luma/selectors/checkout.json index df517c6..24c3013 100644 --- a/cypress/fixtures/luma/selectors/checkout.json +++ b/cypress/fixtures/luma/selectors/checkout.json @@ -14,6 +14,7 @@ "emailValidationErrorField": "fieldset#customer-email-fieldset .control div[for=customer-email].mage-error", "addToCartButton": "#product-addtocart-button", "checkoutEmailLabel": "#customer-email", + "checkoutPasswordInput": "input#customer-password", "moneyOrderPaymentMethodSelector": "#checkmo", "moneOrderAgreement1": "#agreement_checkmo_1", "moneOrderAgreement2": "#agreement_checkmo_2", diff --git a/cypress/integration/luma/user/account.spec.js b/cypress/integration/luma/user/account.spec.js index 9901089..9a504eb 100644 --- a/cypress/integration/luma/user/account.spec.js +++ b/cypress/integration/luma/user/account.spec.js @@ -181,10 +181,14 @@ describe('Guest user test', () => { .as('emailAvailable') cy.intercept('**/rest/*/V1/guest-carts/*/estimate-shipping-methods') .as('estimateShipping') + cy.intercept('**/customer/ajax/login') + .as('login') + cy.intercept('**/rest/*/V1/carts/mine/estimate-shipping-methods-by-address-id') + .as('estimateShippingWithAddress') cy.visit(product.simpleProductUrl) cy.get(checkoutSelectors.addToCartButton) - .contains( 'Add to Cart') + .contains('Add to Cart') .click() cy.visit(checkout.checkoutUrl) cy.wait('@estimateShipping') @@ -192,5 +196,10 @@ describe('Guest user test', () => { cy.wait('@emailAvailable') cy.get('.billing-address-form') .should('contain.text', 'You already have an account with us. Sign in or continue as guest.') + cy.get(checkoutSelectors.checkoutPasswordInput) + .type(`${account.customer.password}{enter}`) + cy.wait('@login') + cy.wait('@estimateShippingWithAddress') + cy.get(checkoutSelectors.addressSelected).should('have.length', 1) }) }) From ba4d327b4b792fdbaeb43c071445491a0844fb0e Mon Sep 17 00:00:00 2001 From: klg Date: Tue, 29 Mar 2022 13:01:57 +0200 Subject: [PATCH 12/17] chore(account): use cy.intercept instead of fixed wait --- cypress/integration/luma/user/account.spec.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cypress/integration/luma/user/account.spec.js b/cypress/integration/luma/user/account.spec.js index 9a504eb..96064b3 100644 --- a/cypress/integration/luma/user/account.spec.js +++ b/cypress/integration/luma/user/account.spec.js @@ -99,14 +99,17 @@ describe('Account activities', () => { }) it('Can add an address automatically from saved address', () => { + cy.intercept('**/rest/*/V1/carts/mine/estimate-shipping-methods-by-address-id') + .as('estimateShippingWithAddress') + Account.createAddress(account.customerInfo) // There needs to be an item in the cart for this to work, and there needs to be a saved address cy.visit(product.simpleProductUrl) cy.contains('Add to Cart').click() cy.visit(checkout.checkoutUrl) - // TODO: Replace with cy.intercept - cy.wait(7000) // this shouldn't be needed but for some reason it doesn't work without - cy.get('.shipping-address-item.selected-item').should('have.length', 1) + cy.wait('@estimateShippingWithAddress') + cy.get(checkoutSelectors.addressSelected) + .should('have.length', 1) }) it('Can remove an address', () => { From 9e6ac7f1324a905a0da6d0a702d4de37bd33a171 Mon Sep 17 00:00:00 2001 From: klg Date: Thu, 12 May 2022 17:17:28 +0200 Subject: [PATCH 13/17] fix(luma): cart test --- cypress/integration/luma/cart/cart.spec.js | 6 +++--- cypress/page-objects/luma/cart.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cypress/integration/luma/cart/cart.spec.js b/cypress/integration/luma/cart/cart.spec.js index 670157f..438f223 100644 --- a/cypress/integration/luma/cart/cart.spec.js +++ b/cypress/integration/luma/cart/cart.spec.js @@ -13,12 +13,12 @@ describe('Isolated test for adding a product to the cart', () => { describe('Cart tests', () => { beforeEach(() => { - cy.intercept('**/rest/*/V1/guest-carts/*/totals-information') - .as('totalsInformation') + cy.intercept('**/rest/default/V1/guest-carts/*/estimate-shipping-methods') + .as('estimateShippingMethod') Cart.addProductToCart(productLuma.simpleProductUrl); cy.visit(cartLuma.cartUrl); - cy.wait('@totalsInformation') + cy.wait('@estimateShippingMethod') }); it('Can change the quantity in the cart', () => { diff --git a/cypress/page-objects/luma/cart.js b/cypress/page-objects/luma/cart.js index 3839de4..846f810 100644 --- a/cypress/page-objects/luma/cart.js +++ b/cypress/page-objects/luma/cart.js @@ -3,19 +3,19 @@ import cart from '../../fixtures/luma/selectors/cart' export class Cart { static addProductToCart(url) { cy.visit(url) - cy.get(cart.addToCartButton).click() + cy.get(cart.product.addToCartButton).click() } static addCouponCode(code) { - cy.intercept('**/rest/*/V1/guest-carts/*/totals-information') - .as('totalsInformation') + cy.intercept('**/rest/default/V1/guest-carts/*/estimate-shipping-methods') + .as('estimateShippingMethod') cy.visit(cart.cartUrl) - cy.wait('@totalsInformation') + cy.wait('@estimateShippingMethod') cy.get(cart.couponDropdownSelector).click() cy.get(cart.couponInputField).type(code, {force: true}) cy.get(cart.addCouponButton).click({force: true}) - cy.wait('@totalsInformation') + cy.wait('@estimateShippingMethod') } } From aed9d279ae5578f00f88fa85d7104caa1a2a55da Mon Sep 17 00:00:00 2001 From: klg Date: Thu, 12 May 2022 17:59:56 +0200 Subject: [PATCH 14/17] fix(luma): checkout test --- cypress/fixtures/luma/product.json | 2 +- cypress/fixtures/luma/selectors/checkout.json | 2 +- .../luma/checkout/checkout.spec.js | 27 ++++++++++++------- cypress/page-objects/luma/checkout.js | 5 ++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cypress/fixtures/luma/product.json b/cypress/fixtures/luma/product.json index 5705e4c..7e5037a 100644 --- a/cypress/fixtures/luma/product.json +++ b/cypress/fixtures/luma/product.json @@ -12,7 +12,7 @@ "outOfStockProductUrl": "dash-digital-watch.html", "outOfStockProductName": "Dash Digital Watch", "productAttributeSelector": ".swatch-attribute-options", - "currency": "$", + "currency": "€", "priceRegexp": "$", "simpleSearchTerm": "didi", "couponProductUrl": "/affirm-water-bottle.html" diff --git a/cypress/fixtures/luma/selectors/checkout.json b/cypress/fixtures/luma/selectors/checkout.json index 24c3013..168777f 100644 --- a/cypress/fixtures/luma/selectors/checkout.json +++ b/cypress/fixtures/luma/selectors/checkout.json @@ -27,7 +27,7 @@ "totalPrice": ".grand.totals .price", "taxesPrice": ".table-totals .totals-tax-summary td .price", "checkoutDiscountPrice": ".totals.discount .price", - "cartDiscount": ":nth-child(3) > .amount", + "cartDiscount": "table.totals tr.totals:nth-child(2) .amount", "checkoutBtn": ".button.action.continue.primary", "orderConfirmationOrderNumber": ".checkout-success strong", "checkoutSuccess": ".checkout-success", diff --git a/cypress/integration/luma/checkout/checkout.spec.js b/cypress/integration/luma/checkout/checkout.spec.js index c674de5..6eb8cf0 100644 --- a/cypress/integration/luma/checkout/checkout.spec.js +++ b/cypress/integration/luma/checkout/checkout.spec.js @@ -85,7 +85,10 @@ describe('Checkout tests', () => { cy.visit(checkout.checkoutUrl) cy.wait('@estimateShipping') Checkout.enterShippingAddress(checkout.shippingAddress) - cy.wait('@sectionLoad') + cy.wait('@estimateShipping') + cy.get('.table-checkout-shipping-method td') + .contains('Fixed') + .click() cy.get('.button.action.continue.primary').click() cy.wait('@sectionLoad') @@ -99,11 +102,13 @@ describe('Checkout tests', () => { cy.get(selectors.checkoutShippingPrice).then(($shippingPrice) => { const shippingPrice = $shippingPrice[0].innerText.trim() cy.get(selectors.totalPrice).then(($totalPrice) => { - const totalPrice = $totalPrice[0].innerText.trim().slice(1) - cy.get(selectors.taxesPrice).then($taxesPrice => { - const taxes = $taxesPrice[0].innerText.trim().slice(1) - expect(parseFloat(checkoutPrice.slice(1)) + parseFloat(shippingPrice.slice(1)) + parseFloat(taxes)).to.equal(parseFloat(totalPrice)) - }) + const totalPrice = $totalPrice[0].innerText.trim() + // Uncomment if your shop has taxes + // cy.get(selectors.taxesPrice).then($taxesPrice => { + // const taxes = $taxesPrice[0].innerText.trim().slice(1) + // expect(parseFloat(checkoutPrice.slice(1)) + parseFloat(shippingPrice.slice(1)) + parseFloat(taxes)).to.equal(parseFloat(totalPrice)) + // }) + expect(parseFloat(checkoutPrice) + parseFloat(shippingPrice)).to.equal(parseFloat(totalPrice)) }) }) }) @@ -115,7 +120,7 @@ describe('Checkout tests', () => { Cart.addProductToCart(productLuma.simpleProductUrl) cy.visit(cartLuma.cartUrl) - cy.wait('@totalsInformation') + cy.wait('@estimateShipping') Magento2RestApi.createRandomCouponCode() .then(coupon => { @@ -126,10 +131,11 @@ describe('Checkout tests', () => { .should('include.text', 'Discount') .should('be.visible') cy.get(selectors.cartDiscount).then(($cartDiscount) => { - const cartDiscount = parseFloat($cartDiscount.last().text().trim().slice(2)) + // FIXME: This gives me 9.2 instead of 9.7 + const cartDiscount = parseFloat($cartDiscount.last().text().trim().slice(1).replace(',', '.')) cy.visit(checkout.checkoutUrl) cy.wait('@estimateShipping') - Checkout.enterShippingAddress(checkout.billingAddress) + Checkout.enterShippingAddress(checkout.shippingAddress) cy.get('.button.action.continue.primary').click() cy.wait('@sectionLoad') cy.wait('@sectionLoad') @@ -137,7 +143,8 @@ describe('Checkout tests', () => { cy.get('.action.showcart').click() } cy.get(selectors.checkoutDiscountPrice).then(($discount) => { - const discount = parseFloat($discount[0].innerText.trim().slice(2)) + console.log($discount[0].innerText.trim().slice(1)) + const discount = parseFloat($discount[0].innerText.trim().slice(1).replace(',', '.')) expect(discount).to.equal(cartDiscount) }) }) diff --git a/cypress/page-objects/luma/checkout.js b/cypress/page-objects/luma/checkout.js index 76085b6..0f940b1 100644 --- a/cypress/page-objects/luma/checkout.js +++ b/cypress/page-objects/luma/checkout.js @@ -10,13 +10,14 @@ export class Checkout { } static enterShippingAddress(shippingAddress) { + cy.get(selectors.customerEmailField).type(shippingAddress.email) cy.get(`${selectors.shippingContainer} ${selectors.firstNameField}`).type(shippingAddress.firstname) cy.get(`${selectors.shippingContainer} ${selectors.lastNameField}`).type(shippingAddress.lastname) cy.get(`${selectors.shippingContainer} ${selectors.companyField}`).type(shippingAddress.companyname) cy.get(`${selectors.shippingContainer} ${selectors.addressField}`).eq(0).type(shippingAddress.street) cy.get(`${selectors.shippingContainer} ${selectors.cityField}`).type(shippingAddress.city) cy.get(`${selectors.shippingContainer} ${selectors.postCodeField}`).type(shippingAddress.postcode) - cy.get(`${selectors.shippingContainer} ${selectors.countryField}`).select('United Kingdom') + cy.get(`${selectors.shippingContainer} ${selectors.countryField}`).select('NL') cy.get(`${selectors.shippingContainer} ${selectors.telephoneField}`).type(shippingAddress.tel) } @@ -28,7 +29,7 @@ export class Checkout { cy.get(`${selectors.billingContainer} ${selectors.addressField}`).eq(0).type(shippingAddress.street) cy.get(`${selectors.billingContainer} ${selectors.cityField}`).type(shippingAddress.city) cy.get(`${selectors.billingContainer} ${selectors.postCodeField}`).type(shippingAddress.postcode) - cy.get(`${selectors.billingContainer} ${selectors.countryField}`).select('United Kingdom') + cy.get(`${selectors.billingContainer} ${selectors.countryField}`).select('NL') cy.get(`${selectors.billingContainer} ${selectors.telephoneField}`).type(shippingAddress.tel) } From db6dbf1f28eace96d85e526b4e0869745ca7c393 Mon Sep 17 00:00:00 2001 From: klg Date: Fri, 13 May 2022 12:45:26 +0200 Subject: [PATCH 15/17] fix(luma): checkout test --- cypress/fixtures/account.json | 6 +- cypress/fixtures/luma/selectors/checkout.json | 8 +- .../luma/checkout/checkout.spec.js | 78 +++++++------------ cypress/page-objects/luma/checkout.js | 6 +- 4 files changed, 41 insertions(+), 57 deletions(-) diff --git a/cypress/fixtures/account.json b/cypress/fixtures/account.json index 7d5a990..01cb80e 100644 --- a/cypress/fixtures/account.json +++ b/cypress/fixtures/account.json @@ -1,15 +1,15 @@ { "customer": { "customer": { - "email": "test@cypress-testing.com", + "email": "roni_cost@example.com", "firstname": "Test", "lastname": "Test" }, - "password": "Test!234" + "password": "roni_cost3@example.com" }, "customerInfo": { "city": "Groningen", - "country": "Netherlands", + "country": "NL", "phone": "1234567890", "state": "Groningen", "streetAddress": "Teststraat 1", diff --git a/cypress/fixtures/luma/selectors/checkout.json b/cypress/fixtures/luma/selectors/checkout.json index 168777f..c64a34c 100644 --- a/cypress/fixtures/luma/selectors/checkout.json +++ b/cypress/fixtures/luma/selectors/checkout.json @@ -3,6 +3,7 @@ "billingContainer": ".billing-address-form form", "companyField": "[name=\"company\"]", "customerEmailField": "#customer-email", + "customerEmailFieldset": "#customer-email-fieldset", "firstNameField": "[name=\"firstname\"]", "lastNameField": "[name=\"lastname\"]", "addressField": "[name=\"street[0]\"]", @@ -11,7 +12,7 @@ "countryField": "[name=\"country_id\"]", "regionField": "[name=\"region\"]", "telephoneField": "[name=\"telephone\"]", - "emailValidationErrorField": "fieldset#customer-email-fieldset .control div[for=customer-email].mage-error", + "emailValidationErrorField": "#customer-email-error", "addToCartButton": "#product-addtocart-button", "checkoutEmailLabel": "#customer-email", "checkoutPasswordInput": "input#customer-password", @@ -35,5 +36,8 @@ "proceedToCheckout": "button[data-role=\"proceed-to-checkout\"]", "checkoutGuestCheckbox": "#checkout_method_guest", "checkoutGuestContinue": "#newcustomer .actions-toolbar .primary .action.create.primary", - "sameBillingAsShipping": "label[for=billing-address-same-as-shipping]" + "sameBillingAsShipping": "label[for=billing-address-same-as-shipping-checkmo]", + "shippingTotal": "tr.totals.shipping .amount", + "continueToPayment": "#shipping-method-buttons-container button", + "updateBillingAddress": ".payment-method-billing-address button.action.action-update" } diff --git a/cypress/integration/luma/checkout/checkout.spec.js b/cypress/integration/luma/checkout/checkout.spec.js index 6eb8cf0..958225c 100644 --- a/cypress/integration/luma/checkout/checkout.spec.js +++ b/cypress/integration/luma/checkout/checkout.spec.js @@ -25,13 +25,13 @@ function setupGuestCheckoutInterceptors() { .as('paymentInformation') } -function chooseMoneyOrderPaymentAndPlaceOrder() { +function chooseMoneyOrderPaymentAndPlaceOrder(wait = '@estimateShipping') { + if(wait !== null) { + cy.wait(wait) + } cy.get(selectors.checkoutBtn).click() - cy.wait('@sectionLoad') cy.get(selectors.moneyOrderPaymentMethodSelector).check({force: true}) cy.get(selectors.moneyOrderPaymentMethodSelector).should('be.checked') - cy.get(selectors.moneOrderAgreement1).check() - cy.get(selectors.moneOrderAgreement2).check() } function addProductToCartAndVerifyItWasAdded() { @@ -50,26 +50,19 @@ function addAProductToCartAndEnterBillingAddressInCheckout() { .click() cy.url() .should('contain', checkout.cartUrl) - cy.wait('@sectionLoad') cy.wait('@estimateShipping') - cy.wait('@totalsInformation') cy.get(selectors.proceedToCheckout) .click() - cy.get(global.pageTitle) - .should('contain.text', 'Customer Login') - cy.get(selectors.checkoutGuestCheckbox) - .check({force: true}) - cy.wait(1000) // FIXME: This wait should not be nessecary - cy.get(selectors.checkoutGuestContinue) - .click() - cy.wait('@estimateShipping') - Checkout.enterShippingAddress(checkout.billingAddress) - cy.wait('@emailAvailable') + Checkout.enterShippingAddress(checkout.shippingAddress) } describe('Checkout tests', () => { + beforeEach(() => { + Account.ensureLoggedOut() + }) + it('Can see the correct product price and shipping costs', () => { setupGuestCheckoutInterceptors() cy.intercept('**/rest/*/V1/carts/mine/shipping-information') @@ -130,9 +123,13 @@ describe('Checkout tests', () => { cy.get(cartLuma.cartSummaryTable) .should('include.text', 'Discount') .should('be.visible') + // The discount is applied to the shipping as well. Because of that it changes after the + // shipping information is loaded and parsed. To make sure we're grabbing the right discount + // amount we wait until that's done. + cy.get(selectors.shippingTotal) + .should('not.contain', '0,00') cy.get(selectors.cartDiscount).then(($cartDiscount) => { - // FIXME: This gives me 9.2 instead of 9.7 - const cartDiscount = parseFloat($cartDiscount.last().text().trim().slice(1).replace(',', '.')) + const cartDiscount = parseFloat($cartDiscount[0].innerText.trim().slice(1).replace(',', '.')) cy.visit(checkout.checkoutUrl) cy.wait('@estimateShipping') Checkout.enterShippingAddress(checkout.shippingAddress) @@ -157,6 +154,8 @@ describe('Checkout tests', () => { .as('shippingInformation') cy.intercept('**/rest/*/V1/carts/mine/payment-information') .as('paymentInformation') + cy.intercept('**/rest/default/V1/carts/mine/estimate-shipping-methods-by-address-id') + .as('estimateShippingByAddressId') Cart.addProductToCart(product.simpleProductUrl) cy.wait('@sectionLoad') @@ -168,7 +167,7 @@ describe('Checkout tests', () => { cy.wait('@sectionLoad') cy.get(selectors.addressSelected).should('exist') - chooseMoneyOrderPaymentAndPlaceOrder() + chooseMoneyOrderPaymentAndPlaceOrder('@estimateShippingByAddressId') cy.get(selectors.placeOrderBtn) .last() .should('be.visible') @@ -200,7 +199,7 @@ describe('Checkout tests', () => { cy.wait('@paymentInformation') cy.get(selectors.checkoutSuccess) - .should('contain.text', 'Thank you for order!') + .should('contain.text', 'Your order # is:') }) it('Can do a checkout as guest with a different shipping address', () => { @@ -208,14 +207,16 @@ describe('Checkout tests', () => { addAProductToCartAndEnterBillingAddressInCheckout() + cy.wait('@estimateShipping') + cy.get(selectors.checkoutBtn).click() cy.get(selectors.sameBillingAsShipping) .click() - Checkout.enterShippingAddress(checkout.shippingAddress) + Checkout.enterBillingAddress(checkout.shippingAddress, false) - chooseMoneyOrderPaymentAndPlaceOrder() + cy.get(selectors.updateBillingAddress) + .click() cy.get('.shipping-information .ship-to .shipping-information-content') - .should('contain.text', checkout.shippingAddress.companyname) .should('contain.text', checkout.shippingAddress.firstname) .should('contain.text', checkout.shippingAddress.lastname) .should('contain.text', checkout.shippingAddress.street) @@ -228,30 +229,7 @@ describe('Checkout tests', () => { cy.wait('@paymentInformation') cy.get(selectors.checkoutSuccess) - .should('contain.text', 'Thank you for order!') - }) - - it('Should add shipping costs again when the subtotal goes below free shipping threshhold', () => { - setupGuestCheckoutInterceptors() - - Cart.addProductToCart(productLuma.simpleProductUrl) - cy.visit(cartLuma.cartUrl) - cy.wait('@totalsInformation') - - cy.get(selectors.checkoutShippingPrice) - .should('contain.text', `${product.currency}0.00`) - - Magento2RestApi.createRandomCouponCode(80) - .then(coupon => { - Cart.addCouponCode(coupon) - cy.wait('@estimateShipping') - cy.wait('@sectionLoad') - cy.get(cartLuma.cartSummaryTable) - .should('include.text', 'Discount') - .should('be.visible') - cy.get(selectors.checkoutShippingPrice) - .should('not.contain.text', `${product.currency}0.00`) - }) + .should('contain.text', 'Your order # is:') }) describe('Validate email address in checkout', () => { @@ -265,12 +243,12 @@ describe('Checkout tests', () => { }) it('Enters a correct email address', () => { - cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`) + cy.get(`${selectors.customerEmailFieldset} ${selectors.customerEmailField}`) .type('john.doe@example.com') }) it('Enters an incorrect email address', () => { - cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`) + cy.get(`${selectors.customerEmailFieldset} ${selectors.customerEmailField}`) .type('John') .blur() cy.get(selectors.emailValidationErrorField) @@ -278,7 +256,7 @@ describe('Checkout tests', () => { }) it('Enters another incorrect email address', () => { - cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`) + cy.get(`${selectors.customerEmailFieldset} ${selectors.customerEmailField}`) .type('john.doe#example.com') .blur() cy.get(selectors.emailValidationErrorField) diff --git a/cypress/page-objects/luma/checkout.js b/cypress/page-objects/luma/checkout.js index 0f940b1..197cc2c 100644 --- a/cypress/page-objects/luma/checkout.js +++ b/cypress/page-objects/luma/checkout.js @@ -21,8 +21,10 @@ export class Checkout { cy.get(`${selectors.shippingContainer} ${selectors.telephoneField}`).type(shippingAddress.tel) } - static enterBillingAddress(shippingAddress) { - cy.get(`${selectors.billingContainer} ${selectors.customerEmailField}`).type(shippingAddress.email) + static enterBillingAddress(shippingAddress, withEmail = true) { + if(withEmail) { + cy.get(selectors.customerEmailField).type(shippingAddress.email) + } cy.get(`${selectors.billingContainer} ${selectors.firstNameField}`).type(shippingAddress.firstname) cy.get(`${selectors.billingContainer} ${selectors.lastNameField}`).type(shippingAddress.lastname) cy.get(`${selectors.billingContainer} ${selectors.companyField}`).type(shippingAddress.companyname) From 4f4acd22382c5e9ed99891af32b9ddf0b0670138 Mon Sep 17 00:00:00 2001 From: klg Date: Fri, 13 May 2022 13:02:48 +0200 Subject: [PATCH 16/17] fix(luma): category tests --- cypress/fixtures/category.json | 4 +-- cypress/fixtures/luma/selectors/category.json | 6 ++-- .../luma/products/category.spec.js | 28 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cypress/fixtures/category.json b/cypress/fixtures/category.json index d589aff..2879bbd 100644 --- a/cypress/fixtures/category.json +++ b/cypress/fixtures/category.json @@ -1,6 +1,6 @@ { - "categoryUrl": "/women/tops-women.html", - "category": "Women", + "categoryUrl": "/men/tops-men.html", + "category": "Tops", "subCategory": "Tops", "filterBy": "Color", "filterQueryParam": "color", diff --git a/cypress/fixtures/luma/selectors/category.json b/cypress/fixtures/luma/selectors/category.json index 0a8723a..bf93800 100644 --- a/cypress/fixtures/luma/selectors/category.json +++ b/cypress/fixtures/luma/selectors/category.json @@ -4,7 +4,7 @@ "productPriceDataAtt": "[data-price-type=\"finalPrice\"]", "highestNumberOfProductsShowOption": "#limiter", "numberOfProductsSelect": "#limiter", - "numberOfShownItems": "#toolbar-amount:first-of-type .toolbar-number:nth-child(2)", + "numberOfShownItems": "#toolbar-amount", "categoryProductContainer": ".products-grid > ol", "breadcrumbsItem": ".breadcrumbs ul li", "categoryProductGridWrapper": ".modes-mode.mode-grid", @@ -14,6 +14,6 @@ "pageLink": "a.page", "secondPageItem": "ul.pages-items > li:nth-child(3) > .page", "filterTitle": ".filter-options-title", - "filterOption": ".filter-options-filter", - "filterByLabel": ".filter-options-content ol.items > li:nth-child(1) > a > label" + "filterOption": ".filter-options-item", + "filterByLabel": ".filter-options .swatch-attribute-options a .color" } diff --git a/cypress/integration/luma/products/category.spec.js b/cypress/integration/luma/products/category.spec.js index 4f80ac1..93c76a9 100644 --- a/cypress/integration/luma/products/category.spec.js +++ b/cypress/integration/luma/products/category.spec.js @@ -19,39 +19,39 @@ describe('Category page tests', () => { .contains(category.filterBy) .get(selectors.filterByLabel) .first() - .click({force: true}) // Only visible when hovering + .click({force: true}) cy.url() .should('contain', `?${category.filterQueryParam}=`) }) it('Can sort products on price from lowest to highest', () => { - cy.get(selectors.sortBySelect).first().select(category.selectByPrice); - cy.get(selectors.productPriceDataAtt).eq(0).invoke('data', 'price-amount') + cy.get(selectors.sortBySelect).first().select(category.selectByPrice) + cy.get(selectors.productPriceDataAtt) + .first() + .invoke('data', 'price-amount') .then((firstPrice) => { cy.get(selectors.productPriceDataAtt) .eq(1) .invoke('data', 'price-amount') - .should('be.lte', firstPrice) - }); + .should('be.gte', firstPrice) + }) }) it('Can change the number of products to be displayed', () => { - cy.get(selectors.highestNumberOfProductsShowOption).find('option').eq(1).invoke('val') - .then((numberOfProducts) => { - cy.get(selectors.numberOfProductsSelect).select(numberOfProducts, {force: true}); - cy.get(selectors.numberOfShownItems).first().should('have.text', numberOfProducts); - cy.get(selectors.categoryProductContainer).children().should('to.have.length.of.at.most', +numberOfProducts); - } - ) + const numberOfProducts = '24' + cy.get(selectors.highestNumberOfProductsShowOption) + .select(numberOfProducts) + cy.get(selectors.numberOfShownItems).first().should('contain', numberOfProducts) + cy.get(selectors.categoryProductContainer).children().should('to.have.length.of.at.most', +numberOfProducts) }) it('Can see the correct breadcrumbs', () => { cy.get(selectors.breadcrumbsItem).first().should('contain.text', 'Home') - cy.get(selectors.breadcrumbsItem).eq(1).should('contain.text', 'Products') + cy.get(selectors.breadcrumbsItem).eq(1).should('contain.text', 'Men') cy.get(selectors.breadcrumbsItem).eq(2).should('contain.text', category.category) }) - if(!isMobile()) { + if (!isMobile()) { it('Can switch between list and grid view', () => { cy.get(selectors.categoryProductGridWrapper).should('be.visible') cy.get(selectors.viewToggle).click() From 66393364578445861ac3db886d81f1160a073781 Mon Sep 17 00:00:00 2001 From: klg Date: Fri, 13 May 2022 13:15:18 +0200 Subject: [PATCH 17/17] fix(luma): product serach tests --- cypress/fixtures/luma/search.json | 4 ++-- cypress/fixtures/luma/selectors/search.json | 3 ++- .../integration/luma/products/product.spec.js | 19 ++++++++++--------- .../luma/search/product-searches.spec.js | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cypress/fixtures/luma/search.json b/cypress/fixtures/luma/search.json index b4f8d5f..3c0ad4e 100644 --- a/cypress/fixtures/luma/search.json +++ b/cypress/fixtures/luma/search.json @@ -1,6 +1,6 @@ { - "searchTerm": "Didi", + "searchTerm": "Watch", "noResults": "1234abcd", "getHint": "didi", - "hintResult": "Didi" + "hintResult": "watch" } diff --git a/cypress/fixtures/luma/selectors/search.json b/cypress/fixtures/luma/selectors/search.json index 82cea59..854270d 100644 --- a/cypress/fixtures/luma/selectors/search.json +++ b/cypress/fixtures/luma/selectors/search.json @@ -5,5 +5,6 @@ "headerSearchIcon": "#search", "headerSearchIconMobile": "#search_mini_form > .field > .label", "headerSearchField": "#search", - "searchSuggestions": ".qs-option-name" + "searchSuggestions": "#search_autocomplete", + "resultContainer": ".products.list.items.product-items" } diff --git a/cypress/integration/luma/products/product.spec.js b/cypress/integration/luma/products/product.spec.js index ea46687..186f448 100644 --- a/cypress/integration/luma/products/product.spec.js +++ b/cypress/integration/luma/products/product.spec.js @@ -8,7 +8,6 @@ describe('Simple Product test suite', () => { cy.intercept('**/customer/section/load/?sections=*') .as('loadSections') cy.visit(product.simpleProductUrl) - cy.wait('@loadSections') }) it('Can see a title and image for the product', () => { @@ -46,12 +45,13 @@ describe('Simple Product test suite', () => { }) - it('Can see breadcrumbs', () => { + it.skip('Can see breadcrumbs', () => { cy.get(selectors.breadCrumbItems) .should('have.length.gte', 2) }) it('Can\'t add a product to a wishlist when the user in not logged in', () => { + cy.wait(1000) cy.get(selectors.addToWishlistButtonGuest) .first() .click() @@ -106,7 +106,8 @@ describe('Simple Product test suite', () => { .should('have.value', '2') }) - it('Can find products in the related products list', () => { + // No related products in sample data + it.skip('Can find products in the related products list', () => { cy.get(selectors.relatedProductsTitle) .should('exist') .should('contain.text', 'Related Products') @@ -120,7 +121,6 @@ describe('Configurable products test suite', () => { cy.intercept('**/customer/section/load/?sections=*') .as('loadSections') cy.visit(product.configurableProductUrl) - cy.wait('@loadSections') }) it('Can\'t add a configurable product to the cart when no configuration is selected', () => { @@ -131,19 +131,20 @@ describe('Configurable products test suite', () => { }) it('Can select swatch product attributes', () => { - cy.get(selectors.productSwatchAttributeSelector) + cy.get(selectors.productAttributeSelector) .eq(0).find('div').first().click() - cy.get(selectors.productSwatchAttributeSelector) + cy.get(selectors.productAttributeSelector) .eq(0).find('div').first() .should('have.class', 'selected') - cy.get(selectors.productSwatchAttributeSelector) + cy.get(selectors.productAttributeSelector) .eq(1).find('div').first().click() - cy.get(selectors.productSwatchAttributeSelector) + cy.get(selectors.productAttributeSelector) .eq(1).find('div').first() .should('have.class', 'selected') }) - it('Can select product options', () => { + // No selectable product option in sample data + it.skip('Can select product options', () => { cy.get('#product-options-wrapper .field.configurable select') .first() .select(product.configurableOption) diff --git a/cypress/integration/luma/search/product-searches.spec.js b/cypress/integration/luma/search/product-searches.spec.js index e6a6d3b..4c16a07 100644 --- a/cypress/integration/luma/search/product-searches.spec.js +++ b/cypress/integration/luma/search/product-searches.spec.js @@ -25,7 +25,7 @@ describe('Perform searches', () => { Search.search(searchLuma.searchTerm) cy.get(selectors.pageHeader) .should('have.text', `Search results for: '${searchLuma.searchTerm}'`) - cy.get(`${selectors.resultContainer} ${selectors.resultItem}`) + cy.get(selectors.resultContainer) .should('have.length.gt', 0) })