Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor luma tests #48

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
6 changes: 3 additions & 3 deletions cypress/fixtures/account.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"customer": {
"customer": {
"email": "test@cypress-testing.com",
"email": "roni_cost@example.com",
"firstname": "Test",
"lastname": "Test"
},
"password": "Test!234"
"password": "[email protected]"
},
"customerInfo": {
"city": "Groningen",
"country": "Netherlands",
"country": "NL",
"phone": "1234567890",
"state": "Groningen",
"streetAddress": "Teststraat 1",
Expand Down
6 changes: 4 additions & 2 deletions cypress/fixtures/category.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"categoryUrl": "/women/tops-women.html",
"category": "Women",
"categoryUrl": "/men/tops-men.html",
"category": "Tops",
"subCategory": "Tops",
"filterBy": "Color",
"filterQueryParam": "color",
"selectByPrice": "Price"
}
2 changes: 1 addition & 1 deletion cypress/fixtures/luma/product.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions cypress/fixtures/luma/search.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"productCategory": "hoodie",
"singleProduct": "Didi",
"singleProductName": "Didi Sport Watch",
"searchTerm": "Watch",
"noResults": "1234abcd",
"getHint": "didi",
"hintResult": "Didi"
"hintResult": "watch"
}
59 changes: 19 additions & 40 deletions cypress/fixtures/luma/selectors/account.json
Original file line number Diff line number Diff line change
@@ -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"
}
42 changes: 19 additions & 23 deletions cypress/fixtures/luma/selectors/cart.json
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 5 additions & 2 deletions cypress/fixtures/luma/selectors/category.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"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",
"categoryProductListWrapper": ".modes-mode.mode-list",
"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-item",
"filterByLabel": ".filter-options .swatch-attribute-options a .color"
}
97 changes: 41 additions & 56 deletions cypress/fixtures/luma/selectors/checkout.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,43 @@
{
"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",
"customerEmailFieldset": "#customer-email-fieldset",
"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": "#customer-email-error",
"addToCartButton": "#product-addtocart-button",
"checkoutEmailLabel": "#customer-email",
"checkoutPasswordInput": "input#customer-password",
"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": "table.totals tr.totals:nth-child(2) .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-checkmo]",
"shippingTotal": "tr.totals.shipping .amount",
"continueToPayment": "#shipping-method-buttons-container button",
"updateBillingAddress": ".payment-method-billing-address button.action.action-update"
}
3 changes: 2 additions & 1 deletion cypress/fixtures/luma/selectors/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
48 changes: 22 additions & 26 deletions cypress/integration/luma/cart/cart.spec.js
Original file line number Diff line number Diff line change
@@ -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/default/V1/guest-carts/*/estimate-shipping-methods')
.as('estimateShippingMethod')

Cart.addProductToCart(productLuma.simpleProductUrl);
cy.visit(cartLuma.cartUrl);
cy.wait('@estimateShippingMethod')
});

it('Can change the quantity in the cart', () => {
Expand All @@ -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.')
});
});
Loading