Fix flaky tests for gift cards (#1938)
* fix gift cards * add new command to search elements on table * remove unused imports
This commit is contained in:
parent
40d9575cad
commit
8bc2931679
7 changed files with 112 additions and 135 deletions
|
@ -2,7 +2,6 @@
|
|||
import faker from "faker";
|
||||
|
||||
import { GIFT_CARD_LIST } from "../../../elements/catalog/giftCard/giftCardList";
|
||||
import { urlList } from "../../../fixtures/urlList";
|
||||
import { completeCheckout } from "../../../support/api/requests/Checkout";
|
||||
import {
|
||||
createGiftCard,
|
||||
|
@ -20,14 +19,11 @@ import {
|
|||
purchaseProductWithPromoCode
|
||||
} from "../../../support/api/utils/ordersUtils";
|
||||
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith
|
||||
} from "../../../support/api/utils/shippingUtils";
|
||||
import { deleteShippingStartsWith } from "../../../support/api/utils/shippingUtils";
|
||||
import filterTests from "../../../support/filterTests";
|
||||
import {
|
||||
changeGiftCardActiveStatus,
|
||||
selectGiftCard
|
||||
enterAndSelectGiftCards
|
||||
} from "../../../support/pages/catalog/giftCardPage";
|
||||
|
||||
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||
|
@ -36,81 +32,38 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
const productPrice = 50;
|
||||
const shippingPrice = 50;
|
||||
const email = "example@example.com";
|
||||
|
||||
let defaultChannel;
|
||||
let productType;
|
||||
let attribute;
|
||||
let category;
|
||||
let shippingMethod;
|
||||
let variants;
|
||||
let address;
|
||||
let dataForCheckout;
|
||||
const giftCardData = {
|
||||
amount: 150,
|
||||
currency: "USD"
|
||||
};
|
||||
|
||||
let defaultChannel;
|
||||
let address;
|
||||
let dataForCheckout;
|
||||
|
||||
before(() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
deleteGiftCardsWithTagStartsWith(startsWith);
|
||||
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
productType: productTypeResp,
|
||||
attribute: attributeResp,
|
||||
category: categoryResp
|
||||
}) => {
|
||||
productType = productTypeResp;
|
||||
attribute = attributeResp;
|
||||
category = categoryResp;
|
||||
|
||||
channelsUtils.getDefaultChannel();
|
||||
}
|
||||
)
|
||||
.then(channel => {
|
||||
defaultChannel = channel;
|
||||
cy.fixture("addresses");
|
||||
})
|
||||
.then(addresses => {
|
||||
address = addresses.plAddress;
|
||||
createShipping({
|
||||
channelId: defaultChannel.id,
|
||||
name,
|
||||
address,
|
||||
price: shippingPrice
|
||||
});
|
||||
})
|
||||
.then(
|
||||
({ shippingMethod: shippingMethodResp, warehouse: warehouse }) => {
|
||||
shippingMethod = shippingMethodResp;
|
||||
productsUtils.createProductInChannel({
|
||||
name,
|
||||
channelId: defaultChannel.id,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice
|
||||
});
|
||||
}
|
||||
)
|
||||
.then(({ variantsList: variantsResp }) => {
|
||||
variants = variantsResp;
|
||||
.createProductWithShipping({ name, shippingPrice, productPrice })
|
||||
.then(resp => {
|
||||
defaultChannel = resp.defaultChannel;
|
||||
address = resp.address;
|
||||
|
||||
dataForCheckout = {
|
||||
address,
|
||||
email,
|
||||
auth: "token",
|
||||
channelSlug: defaultChannel.slug,
|
||||
shippingMethodName: shippingMethod.name,
|
||||
variantsList: variants
|
||||
shippingMethodName: resp.shippingMethod.name,
|
||||
variantsList: resp.variantsList
|
||||
};
|
||||
});
|
||||
});
|
||||
|
@ -122,6 +75,7 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
it("should be able to enable gift card and use it in checkout. TC: SALEOR_1006", () => {
|
||||
const expectedGiftCardBalance =
|
||||
giftCardData.amount - productPrice - shippingPrice;
|
||||
|
||||
giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
|
||||
let giftCard;
|
||||
|
||||
|
@ -198,14 +152,13 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
})
|
||||
.then(giftCard => {
|
||||
secondGiftCard = giftCard;
|
||||
cy.visit(urlList.giftCards).waitForProgressBarToNotExist();
|
||||
selectGiftCard(firstGiftCard.id);
|
||||
selectGiftCard(secondGiftCard.id)
|
||||
.addAliasToGraphRequest("GiftCardBulkDeactivate")
|
||||
|
||||
enterAndSelectGiftCards([firstGiftCard.id, secondGiftCard.id]);
|
||||
cy.addAliasToGraphRequest("GiftCardBulkDeactivate")
|
||||
.get(GIFT_CARD_LIST.deactivateGiftCardButton)
|
||||
.click()
|
||||
.waitForRequestAndCheckIfNoErrors("@GiftCardBulkDeactivate")
|
||||
.confirmationMessageShouldDisappear();
|
||||
.confirmationMessageShouldAppear();
|
||||
dataForCheckout.voucherCode = firstGiftCard.code;
|
||||
createCheckoutWithDisabledGiftCard(dataForCheckout);
|
||||
dataForCheckout.voucherCode = secondGiftCard.code;
|
||||
|
@ -252,14 +205,12 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
})
|
||||
.then(giftCard => {
|
||||
secondGiftCard = giftCard;
|
||||
cy.visit(urlList.giftCards).waitForProgressBarToNotExist();
|
||||
selectGiftCard(firstGiftCard.id);
|
||||
selectGiftCard(secondGiftCard.id)
|
||||
.addAliasToGraphRequest("GiftCardBulkActivate")
|
||||
enterAndSelectGiftCards([firstGiftCard.id, secondGiftCard.id]);
|
||||
cy.addAliasToGraphRequest("GiftCardBulkActivate")
|
||||
.get(GIFT_CARD_LIST.activateGiftCardButton)
|
||||
.click()
|
||||
.waitForRequestAndCheckIfNoErrors("@GiftCardBulkActivate")
|
||||
.confirmationMessageShouldDisappear();
|
||||
.confirmationMessageShouldAppear();
|
||||
dataForCheckout.voucherCode = firstGiftCard.code;
|
||||
purchaseProductWithActiveGiftCard({
|
||||
giftCard: firstGiftCard,
|
||||
|
|
|
@ -15,7 +15,6 @@ import * as channelsUtils from "../../../support/api/utils/channelsUtils";
|
|||
import * as shippingUtils from "../../../support/api/utils/shippingUtils";
|
||||
import filterTests from "../../../support/filterTests";
|
||||
import { getCurrencyAndAmountInString } from "../../../support/formatData/formatCurrencyAmount";
|
||||
import { getFormattedCurrencyAmount } from "../../../support/formatData/formatCurrencyAmount";
|
||||
import { enterHomePageChangeChannelAndReturn } from "../../../support/pages/channelsPage";
|
||||
import {
|
||||
enterAndSelectShippings,
|
||||
|
|
|
@ -6,3 +6,7 @@ Cypress.Commands.add("confirmationMessageShouldDisappear", () => {
|
|||
.get(SHARED_ELEMENTS.notificationSuccess)
|
||||
.should("not.exist");
|
||||
});
|
||||
|
||||
Cypress.Commands.add("confirmationMessageShouldAppear", () => {
|
||||
cy.get(SHARED_ELEMENTS.notificationSuccess).should("be.visible");
|
||||
});
|
||||
|
|
|
@ -1,23 +1,6 @@
|
|||
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
|
||||
|
||||
Cypress.Commands.add("findElementOnTable", (elementName, alias) => {
|
||||
cy.get(SHARED_ELEMENTS.skeleton).should("not.exist");
|
||||
cy.getTextFromElement(SHARED_ELEMENTS.table).then(tableText => {
|
||||
if (tableText.includes(elementName)) {
|
||||
cy.contains(SHARED_ELEMENTS.tableRow, elementName).click({ force: true });
|
||||
} else {
|
||||
cy.addAliasToGraphRequest(alias);
|
||||
cy.get(BUTTON_SELECTORS.nextPaginationButton).click();
|
||||
if (alias) {
|
||||
cy.wait(`@${alias}`);
|
||||
}
|
||||
cy.waitForProgressBarToNotExist();
|
||||
cy.findElementOnTable(elementName, alias);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("searchInTable", query => {
|
||||
cy.get(SHARED_ELEMENTS.searchInput)
|
||||
.type(query)
|
||||
|
@ -25,3 +8,62 @@ Cypress.Commands.add("searchInTable", query => {
|
|||
.should("be.visible")
|
||||
.waitForProgressBarToNotExist();
|
||||
});
|
||||
|
||||
// This command is searching for element/s on table, and then make an action on this element/s (select checkbox, or click)
|
||||
// Before this command execute cy.addAliasToGraphRequest(), same alias pass as elementsGraphqlAlias parameter
|
||||
// elementsName is for example "shippingZones", pass elements ids in array, or single element id in elementsIds
|
||||
// action function is click or select checkbox on table with parameter id
|
||||
Cypress.Commands.add(
|
||||
"findElementsAndMakeActionOnTable",
|
||||
({
|
||||
elementsGraphqlAlias,
|
||||
elementsName,
|
||||
elementsIds,
|
||||
counter = 0,
|
||||
actionFunction
|
||||
}) => {
|
||||
cy.wait(`@${elementsGraphqlAlias}`)
|
||||
.its("response.body")
|
||||
.then(body => {
|
||||
let shippingResults;
|
||||
if (Array.isArray(body)) {
|
||||
shippingResults = body.find(element => {
|
||||
if (element.data[elementsName]) {
|
||||
return element;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
shippingResults = body;
|
||||
}
|
||||
const shippingList = shippingResults.data[elementsName].edges;
|
||||
const notSelectedElements = [];
|
||||
elementsIds = Array.isArray(elementsIds) ? elementsIds : [elementsIds];
|
||||
elementsIds.forEach(id => {
|
||||
const isShippingOnList = shippingList.find(
|
||||
element => element.node.id === id
|
||||
);
|
||||
if (isShippingOnList) {
|
||||
actionFunction(id);
|
||||
counter += 1;
|
||||
} else {
|
||||
notSelectedElements.push(id);
|
||||
}
|
||||
if (counter === elementsIds.length) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (counter === elementsIds.length) {
|
||||
return;
|
||||
}
|
||||
cy.get(BUTTON_SELECTORS.nextPaginationButton)
|
||||
.click()
|
||||
.findElementsAndMakeActionOnTable({
|
||||
elementsIds: notSelectedElements,
|
||||
actionFunction,
|
||||
counter,
|
||||
elementsGraphqlAlias,
|
||||
elementsName
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
7
cypress/support/index.d.ts
vendored
7
cypress/support/index.d.ts
vendored
|
@ -46,7 +46,12 @@ declare namespace Cypress {
|
|||
sendRequestWithQuery(query: string): Chainable<any>;
|
||||
fillMultiSelect(selectSelector: string, option: string): Chainable<any>;
|
||||
createNewOption(selectSelector: string, newOption: string): Chainable<any>;
|
||||
findElementOnTable(elementName: string): Chainable<any>;
|
||||
findElementsAndMakeActionOnTable({
|
||||
elementsGraphqlAlias: string,
|
||||
elementsName: string,
|
||||
elementsIds: string,
|
||||
actionFunction
|
||||
}): Chainable<any>;
|
||||
searchInTable(query: string): Chainable<any>;
|
||||
waitForRequestAndCheckIfNoErrors(alias: string): Chainable<any>;
|
||||
deleteElementWithReqAlias(alias: string): Chainable<any>;
|
||||
|
|
|
@ -68,7 +68,7 @@ export function changeGiftCardActiveStatus(giftCardId) {
|
|||
cy.visit(giftCardDetailsUrl(giftCardId))
|
||||
.get(GIFT_CARD_UPDATE.changeActiveStatusButton)
|
||||
.click()
|
||||
.confirmationMessageShouldDisappear();
|
||||
.confirmationMessageShouldAppear();
|
||||
}
|
||||
|
||||
export function selectGiftCard(giftCardId) {
|
||||
|
@ -77,3 +77,15 @@ export function selectGiftCard(giftCardId) {
|
|||
.find(GIFT_CARD_LIST.selectGiftCardCheckbox)
|
||||
.click();
|
||||
}
|
||||
|
||||
export function enterAndSelectGiftCards(giftCardsIds) {
|
||||
const alias = "GiftCardList";
|
||||
cy.addAliasToGraphRequest(alias)
|
||||
.visit(urlList.giftCards)
|
||||
.findElementsAndMakeActionOnTable({
|
||||
elementsGraphqlAlias: alias,
|
||||
elementsName: "giftCards",
|
||||
elementsIds: giftCardsIds,
|
||||
actionFunction: selectGiftCard
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||
import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements";
|
||||
import {
|
||||
SHIPPING_ZONE_CHECKBOX,
|
||||
SHIPPING_ZONE_NAME
|
||||
|
@ -10,47 +8,13 @@ export function enterAndSelectShippings(
|
|||
shippingIds,
|
||||
actionFunction = selectShippingZone
|
||||
) {
|
||||
cy.addAliasToGraphRequest("ShippingZones").visit(urlList.shippingMethods);
|
||||
selectShippingsOnTable(shippingIds, actionFunction);
|
||||
}
|
||||
|
||||
export function selectShippingsOnTable(
|
||||
shippingIds,
|
||||
actionFunction = selectShippingZone,
|
||||
counter = 0
|
||||
) {
|
||||
cy.get(SHARED_ELEMENTS.skeleton)
|
||||
.should("not.exist")
|
||||
.wait("@ShippingZones")
|
||||
.its("response.body")
|
||||
.then(body => {
|
||||
const shippingResults = body.find(element => {
|
||||
if (element.data.shippingZones) {
|
||||
return element;
|
||||
}
|
||||
});
|
||||
const shippingList = shippingResults.data.shippingZones.edges;
|
||||
const notSelectedShippings = [];
|
||||
shippingIds = Array.isArray(shippingIds) ? shippingIds : [shippingIds];
|
||||
shippingIds.forEach(id => {
|
||||
const isShippingOnList = shippingList.find(
|
||||
element => element.node.id === id
|
||||
);
|
||||
if (isShippingOnList) {
|
||||
actionFunction(id);
|
||||
counter += 1;
|
||||
} else {
|
||||
notSelectedShippings.push(id);
|
||||
}
|
||||
if (counter === shippingIds.length) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (counter === shippingIds.length) {
|
||||
return;
|
||||
}
|
||||
cy.get(BUTTON_SELECTORS.nextPaginationButton).click();
|
||||
selectShippingsOnTable(notSelectedShippings, actionFunction, counter);
|
||||
cy.addAliasToGraphRequest("ShippingZones")
|
||||
.visit(urlList.shippingMethods)
|
||||
.findElementsAndMakeActionOnTable({
|
||||
elementsGraphqlAlias: "ShippingZones",
|
||||
elementsName: "shippingZones",
|
||||
elementsIds: shippingIds,
|
||||
actionFunction
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue