From 5a14884f9d5366053c6ef998bdbc8475987efbef Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Fri, 17 Dec 2021 12:07:51 +0100 Subject: [PATCH] Fix failing cypress tests (#1671) * fix tests * fix prorders & images * change base url * remove comment --- .../integration/configuration/channels/channels.js | 2 +- .../shippingMethods/channelsInShipping.js | 9 +-------- cypress/integration/configuration/translations.js | 2 +- cypress/integration/discounts/sales/sales.js | 5 ++++- cypress/integration/discounts/vouchers.js | 2 ++ cypress/integration/orders/orders.js | 3 --- .../preorders/createAndEditVariantsInPreorder.js | 2 +- cypress/integration/preorders/stocksAndThreshold.js | 4 ++-- cypress/integration/products/images.js | 10 ++++++---- cypress/support/api/requests/Collections.js | 6 ++++-- cypress/support/api/requests/Product.js | 3 +-- cypress/support/api/utils/catalog/collectionsUtils.js | 7 ++++++- .../customCommands/sharedElementsOperations/tables.js | 11 +++++++---- .../support/pages/catalog/products/VariantsPage.js | 11 +++++++---- 14 files changed, 43 insertions(+), 34 deletions(-) diff --git a/cypress/integration/configuration/channels/channels.js b/cypress/integration/configuration/channels/channels.js index 7aa1eb37d..16e3bdf78 100644 --- a/cypress/integration/configuration/channels/channels.js +++ b/cypress/integration/configuration/channels/channels.js @@ -76,7 +76,7 @@ filterTests({ definedTags: ["all"] }, () => { .waitForProgressBarToNotExist() .get(PRODUCTS_LIST.emptyProductRow) .should("not.exist") - .get(PRODUCTS_LIST.productsList) + .get(PRODUCTS_LIST.productsNames) .first() .click() .get(AVAILABLE_CHANNELS_FORM.menageChannelsButton) diff --git a/cypress/integration/configuration/shippingMethods/channelsInShipping.js b/cypress/integration/configuration/shippingMethods/channelsInShipping.js index 9c49de49e..ced220d08 100644 --- a/cypress/integration/configuration/shippingMethods/channelsInShipping.js +++ b/cypress/integration/configuration/shippingMethods/channelsInShipping.js @@ -91,14 +91,7 @@ filterTests({ definedTags: ["all"] }, () => { .should("be.visible") .waitForProgressBarToNotExist() .addAliasToGraphRequest("ShippingZone") - .getTextFromElement(SHARED_ELEMENTS.table); - }) - .then(tableText => { - if (!tableText.includes(shippingZone.name)) { - cy.get(BUTTON_SELECTORS.nextPaginationButton).click(); - } - cy.contains(shippingZone.name) - .click() + .findElementOnTable(shippingZone.name, "ShippingZones") .waitForRequestAndCheckIfNoErrors("@ShippingZone"); enterHomePageChangeChannelAndReturn(defaultChannel.name); cy.waitForProgressBarToNotBeVisible() diff --git a/cypress/integration/configuration/translations.js b/cypress/integration/configuration/translations.js index 94971de80..7a4010c4f 100644 --- a/cypress/integration/configuration/translations.js +++ b/cypress/integration/configuration/translations.js @@ -37,7 +37,7 @@ filterTests({ definedTags: ["all"], version: "3.1.1" }, () => { cy.visit(urlList.translations) .get(LANGUAGES_LIST.polishLanguageButton) .click() - .findElementOnTable(category.name); + .findElementOnTable(category.name, "CategoryTranslations"); cy.get(ELEMENT_TRANSLATION.editNameButton) .click() .get(SHARED_ELEMENTS.skeleton) diff --git a/cypress/integration/discounts/sales/sales.js b/cypress/integration/discounts/sales/sales.js index 22cbf7a23..2f82ef355 100644 --- a/cypress/integration/discounts/sales/sales.js +++ b/cypress/integration/discounts/sales/sales.js @@ -96,6 +96,7 @@ filterTests({ definedTags: ["all"] }, () => { let variantOnSale; productData.name = productName; + productData.sku = productName; createProductInChannel(productData) .then(({ product, variantsList }) => { variantNotOnSale = variantsList; @@ -103,7 +104,7 @@ filterTests({ definedTags: ["all"] }, () => { productData.sku = name; productData.productId = product.id; productData.quantityInWarehouse = 10; - productData.attributeValues = ["value2"]; + productData.attributeName = "value2"; createVariant(productData); }) .then(variantsList => { @@ -141,6 +142,7 @@ filterTests({ definedTags: ["all"] }, () => { let variants; let saleToDelete; productData.name = name; + productData.sku = name; createProductInChannel(productData) .then(({ variantsList }) => { variants = variantsList; @@ -183,6 +185,7 @@ filterTests({ definedTags: ["all"] }, () => { let product; let variants; productData.name = name; + productData.sku = name; createProductInChannel(productData) .then(({ variantsList, product: productResp }) => { product = productResp; diff --git a/cypress/integration/discounts/vouchers.js b/cypress/integration/discounts/vouchers.js index e0165e13a..4b51d7c4c 100644 --- a/cypress/integration/discounts/vouchers.js +++ b/cypress/integration/discounts/vouchers.js @@ -18,6 +18,7 @@ import { createCheckoutWithVoucher } from "../../support/api/utils/ordersUtils"; import * as productsUtils from "../../support/api/utils/products/productsUtils"; +import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils"; import filterTests from "../../support/filterTests"; import { createVoucher, @@ -41,6 +42,7 @@ filterTests({ definedTags: ["all"] }, () => { cy.clearSessionData().loginUserViaRequest(); channelsUtils.deleteChannelsStartsWith(startsWith); deleteVouchersStartsWith(startsWith); + deleteShippingStartsWith(startsWith); const name = `${startsWith}${faker.datatype.number()}`; productsUtils .createProductWithShipping({ name, productPrice, shippingPrice }) diff --git a/cypress/integration/orders/orders.js b/cypress/integration/orders/orders.js index cb5df7abe..56a64ae87 100644 --- a/cypress/integration/orders/orders.js +++ b/cypress/integration/orders/orders.js @@ -116,8 +116,6 @@ filterTests({ definedTags: ["all"] }, () => { }); it("should create order with selected channel", () => { - // Remove login as admin after fixing SALEOR-3154 - cy.clearSessionData().loginUserViaRequest(); cy.visit(urlList.orders) .get(ORDERS_SELECTORS.createOrder) .click(); @@ -131,7 +129,6 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - // This test will pass after fixing SALEOR-3154 it("should not be possible to change channel in order", () => { createOrder({ customerId: customer.id, diff --git a/cypress/integration/preorders/createAndEditVariantsInPreorder.js b/cypress/integration/preorders/createAndEditVariantsInPreorder.js index 2b131e6ff..426ac9870 100644 --- a/cypress/integration/preorders/createAndEditVariantsInPreorder.js +++ b/cypress/integration/preorders/createAndEditVariantsInPreorder.js @@ -22,7 +22,7 @@ import { } from "../../support/pages/catalog/products/VariantsPage"; filterTests({ definedTags: ["all"], version: "3.1.0" }, () => { - describe("Creating variants", () => { + describe("Creating variants in preorder", () => { const startsWith = "CreatePreOrder"; const attributeValues = ["value1", "value2", "value3"]; const threshold = 100; diff --git a/cypress/integration/preorders/stocksAndThreshold.js b/cypress/integration/preorders/stocksAndThreshold.js index 46fcc586f..3433df612 100644 --- a/cypress/integration/preorders/stocksAndThreshold.js +++ b/cypress/integration/preorders/stocksAndThreshold.js @@ -13,8 +13,8 @@ import filterTests from "../../support/filterTests"; import { saveVariant } from "../../support/pages/catalog/products/VariantsPage"; filterTests({ definedTags: ["all"], version: "3.1.0" }, () => { - describe("Creating variants", () => { - const startsWith = "CreatePreOrder"; + describe("Stocks and threshold in preorder variants", () => { + const startsWith = "StocksThreshold"; const attributeValues = ["value1", "value2"]; const preorder = { globalThreshold: 15 diff --git a/cypress/integration/products/images.js b/cypress/integration/products/images.js index 60a3d4ab1..9185f77f2 100644 --- a/cypress/integration/products/images.js +++ b/cypress/integration/products/images.js @@ -7,7 +7,7 @@ import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements"; import { demoProductsNames } from "../../fixtures/products"; import { productDetailsUrl, urlList } from "../../fixtures/urlList"; import { getFirstProducts } from "../../support/api/requests/Product"; -import { loginDeleteProductsAndCreateNewOneWithNewDataAndDefaultChannel } from "../../support/api/utils/products/productsUtils"; +import { deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel } from "../../support/api/utils/products/productsUtils"; import filterTests from "../../support/filterTests"; filterTests({ definedTags: ["all"] }, () => { @@ -26,7 +26,8 @@ filterTests({ definedTags: ["all"] }, () => { element.data.hasOwnProperty("products") ).data; const products = data.products.edges; - cy.get(PRODUCTS_LIST.productImage) + cy.get(PRODUCTS_LIST.productsList) + .find(PRODUCTS_LIST.productImage) .each($image => { cy.wrap($image) .invoke("attr", "src") @@ -68,9 +69,10 @@ filterTests({ definedTags: ["all"] }, () => { const name = "CyImages"; cy.clearSessionData().loginUserViaRequest(); - loginDeleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ name }) - .then(product => { + deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ name }) + .then(({ product }) => { cy.visit(productDetailsUrl(product.id)) + .waitForProgressBarToNotBeVisible() .get(PRODUCT_DETAILS.uploadImageButton) .click() .get(PRODUCT_DETAILS.uploadSavedImagesButton) diff --git a/cypress/support/api/requests/Collections.js b/cypress/support/api/requests/Collections.js index 312eb4efe..32815e0b4 100644 --- a/cypress/support/api/requests/Collections.js +++ b/cypress/support/api/requests/Collections.js @@ -18,18 +18,20 @@ export function createCollection(name, slug = name) { .sendRequestWithQuery(mutation) .its("body.data.collectionCreate.collection"); } -export function getCollections(search) { + +export function getCollections(first, search) { const filter = search ? `, filter:{ search:"" }` : ""; const query = `query{ - collections(first:100 ${filter}){ + collections(first:${first} ${filter}){ edges{ node{ id name + slug } } } diff --git a/cypress/support/api/requests/Product.js b/cypress/support/api/requests/Product.js index c8368c579..18ca5d481 100644 --- a/cypress/support/api/requests/Product.js +++ b/cypress/support/api/requests/Product.js @@ -155,7 +155,6 @@ export function createVariant({ costPrice = 1, trackInventory = true, weight = 1, - attributeValues = ["value"], attributeName = "value", preorder }) { @@ -205,7 +204,7 @@ export function createVariant({ id name } - bulkProductErrors{ + errors{ field message } diff --git a/cypress/support/api/utils/catalog/collectionsUtils.js b/cypress/support/api/utils/catalog/collectionsUtils.js index 70402fdb2..84070ec9a 100644 --- a/cypress/support/api/utils/catalog/collectionsUtils.js +++ b/cypress/support/api/utils/catalog/collectionsUtils.js @@ -1,5 +1,10 @@ import { deleteCollection, getCollections } from "../../requests/Collections"; export function deleteCollectionsStartsWith(startsWith) { - cy.deleteElementsStartsWith(deleteCollection, getCollections, startsWith); + cy.deleteElementsStartsWith( + deleteCollection, + getCollections, + startsWith, + "slug" + ); } diff --git a/cypress/support/customCommands/sharedElementsOperations/tables.js b/cypress/support/customCommands/sharedElementsOperations/tables.js index b5b6df3f2..4447e5578 100644 --- a/cypress/support/customCommands/sharedElementsOperations/tables.js +++ b/cypress/support/customCommands/sharedElementsOperations/tables.js @@ -1,14 +1,17 @@ import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements"; -Cypress.Commands.add("findElementOnTable", elementName => { +Cypress.Commands.add("findElementOnTable", (elementName, alias) => { cy.getTextFromElement(SHARED_ELEMENTS.table).then(tableText => { if (tableText.includes(elementName)) { cy.contains(SHARED_ELEMENTS.tableRow, elementName).click({ force: true }); } else { - cy.get(BUTTON_SELECTORS.nextPaginationButton) - .click() - .findElementOnTable(elementName); + cy.addAliasToGraphRequest(alias); + cy.get(BUTTON_SELECTORS.nextPaginationButton).click(); + if (alias) { + cy.wait(`@${alias}`); + } + cy.findElementOnTable(elementName, alias); } }); }); diff --git a/cypress/support/pages/catalog/products/VariantsPage.js b/cypress/support/pages/catalog/products/VariantsPage.js index e6a112369..7477b3b1d 100644 --- a/cypress/support/pages/catalog/products/VariantsPage.js +++ b/cypress/support/pages/catalog/products/VariantsPage.js @@ -114,9 +114,10 @@ export function fillUpVariantAttributeAndSku({ attributeName, sku }) { .click() .get(VARIANTS_SELECTORS.attributeOption) .contains(attributeName) - .click() - .get(VARIANTS_SELECTORS.skuInputInAddVariant) - .type(sku); + .click(); + if (sku) { + cy.get(VARIANTS_SELECTORS.skuInputInAddVariant).type(sku); + } } export function selectChannelForVariantAndFillUpPrices({ @@ -125,7 +126,9 @@ export function selectChannelForVariantAndFillUpPrices({ price, costPrice = price }) { - cy.addAliasToGraphRequest("ProductChannelListingUpdate"); + cy.waitForProgressBarToNotBeVisible().addAliasToGraphRequest( + "ProductChannelListingUpdate" + ); selectChannelVariantInDetailsPage(channelName, attributeName); cy.get(BUTTON_SELECTORS.confirm) .click()