Skip to content

Commit

Permalink
test: refactor e2e tools to reduce duplication (#17630)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHi authored Jul 12, 2023
1 parent 211bede commit a2c3715
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as cart from '../../../helpers/cart';
import * as configuration from '../../../helpers/product-configurator';
import * as textfieldConfiguration from '../../../helpers/textfield-configuration';
import * as common from '../../../helpers/common';

const electronicsShop = 'electronics-spa';
const testProduct = '1934793';
Expand Down Expand Up @@ -46,8 +47,8 @@ context('Textfield Configuration', () => {
electronicsShop,
testProduct
);
textfieldConfiguration.clickOnAddToCartBtnOnPD();
textfieldConfiguration.clickOnViewCartBtnOnPD();
common.clickOnAddToCartBtnOnPD();
common.clickOnViewCartBtnOnPD();
cart.verifyCartNotEmpty();
textfieldConfiguration.clickOnEditConfigurationLink(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as configurationCartVc from '../../../helpers/product-configurator-cart
import * as configurationOverview from '../../../helpers/product-configurator-overview';
import * as configurationOverviewVc from '../../../helpers/product-configurator-overview-vc';
import * as configurationVc from '../../../helpers/product-configurator-vc';
import * as common from '../../../helpers/common';

const electronicsShop = 'electronics-spa';
const testProductMultiLevel = 'CONF_HOME_THEATER_ML';
Expand Down Expand Up @@ -98,8 +99,8 @@ context('Product Configuration', () => {
it('should be able to navigate from the cart after adding product directly to the cart', () => {
clickAllowAllFromBanner();
configuration.searchForProduct(testProductMultiLevel);
configuration.clickOnAddToCartBtnOnPD();
configuration.clickOnViewCartBtnOnPD();
common.clickOnAddToCartBtnOnPD();
common.clickOnViewCartBtnOnPD();
cart.verifyCartNotEmpty();
configurationCart.clickOnEditConfigurationLink(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as configuration from '../../../helpers/product-configurator';
import { clickAllowAllFromBanner } from '../../../helpers/anonymous-consents';
import * as configurationOverviewVc from '../../../helpers/product-configurator-overview-vc';
import * as configurationVc from '../../../helpers/product-configurator-vc';
import * as common from '../../../helpers/common';

const electronicsShop = 'electronics-spa';
const testProduct = 'CONF_CAMERA_SL';
Expand Down Expand Up @@ -96,7 +97,7 @@ context('Product Configuration', () => {

it('should be able to navigate from the product details page', () => {
clickAllowAllFromBanner();
configurationVc.goToPDPage(electronicsShop, testProduct);
common.goToPDPage(electronicsShop, testProduct);
configurationVc.clickOnConfigureBtnInCatalog(testProduct);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import * as configuration from '../../../helpers/product-configurator';
import * as configurationCpq from '../../../helpers/product-configurator-cpq';
import * as configurationOverview from '../../../helpers/product-configurator-overview';
import * as configurationOverviewCpq from '../../../helpers/product-configurator-overview-cpq';
import * as configurationCart from '../../../helpers/product-configurator-cart';
import * as configurationCartCpq from '../../../helpers/product-configurator-cart-cpq';
import * as common from '../../../helpers/common';
import { clickAllowAllFromBanner } from '../../../helpers/anonymous-consents';

const POWERTOOLS = 'powertools-spa';
Expand Down Expand Up @@ -109,14 +108,14 @@ context('CPQ Configuration', () => {
});

it('should be able to navigate from the product details page', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
common.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
configurationCpq.clickOnConfigureBtnInCatalog();
});
});

describe('Handling different UI type', () => {
it('should support radio button attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_CUPS, RADGRP);
Expand All @@ -137,7 +136,7 @@ context('CPQ Configuration', () => {
});

it('should support checkbox list attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_MODE, CHKBOX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as configurationOverview from '../../../helpers/product-configurator-ov
import * as configurationOverviewCpq from '../../../helpers/product-configurator-overview-cpq';
import * as configurationCart from '../../../helpers/product-configurator-cart';
import * as configurationCartCpq from '../../../helpers/product-configurator-cart-cpq';
import * as common from '../../../helpers/common';
import { clickAllowAllFromBanner } from '../../../helpers/anonymous-consents';

const POWERTOOLS = 'powertools-spa';
Expand Down Expand Up @@ -127,14 +128,14 @@ testConfig.forEach((config) => {
});

it('should be able to navigate from the product details page', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
common.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
configurationCpq.clickOnConfigureBtnInCatalog();
});
});

describe('Handling different UI type', () => {
it('should support radio button attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_CUPS, RADGRP);
Expand Down Expand Up @@ -165,7 +166,7 @@ testConfig.forEach((config) => {
});

it('should support checkbox list attribute type', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_COF);
common.goToPDPage(POWERTOOLS, PROD_CODE_COF);
configurationCpq.clickOnConfigureBtnInCatalog();

configuration.checkAttributeDisplayed(ATTR_COF_MODE, CHKBOX);
Expand Down Expand Up @@ -555,9 +556,9 @@ testConfig.forEach((config) => {

describe('Configuration Process', () => {
it('should support configuration aspect in product search, cart, checkout and order history', () => {
configurationCpq.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
configuration.clickOnAddToCartBtnOnPD();
configuration.clickOnViewCartBtnOnPD();
common.goToPDPage(POWERTOOLS, PROD_CODE_CAM);
common.clickOnAddToCartBtnOnPD();
common.clickOnViewCartBtnOnPD();

cy.get('cx-mini-cart .count').then((elem) => {
const numberOfCartItems = Number(elem.text());
Expand Down
60 changes: 60 additions & 0 deletions projects/storefrontapp-e2e-cypress/cypress/helpers/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Clicks on 'Add to cart' on the product details page.
*/
export function clickOnAddToCartBtnOnPD(): void {
cy.get('cx-add-to-cart button.btn-primary')
.contains('Add to cart')
.click()
.then(() => {
cy.get('cx-added-to-cart-dialog').should('be.visible');
cy.get('div.cx-dialog-body').should('be.visible');
cy.get('div.cx-dialog-buttons a.btn-primary')
.contains('view cart')
.should('be.visible');
cy.get('div.cx-dialog-buttons a.btn-secondary')
.contains('proceed to checkout')
.should('be.visible');
});
}

/**
* Clicks on 'View Cart' on the product details page.
*/
export function clickOnViewCartBtnOnPD(): void {
cy.get('div.cx-dialog-buttons a.btn-primary')
.contains('view cart')
.click()
.then(() => {
cy.location('pathname').should('contain', '/cart');
cy.get('cx-cart-details').should('be.visible');
});
}

/**
* Navigates to the product detail page.
*
* @param {string} shopName - shop name
* @param {string} productId - Product ID
*/
export function goToPDPage(shopName: string, productId: string): void {
const location = `${shopName}/en/USD/product/${productId}/${productId}`;
cy.visit(location).then(() => {
checkLoadingMsgNotDisplayed();
cy.location('pathname').should('contain', location);
cy.get('.ProductDetailsPageTemplate').should('be.visible');
});
}

/**
* Verifies whether the loading message is not displayed.
*/
export function checkLoadingMsgNotDisplayed(): void {
cy.log('Wait until the loading notification is not displayed anymore');
cy.get('cx-storefront').should('not.contain.value', 'Loading');
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ export function goToCPQConfigurationPage(
});
}

/**
* Navigates to the product detail page.
*
* @param {string} shopName - shop name
* @param {string} productId - Product ID
*/
export function goToPDPage(shopName: string, productId: string): void {
const location = `${shopName}/en/USD/product/${productId}/${productId}`;
cy.visit(location).then(() => {
cy.location('pathname').should('contain', location);
cy.get('.ProductDetailsPageTemplate').should('be.visible');
});
}

/**
* Clicks on 'Add to Cart' button in catalog list.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import * as configuration from './product-configurator';
import * as common from './common';

const addToCartButtonSelector =
'cx-configurator-add-to-cart-button button.cx-add-to-cart-btn';
Expand Down Expand Up @@ -93,21 +94,6 @@ export function registerCreateConfigurationRoute() {
}).as(CREATE_CONFIG_ALIAS.substring(1)); // strip the '@'
}

/**
* Navigates to the product detail page.
*
* @param {string} shopName - shop name
* @param {string} productId - Product ID
*/
export function goToPDPage(shopName: string, productId: string): void {
const location = `${shopName}/en/USD/product/${productId}/${productId}`;
cy.visit(location).then(() => {
checkLoadingMsgNotDisplayed();
cy.location('pathname').should('contain', location);
cy.get('.ProductDetailsPageTemplate').should('be.visible');
});
}

/**
* Navigates to the cart page.
*
Expand All @@ -121,14 +107,6 @@ export function goToCart(shopName: string) {
});
}

/**
* Verifies whether the loading message is not displayed.
*/
export function checkLoadingMsgNotDisplayed(): void {
cy.log('Wait until the loading notification is not displayed anymore');
cy.get('cx-storefront').should('not.contain.value', 'Loading');
}

/**
* Verifies whether the global message is not displayed on the top of the configuration.
*/
Expand Down Expand Up @@ -171,7 +149,7 @@ export function checkGhostAnimationNotDisplayed(): void {
*/
export function checkConfigPageDisplayed(): void {
checkGhostAnimationNotDisplayed();
checkLoadingMsgNotDisplayed();
common.checkLoadingMsgNotDisplayed();
checkGlobalMessageNotDisplayed();
configuration.checkTabBarDisplayed();
configuration.checkGroupTitleDisplayed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import * as login from './login';
import * as configurationCartVc from './product-configurator-cart-vc';
//import * as configurationCart from './product-configurator-cart';
import * as productSearch from './product-search';
import * as common from './common';
import { verifyGlobalMessageAfterRegistration } from './register';

const nextBtnSelector =
Expand Down Expand Up @@ -487,38 +487,6 @@ export function checkHamburgerDisplayed(): void {
).should('be.visible');
}

/**
* Clicks on 'Add to cart' on the product details page.
*/
export function clickOnAddToCartBtnOnPD(): void {
cy.get('cx-add-to-cart button.btn-primary')
.contains('Add to cart')
.click()
.then(() => {
cy.get('cx-added-to-cart-dialog').should('be.visible');
cy.get('div.cx-dialog-body').should('be.visible');
cy.get('div.cx-dialog-buttons a.btn-primary')
.contains('view cart')
.should('be.visible');
cy.get('div.cx-dialog-buttons a.btn-secondary')
.contains('proceed to checkout')
.should('be.visible');
});
}

/**
* Clicks on 'View Cart' on the product details page.
*/
export function clickOnViewCartBtnOnPD(): void {
cy.get('div.cx-dialog-buttons a.btn-primary')
.contains('view cart')
.click()
.then(() => {
cy.location('pathname').should('contain', '/cart');
cy.get('cx-cart-details').should('be.visible');
});
}

/**
* Clicks on 'Proceed to Checkout' on the product details page.
*/
Expand Down Expand Up @@ -569,7 +537,7 @@ export function completeOrderProcess(productName: string): void {
login.loginUser();
cy.wait(tokenAuthRequestAlias).its('response.statusCode').should('eq', 200);
this.searchForProduct(productName);
this.clickOnAddToCartBtnOnPD();
common.clickOnAddToCartBtnOnPD();
this.clickOnProceedToCheckoutBtnOnPD();
configurationCartVc.checkout();
//TODO: activate after 22.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,42 +144,6 @@ export function clickAddToCartButton(shopName: string): void {
});
}

/**
* Clicks 'Add to Cart' button on the product details page.
*/
export function clickOnAddToCartBtnOnPD(): void {
cy.log("Clicks 'Add to Cart' button on the product details page");
cy.get('cx-add-to-cart button.btn-primary')
.contains('Add to cart')
.click()
.then(() => {
cy.get('cx-added-to-cart-dialog').should('be.visible');
cy.get('div.cx-dialog-body').should('be.visible');
cy.get('div.cx-dialog-buttons a.btn-primary')
.contains('view cart')
.should('be.visible');
cy.get('div.cx-dialog-buttons a.btn-secondary')
.contains('proceed to checkout')
.should('be.visible');
});
}

/**
* Clicks on 'View Cart' on the product details page.
*/
export function clickOnViewCartBtnOnPD(): void {
cy.log("Clicks on 'View Cart' on the product details page");
cy.get('div.cx-dialog-buttons a.btn-primary')
.contains('view cart')
.click()
.then(() => {
cy.log("Verify whether 'Cart details section' is visible");
cy.get('cx-cart-details').should('be.visible');
cy.log("Verify whether 'cx-cart-details' is visible");
cy.get('cx-cart-details').should('be.visible');
});
}

/**
* Verifies whether the cart contains the product.
*
Expand Down

0 comments on commit a2c3715

Please sign in to comment.