From 716a89db5a58989efe0e46ff3c0239d243746fd5 Mon Sep 17 00:00:00 2001 From: Shveta Sachdeva Date: Mon, 20 Nov 2023 10:18:32 -0800 Subject: [PATCH] [RFR][CR][JF] Fix tier3 failures (#820) * Fix tier3 failures Signed-off-by: Shveta Sachdeva * Fix tier3 failures Signed-off-by: Shveta Sachdeva --------- Signed-off-by: Shveta Sachdeva Co-authored-by: Shveta Sachdeva --- .../manageimports/pagination.test.ts | 4 +- .../businessservices/pagination.test.ts | 3 +- .../controls/jobfunctions/pagination.test.ts | 10 +- .../stakeholdergroups/pagination.test.ts | 15 +- .../controls/stakeholders/pagination.test.ts | 6 +- .../e2e/views/applicationinventory.view.ts | 2 +- cypress/utils/utils.ts | 298 ++++++------------ 7 files changed, 105 insertions(+), 233 deletions(-) diff --git a/cypress/e2e/tests/migration/applicationinventory/manageimports/pagination.test.ts b/cypress/e2e/tests/migration/applicationinventory/manageimports/pagination.test.ts index 8f3c9d942..c5d6aa8a7 100644 --- a/cypress/e2e/tests/migration/applicationinventory/manageimports/pagination.test.ts +++ b/cypress/e2e/tests/migration/applicationinventory/manageimports/pagination.test.ts @@ -27,7 +27,7 @@ import { deleteAppImportsTableRows, validatePagination, } from "../../../../../utils/utils"; -import { sideKebabMenuImports } from "../../../../views/applicationinventory.view"; +import { sideKebabMenu } from "../../../../views/applicationinventory.view"; import * as commonView from "../../../../views/common.view"; import { Application } from "../../../../models/migration/applicationinventory/application"; @@ -119,7 +119,7 @@ describe(["@tier3"], "Manage imports pagination validations", function () { .get("tbody") .find("td[data-label='File name']") .each(($tableRow) => { - click(sideKebabMenuImports); + click(sideKebabMenu); cy.get("ul[role=menu] > li").contains("Delete").click(); click(commonView.confirmButton); cy.wait("@deleteImport"); diff --git a/cypress/e2e/tests/migration/controls/businessservices/pagination.test.ts b/cypress/e2e/tests/migration/controls/businessservices/pagination.test.ts index eadd22b28..2968a85cb 100644 --- a/cypress/e2e/tests/migration/controls/businessservices/pagination.test.ts +++ b/cypress/e2e/tests/migration/controls/businessservices/pagination.test.ts @@ -25,6 +25,7 @@ import { deleteTableRows, deleteApplicationTableRows, deleteAllBusinessServices, + deleteAllItems, } from "../../../../../utils/utils"; import { SEC } from "../../../../types/constants"; import { prevPageButton } from "../../../../views/common.view"; @@ -81,7 +82,7 @@ describe(["@tier3"], "Business services pagination validations", function () { cy.wait(2 * SEC); goToLastPage(); // Delete all items of last page - deleteTableRows(); + deleteAllItems(); // Verify that page is re-directed to previous page cy.get("td[data-label=Name]").then(($rows) => { cy.wrap($rows.length).should("eq", 10); diff --git a/cypress/e2e/tests/migration/controls/jobfunctions/pagination.test.ts b/cypress/e2e/tests/migration/controls/jobfunctions/pagination.test.ts index a48c5f672..277acceb3 100644 --- a/cypress/e2e/tests/migration/controls/jobfunctions/pagination.test.ts +++ b/cypress/e2e/tests/migration/controls/jobfunctions/pagination.test.ts @@ -22,13 +22,7 @@ import { deleteByList, validatePagination, } from "../../../../../utils/utils"; -import { - firstPageButton, - lastPageButton, - nextPageButton, - pageNumInput, - prevPageButton, -} from "../../../../views/common.view"; +import { pageNumInput, prevPageButton } from "../../../../views/common.view"; import { Jobfunctions } from "../../../../models/migration/controls/jobfunctions"; let jobFunctionsList: Array = []; @@ -72,7 +66,7 @@ describe(["@tier3"], "Job functions pagination validations", function () { }); }); - it("Bug MTA-1675: Page number validations", function () { + it("Page number validations", function () { // Navigate to Job functions tab Jobfunctions.openList(); diff --git a/cypress/e2e/tests/migration/controls/stakeholdergroups/pagination.test.ts b/cypress/e2e/tests/migration/controls/stakeholdergroups/pagination.test.ts index b6d51cc6e..832cf0b92 100644 --- a/cypress/e2e/tests/migration/controls/stakeholdergroups/pagination.test.ts +++ b/cypress/e2e/tests/migration/controls/stakeholdergroups/pagination.test.ts @@ -18,19 +18,18 @@ limitations under the License. import { login, selectItemsPerPage, - deleteTableRows, createMultipleStakeholderGroups, validatePagination, + deleteAllStakeholderGroups, + deleteAllItems, } from "../../../../../utils/utils"; import { Stakeholdergroups } from "../../../../models/migration/controls/stakeholdergroups"; import { lastPageButton, pageNumInput, prevPageButton } from "../../../../views/common.view"; -let stakeholderGroupsList: Array = []; - describe(["@tier3"], "Stakeholder groups pagination validations", function () { before("Login and Create Test Data", function () { login(); - stakeholderGroupsList = createMultipleStakeholderGroups(11); + createMultipleStakeholderGroups(11); }); beforeEach("Interceptors", function () { @@ -46,7 +45,7 @@ describe(["@tier3"], "Stakeholder groups pagination validations", function () { validatePagination(); }); - it("Items per page validations", function () { + it("Bug MTA-1694: Items per page validations", function () { // Navigate to stakeholder groups tab Stakeholdergroups.openList(); cy.get("@getStakeholdergroups"); @@ -88,7 +87,7 @@ describe(["@tier3"], "Stakeholder groups pagination validations", function () { }); }); - it("Bug MTA-1675: Last page item(s) deletion, impact on page reload validation", function () { + it("Bug MTA-1694: Last page item(s) deletion, impact on page reload validation", function () { // Issue - https://issues.redhat.com/browse/TACKLE-155 // Navigate to stakeholder groups tab Stakeholdergroups.openList(); @@ -103,7 +102,7 @@ describe(["@tier3"], "Stakeholder groups pagination validations", function () { cy.wait(2000); // Delete all items of last page - deleteTableRows(); + deleteAllItems(); // Verify that page is re-directed to previous page cy.get("td[data-label=Name]").then(($rows) => { @@ -112,6 +111,6 @@ describe(["@tier3"], "Stakeholder groups pagination validations", function () { }); after("Perform test data clean up", function () { - deleteTableRows(); + deleteAllStakeholderGroups(); }); }); diff --git a/cypress/e2e/tests/migration/controls/stakeholders/pagination.test.ts b/cypress/e2e/tests/migration/controls/stakeholders/pagination.test.ts index a551aeaa6..97e34645b 100644 --- a/cypress/e2e/tests/migration/controls/stakeholders/pagination.test.ts +++ b/cypress/e2e/tests/migration/controls/stakeholders/pagination.test.ts @@ -18,9 +18,9 @@ limitations under the License. import { login, selectItemsPerPage, - deleteTableRows, createMultipleStakeholders, validatePagination, + deleteAllItems, } from "../../../../../utils/utils"; import { lastPageButton, pageNumInput, prevPageButton } from "../../../../views/common.view"; import { Stakeholders } from "../../../../models/migration/controls/stakeholders"; @@ -101,7 +101,7 @@ describe(["@tier3"], "Stakeholder pagination validations", function () { cy.wait(2000); // Delete all items of last page - deleteTableRows(stakeHoldersTable); + deleteAllItems(stakeHoldersTable); // Verify that page is re-directed to previous page cy.get("td[data-label=Email]").then(($rows) => { @@ -110,6 +110,6 @@ describe(["@tier3"], "Stakeholder pagination validations", function () { }); after("Perform test data clean up", function () { - deleteTableRows(stakeHoldersTable); + deleteAllItems(stakeHoldersTable); }); }); diff --git a/cypress/e2e/views/applicationinventory.view.ts b/cypress/e2e/views/applicationinventory.view.ts index d849d0168..2c87ef8f3 100644 --- a/cypress/e2e/views/applicationinventory.view.ts +++ b/cypress/e2e/views/applicationinventory.view.ts @@ -44,7 +44,7 @@ export const topKebabMenu = "#toolbar-kebab"; export const kebabMenuItem = "span.pf-v5-c-menu__item-text"; export const bulkApplicationSelectionCheckBox = "input[name='bulk-selected-items-checkbox']"; // This is on the Application imports page. -export const sideKebabMenuImports = "button[aria-label='Kebab toggle']"; +export const sideKebabMenu = "button[aria-label='Kebab toggle']"; //Fields related to analysis - source mode export const sourceRepository = "input[name=sourceRepository]"; diff --git a/cypress/utils/utils.ts b/cypress/utils/utils.ts index f562bb53d..2fd895e84 100644 --- a/cypress/utils/utils.ts +++ b/cypress/utils/utils.ts @@ -38,7 +38,6 @@ import { criticality, priority, confidence, - deleteAction, applicationInventory, SEC, CredentialType, @@ -55,7 +54,7 @@ import { actionButton, date, createEntitiesCheckbox, - sideKebabMenuImports, + sideKebabMenu, appImportForm, kebabMenu, } from "../e2e/views/applicationinventory.view"; @@ -92,6 +91,7 @@ import { Jira } from "../e2e/models/administration/jira-connection/jira"; import { JiraCredentials } from "../e2e/models/administration/credentials/JiraCredentials"; import { closeModal } from "../e2e/views/assessment.view"; import { Application } from "../e2e/models/migration/applicationinventory/application"; +import { stakeHoldersTable } from "../e2e/views/stakeholders.view"; const { _ } = Cypress; @@ -656,22 +656,6 @@ export function notExistsWithinRow( .should("not.contain", valueToSearch); } -export function deleteTableRows(tableSelector = commonView.appTable): void { - cy.get(tableSelector).get("tbody").find(trTag).as("rowsIdentifier"); - cy.get("@rowsIdentifier").then(($tableRows) => { - for (let i = 0; i < $tableRows.length; i++) { - cy.get("@rowsIdentifier") - .eq(0) - .within(() => { - click(commonView.deleteButton); - cy.wait(2 * SEC); - }); - cy.get(commonView.confirmButton).click(); - cy.wait(2 * SEC); - } - }); -} - export function importApplication(fileName: string, disableAutoCreation?: boolean): void { // Performs application import via csv file upload application_inventory_kebab_menu("Import"); @@ -764,7 +748,7 @@ export function openManageImportsPage(): void { export function openErrorReport(): void { // Open error report for the first row cy.get("table > tbody > tr").eq(0).as("firstRow"); - cy.get("@firstRow").find(sideKebabMenuImports).click(); + cy.get("@firstRow").find(sideKebabMenu).click(); cy.get("@firstRow").find(button).contains("View error report").click(); cy.get("h1", { timeout: 5 * SEC }).contains("Error report"); } @@ -800,84 +784,6 @@ export function migration_wave_kebab_menu(menu): void { cy.get(commonView.kebabMenuItem).contains(menu).click({ force: true }); } -export function deleteAllMigrationWaves(currentPage = false): void { - MigrationWave.open(); - cy.wait(2000); - cy.get(MigrationWaveView.waveTable) - .next() - .then(($div) => { - if (!$div.hasClass("pf-c-empty-state")) { - cy.wait(1000); - cy.get("span.pf-c-options-menu__toggle-text") - .eq(0) - .then(($body) => { - if (!$body.text().includes("of 0")) { - if (currentPage) { - cy.get(".pf-c-dropdown__toggle-button").click({ force: true }); - clickByText(button, "Select page"); - } else { - cy.get("input#bulk-selected-items-checkbox", { - timeout: 10 * SEC, - }).check({ force: true }); - } - - migration_wave_kebab_menu("Delete"); - clickByText(button, "Delete", true); - } - }); - } - }); -} - -export function deleteApplicationTableRows(): void { - // Delete all rows one by one for which Delete button is enabled - // to be used only in manageImports tests as we don't know which apps - // are imported. For all other tests use deleteByList(appList) - navigate_to_application_inventory(); - cy.get(commonView.appTable) - .next() - .then(($div) => { - if (!$div.hasClass("pf-v5-c-empty-state")) { - cy.get(commonView.appTable) - .find(trTag) - .then(($rows) => { - for (let i = 0; i < $rows.length - 2; i++) { - cy.get(sideKebabMenuImports, { timeout: 10000 }).first().click(); - cy.get("ul[role=menu] > li").contains("Delete").click(); - cy.get(commonView.confirmButton).click(); - cy.wait(5000); - } - }); - } - }); -} - -export function deleteAppImportsTableRows() { - openManageImportsPage(); - - cy.intercept("DELETE", "/hub/importsummaries*/*").as("deleteImportUtils"); - - cy.get(commonView.appTable) - .find(trTag) - .then(($rows) => { - for (let i = 0; i < $rows.length - 1; i++) { - cy.get(sideKebabMenuImports, { timeout: 10000 }).first().click(); - cy.get("ul[role=menu] > li").contains("Delete").click(); - cy.get(commonView.confirmButton).click(); - cy.wait("@deleteImportUtils"); - cy.wait(5000); - } - }); -} - -// Checks if the hook has to be skipped, if the tag is not mentioned during test run -export function hasToBeSkipped(tagName: string): boolean { - if (Cypress.env("grepTags")) { - if (!Cypress.env("grepTags").includes(tagName)) return true; - } - return false; -} - // Perform edit/delete action on the specified row selector by clicking a text button export function performRowAction(itemName: string, action: string): void { // itemName is text to be searched on the screen (like credentials name, stakeholder name, etc) @@ -1235,11 +1141,6 @@ export function createApplicationObjects(numberOfObjects: number): Array void }; export function deleteByList(array: T[]): void { @@ -1249,89 +1150,6 @@ export function deleteByList(array: T[]): void { }); } -export function deleteAllStakeholders(): void { - Stakeholders.openList(); - cy.get("table[aria-label='Stakeholders table']", { timeout: 2 * SEC }).then(($tbody) => { - if (!$tbody.text().includes("No data available")) { - selectItemsPerPage(100); - cy.get(commonView.deleteButton).then(($elems) => { - const elemsLength = $elems.length; - for (let i = 0; i < elemsLength; i++) { - cy.get(commonView.deleteButton) - .first() - .click() - .then((_) => { - cy.wait(0.5 * SEC); - click(commonView.confirmButton); - cy.wait(SEC); - }); - } - }); - } - }); -} - -export function deleteAllStakeholderGroups(cancel = false): void { - Stakeholdergroups.openList(); - deleteAllItems(); -} - -export function deleteAllBusinessServices() { - BusinessServices.openList(); - cy.get(commonView.appTable) - .next() - .then(($div) => { - if (!$div.hasClass("pf-c-empty-state")) { - cy.get("tbody") - .find(trTag) - .not(".pf-c-table__expandable-row") - .each(($tableRow) => { - const name = $tableRow.find("td[data-label=Name]").text(); - cy.get(tdTag) - .contains(name) - .closest(trTag) - .contains(button, deleteAction) - .then(($delete_btn) => { - if (!$delete_btn.hasClass("pf-m-aria-disabled")) { - $delete_btn.click(); - cy.wait(800); - click(commonView.confirmButton); - cy.wait(2000); - } - }); - }); - } - }); -} - -export function deleteAllTagCategory(cancel = false): void { - TagCategory.openList(); - cy.get(commonView.appTable, { timeout: 2 * SEC }) - .next() - .then(($div) => { - if (!$div.hasClass("pf-c-empty-state")) { - cy.get("tbody") - .find(trTag) - .not(".pf-c-table__expandable-row") - .each(($tableRow) => { - cy.wait(1000); - let name = $tableRow.find('td[data-label="Tag type"]').text(); - if (!(data.getDefaultTagCategories().indexOf(name) > -1)) { - cy.get(tdTag) - .contains(name) - .parent(trTag) - .within(() => { - click(commonView.deleteButton); - cy.wait(1000); - }); - click(commonView.confirmButton); - cy.wait(4000); - } - }); - } - }); -} - export function deleteAllTagsAndTagCategories(): void { const nonDefaultTagTypes = []; TagCategory.openList(); @@ -1383,37 +1201,97 @@ export function deleteAllTagsAndTagCategories(): void { }); } -export async function deleteAllCredentials() { - Credentials.openList(); - deleteAllItems(); +export function isTableEmpty( + tableSelector: string = commonView.commonTable +): Cypress.Chainable { + return cy.get(tableSelector).then(($element) => { + return $element.hasClass("pf-c-empty-state"); + }); } -export function deleteAllItems(amountPerPage = 100, pageNumber?: number) { - selectItemsPerPage(amountPerPage); +export function deleteAllRows(tableSelector: string = commonView.commonTable) { + // This method if for pages that have delete button inside Kebab menu + // like Applications and Imports page + selectItemsPerPage(100); + isTableEmpty().then((empty) => { + if (!empty) { + cy.get(tableSelector) + .find(trTag) + .then(($rows) => { + for (let i = 0; i < $rows.length - 2; i++) { + cy.get(sideKebabMenu, { timeout: 10000 }).first().click(); + cy.get("ul[role=menu] > li").contains("Delete").click(); + cy.get(commonView.confirmButton).click(); + cy.wait(5000); + } + }); + } + }); +} + +export function deleteAllItems( + tableSelector: string = commonView.commonTable, + pageNumber?: number +) { + // This method if for pages like controls that do not have delete button inside kebabmenu if (pageNumber) { goToPage(pageNumber); } - cy.get(commonView.appTable, { timeout: 15 * SEC }) - .next() - .then(($div) => { - if (!$div.hasClass("pf-c-empty-state")) { - cy.get("tbody") - .find(trTag) - .not(".pf-c-table__expandable-row") - .each(($tableRow) => { - let name = $tableRow.find("td[data-label=Name]").text(); - cy.get(tdTag) - .contains(name) - .closest(trTag) - .within(() => { - click(commonView.deleteButton); - cy.wait(SEC); + isTableEmpty().then((empty) => { + if (!empty) { + cy.get(tableSelector) + .find(trTag) + .then(($rows) => { + for (let i = 0; i < $rows.length - 1; i++) { + cy.get(commonView.deleteButton, { timeout: 10000 }) + .first() + .then(($delete_btn) => { + if (!$delete_btn.hasClass("pf-m-aria-disabled")) { + $delete_btn.click(); + cy.wait(0.5 * SEC); + click(commonView.confirmButton); + cy.wait(SEC); + } }); - click(commonView.confirmButton); - cy.wait(SEC); - }); - } - }); + } + }); + } + }); +} + +export function deleteAllBusinessServices() { + BusinessServices.openList(); + deleteAllItems(); +} + +export function deleteAllStakeholderGroups(cancel = false): void { + Stakeholdergroups.openList(); + deleteAllItems(); +} + +export function deleteAllStakeholders(): void { + Stakeholders.openList(); + deleteAllItems(stakeHoldersTable); +} + +export async function deleteAllCredentials() { + Credentials.openList(); + deleteAllItems(); +} + +export function deleteAllJobfunctions(cancel = false): void { + Jobfunctions.openList(); + deleteAllItems(); +} + +export function deleteApplicationTableRows(): void { + navigate_to_application_inventory(); + deleteAllRows(); +} + +export function deleteAppImportsTableRows() { + openManageImportsPage(); + deleteAllRows(); } export const deleteFromArray = (array: T[], el: T): T[] => {