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 faker from "faker";
|
||||||
|
|
||||||
import { GIFT_CARD_LIST } from "../../../elements/catalog/giftCard/giftCardList";
|
import { GIFT_CARD_LIST } from "../../../elements/catalog/giftCard/giftCardList";
|
||||||
import { urlList } from "../../../fixtures/urlList";
|
|
||||||
import { completeCheckout } from "../../../support/api/requests/Checkout";
|
import { completeCheckout } from "../../../support/api/requests/Checkout";
|
||||||
import {
|
import {
|
||||||
createGiftCard,
|
createGiftCard,
|
||||||
|
@ -20,14 +19,11 @@ import {
|
||||||
purchaseProductWithPromoCode
|
purchaseProductWithPromoCode
|
||||||
} from "../../../support/api/utils/ordersUtils";
|
} from "../../../support/api/utils/ordersUtils";
|
||||||
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
||||||
import {
|
import { deleteShippingStartsWith } from "../../../support/api/utils/shippingUtils";
|
||||||
createShipping,
|
|
||||||
deleteShippingStartsWith
|
|
||||||
} from "../../../support/api/utils/shippingUtils";
|
|
||||||
import filterTests from "../../../support/filterTests";
|
import filterTests from "../../../support/filterTests";
|
||||||
import {
|
import {
|
||||||
changeGiftCardActiveStatus,
|
changeGiftCardActiveStatus,
|
||||||
selectGiftCard
|
enterAndSelectGiftCards
|
||||||
} from "../../../support/pages/catalog/giftCardPage";
|
} from "../../../support/pages/catalog/giftCardPage";
|
||||||
|
|
||||||
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||||
|
@ -36,81 +32,38 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||||
const productPrice = 50;
|
const productPrice = 50;
|
||||||
const shippingPrice = 50;
|
const shippingPrice = 50;
|
||||||
const email = "example@example.com";
|
const email = "example@example.com";
|
||||||
|
|
||||||
let defaultChannel;
|
|
||||||
let productType;
|
|
||||||
let attribute;
|
|
||||||
let category;
|
|
||||||
let shippingMethod;
|
|
||||||
let variants;
|
|
||||||
let address;
|
|
||||||
let dataForCheckout;
|
|
||||||
const giftCardData = {
|
const giftCardData = {
|
||||||
amount: 150,
|
amount: 150,
|
||||||
currency: "USD"
|
currency: "USD"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let defaultChannel;
|
||||||
|
let address;
|
||||||
|
let dataForCheckout;
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
|
const name = `${startsWith}${faker.datatype.number()}`;
|
||||||
|
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
|
||||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||||
productsUtils.deleteProductsStartsWith(startsWith);
|
productsUtils.deleteProductsStartsWith(startsWith);
|
||||||
deleteShippingStartsWith(startsWith);
|
deleteShippingStartsWith(startsWith);
|
||||||
deleteGiftCardsWithTagStartsWith(startsWith);
|
deleteGiftCardsWithTagStartsWith(startsWith);
|
||||||
|
|
||||||
const name = `${startsWith}${faker.datatype.number()}`;
|
|
||||||
|
|
||||||
productsUtils
|
productsUtils
|
||||||
.createTypeAttributeAndCategoryForProduct({ name })
|
.createProductWithShipping({ name, shippingPrice, productPrice })
|
||||||
.then(
|
.then(resp => {
|
||||||
({
|
defaultChannel = resp.defaultChannel;
|
||||||
productType: productTypeResp,
|
address = resp.address;
|
||||||
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;
|
|
||||||
|
|
||||||
dataForCheckout = {
|
dataForCheckout = {
|
||||||
address,
|
address,
|
||||||
email,
|
email,
|
||||||
auth: "token",
|
auth: "token",
|
||||||
channelSlug: defaultChannel.slug,
|
channelSlug: defaultChannel.slug,
|
||||||
shippingMethodName: shippingMethod.name,
|
shippingMethodName: resp.shippingMethod.name,
|
||||||
variantsList: variants
|
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", () => {
|
it("should be able to enable gift card and use it in checkout. TC: SALEOR_1006", () => {
|
||||||
const expectedGiftCardBalance =
|
const expectedGiftCardBalance =
|
||||||
giftCardData.amount - productPrice - shippingPrice;
|
giftCardData.amount - productPrice - shippingPrice;
|
||||||
|
|
||||||
giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
|
giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
|
||||||
let giftCard;
|
let giftCard;
|
||||||
|
|
||||||
|
@ -198,14 +152,13 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||||
})
|
})
|
||||||
.then(giftCard => {
|
.then(giftCard => {
|
||||||
secondGiftCard = giftCard;
|
secondGiftCard = giftCard;
|
||||||
cy.visit(urlList.giftCards).waitForProgressBarToNotExist();
|
|
||||||
selectGiftCard(firstGiftCard.id);
|
enterAndSelectGiftCards([firstGiftCard.id, secondGiftCard.id]);
|
||||||
selectGiftCard(secondGiftCard.id)
|
cy.addAliasToGraphRequest("GiftCardBulkDeactivate")
|
||||||
.addAliasToGraphRequest("GiftCardBulkDeactivate")
|
|
||||||
.get(GIFT_CARD_LIST.deactivateGiftCardButton)
|
.get(GIFT_CARD_LIST.deactivateGiftCardButton)
|
||||||
.click()
|
.click()
|
||||||
.waitForRequestAndCheckIfNoErrors("@GiftCardBulkDeactivate")
|
.waitForRequestAndCheckIfNoErrors("@GiftCardBulkDeactivate")
|
||||||
.confirmationMessageShouldDisappear();
|
.confirmationMessageShouldAppear();
|
||||||
dataForCheckout.voucherCode = firstGiftCard.code;
|
dataForCheckout.voucherCode = firstGiftCard.code;
|
||||||
createCheckoutWithDisabledGiftCard(dataForCheckout);
|
createCheckoutWithDisabledGiftCard(dataForCheckout);
|
||||||
dataForCheckout.voucherCode = secondGiftCard.code;
|
dataForCheckout.voucherCode = secondGiftCard.code;
|
||||||
|
@ -252,14 +205,12 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||||
})
|
})
|
||||||
.then(giftCard => {
|
.then(giftCard => {
|
||||||
secondGiftCard = giftCard;
|
secondGiftCard = giftCard;
|
||||||
cy.visit(urlList.giftCards).waitForProgressBarToNotExist();
|
enterAndSelectGiftCards([firstGiftCard.id, secondGiftCard.id]);
|
||||||
selectGiftCard(firstGiftCard.id);
|
cy.addAliasToGraphRequest("GiftCardBulkActivate")
|
||||||
selectGiftCard(secondGiftCard.id)
|
|
||||||
.addAliasToGraphRequest("GiftCardBulkActivate")
|
|
||||||
.get(GIFT_CARD_LIST.activateGiftCardButton)
|
.get(GIFT_CARD_LIST.activateGiftCardButton)
|
||||||
.click()
|
.click()
|
||||||
.waitForRequestAndCheckIfNoErrors("@GiftCardBulkActivate")
|
.waitForRequestAndCheckIfNoErrors("@GiftCardBulkActivate")
|
||||||
.confirmationMessageShouldDisappear();
|
.confirmationMessageShouldAppear();
|
||||||
dataForCheckout.voucherCode = firstGiftCard.code;
|
dataForCheckout.voucherCode = firstGiftCard.code;
|
||||||
purchaseProductWithActiveGiftCard({
|
purchaseProductWithActiveGiftCard({
|
||||||
giftCard: firstGiftCard,
|
giftCard: firstGiftCard,
|
||||||
|
|
|
@ -15,7 +15,6 @@ import * as channelsUtils from "../../../support/api/utils/channelsUtils";
|
||||||
import * as shippingUtils from "../../../support/api/utils/shippingUtils";
|
import * as shippingUtils from "../../../support/api/utils/shippingUtils";
|
||||||
import filterTests from "../../../support/filterTests";
|
import filterTests from "../../../support/filterTests";
|
||||||
import { getCurrencyAndAmountInString } from "../../../support/formatData/formatCurrencyAmount";
|
import { getCurrencyAndAmountInString } from "../../../support/formatData/formatCurrencyAmount";
|
||||||
import { getFormattedCurrencyAmount } from "../../../support/formatData/formatCurrencyAmount";
|
|
||||||
import { enterHomePageChangeChannelAndReturn } from "../../../support/pages/channelsPage";
|
import { enterHomePageChangeChannelAndReturn } from "../../../support/pages/channelsPage";
|
||||||
import {
|
import {
|
||||||
enterAndSelectShippings,
|
enterAndSelectShippings,
|
||||||
|
|
|
@ -6,3 +6,7 @@ Cypress.Commands.add("confirmationMessageShouldDisappear", () => {
|
||||||
.get(SHARED_ELEMENTS.notificationSuccess)
|
.get(SHARED_ELEMENTS.notificationSuccess)
|
||||||
.should("not.exist");
|
.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 { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||||
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
|
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 => {
|
Cypress.Commands.add("searchInTable", query => {
|
||||||
cy.get(SHARED_ELEMENTS.searchInput)
|
cy.get(SHARED_ELEMENTS.searchInput)
|
||||||
.type(query)
|
.type(query)
|
||||||
|
@ -25,3 +8,62 @@ Cypress.Commands.add("searchInTable", query => {
|
||||||
.should("be.visible")
|
.should("be.visible")
|
||||||
.waitForProgressBarToNotExist();
|
.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>;
|
sendRequestWithQuery(query: string): Chainable<any>;
|
||||||
fillMultiSelect(selectSelector: string, option: string): Chainable<any>;
|
fillMultiSelect(selectSelector: string, option: string): Chainable<any>;
|
||||||
createNewOption(selectSelector: string, newOption: 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>;
|
searchInTable(query: string): Chainable<any>;
|
||||||
waitForRequestAndCheckIfNoErrors(alias: string): Chainable<any>;
|
waitForRequestAndCheckIfNoErrors(alias: string): Chainable<any>;
|
||||||
deleteElementWithReqAlias(alias: string): Chainable<any>;
|
deleteElementWithReqAlias(alias: string): Chainable<any>;
|
||||||
|
|
|
@ -68,7 +68,7 @@ export function changeGiftCardActiveStatus(giftCardId) {
|
||||||
cy.visit(giftCardDetailsUrl(giftCardId))
|
cy.visit(giftCardDetailsUrl(giftCardId))
|
||||||
.get(GIFT_CARD_UPDATE.changeActiveStatusButton)
|
.get(GIFT_CARD_UPDATE.changeActiveStatusButton)
|
||||||
.click()
|
.click()
|
||||||
.confirmationMessageShouldDisappear();
|
.confirmationMessageShouldAppear();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectGiftCard(giftCardId) {
|
export function selectGiftCard(giftCardId) {
|
||||||
|
@ -77,3 +77,15 @@ export function selectGiftCard(giftCardId) {
|
||||||
.find(GIFT_CARD_LIST.selectGiftCardCheckbox)
|
.find(GIFT_CARD_LIST.selectGiftCardCheckbox)
|
||||||
.click();
|
.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 {
|
import {
|
||||||
SHIPPING_ZONE_CHECKBOX,
|
SHIPPING_ZONE_CHECKBOX,
|
||||||
SHIPPING_ZONE_NAME
|
SHIPPING_ZONE_NAME
|
||||||
|
@ -10,47 +8,13 @@ export function enterAndSelectShippings(
|
||||||
shippingIds,
|
shippingIds,
|
||||||
actionFunction = selectShippingZone
|
actionFunction = selectShippingZone
|
||||||
) {
|
) {
|
||||||
cy.addAliasToGraphRequest("ShippingZones").visit(urlList.shippingMethods);
|
cy.addAliasToGraphRequest("ShippingZones")
|
||||||
selectShippingsOnTable(shippingIds, actionFunction);
|
.visit(urlList.shippingMethods)
|
||||||
}
|
.findElementsAndMakeActionOnTable({
|
||||||
|
elementsGraphqlAlias: "ShippingZones",
|
||||||
export function selectShippingsOnTable(
|
elementsName: "shippingZones",
|
||||||
shippingIds,
|
elementsIds: shippingIds,
|
||||||
actionFunction = selectShippingZone,
|
actionFunction
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue