From d9af859d41449f228d68265c3440874e9ccf628d Mon Sep 17 00:00:00 2001 From: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Date: Thu, 22 Jun 2023 17:35:59 +0530 Subject: [PATCH] test: Cypress | Flaky fixes (#24723) - This PR fixes below flaky specs: - GitDiscardChange/DiscardChanges_spec.js - Socket closed before finished writing response fix - Workspace/ShareAppTests_spec.js (NavigateBacktoEditor() fix) - Script fix (non-breaking change which fixes an issue) - [X] Cypress - [X] Added `Test Plan Approved` label after changes are reviewed (cherry picked from commit 6df0810cc954d39244db094a10b80490f68f8d3c) --- .../Datasources/ElasticSearch_Basic_Spec.ts | 2 +- .../cypress/support/Objects/CommonLocators.ts | 3 ++- app/client/cypress/support/Pages/DataSources.ts | 4 ++-- .../cypress/support/Pages/DeployModeHelper.ts | 2 +- app/client/cypress/support/Pages/GitSync.ts | 2 ++ app/client/cypress/support/commands.js | 13 ++++++------- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/client/cypress/e2e/Regression/ServerSide/Datasources/ElasticSearch_Basic_Spec.ts b/app/client/cypress/e2e/Regression/ServerSide/Datasources/ElasticSearch_Basic_Spec.ts index fba6266f53..69c42815e2 100644 --- a/app/client/cypress/e2e/Regression/ServerSide/Datasources/ElasticSearch_Basic_Spec.ts +++ b/app/client/cypress/e2e/Regression/ServerSide/Datasources/ElasticSearch_Basic_Spec.ts @@ -11,7 +11,7 @@ describe("Validate Elasticsearch DS", () => { containerName = "elasticsearch1"; before("Create a new ElasticSearch DS", () => { - dataSources.StartContainerNVerify("Elasticsearch", containerName); + dataSources.StartContainerNVerify("Elasticsearch", containerName, 40000); dataSources.CreateDataSource("Elasticsearch"); cy.get("@dsName").then(($dsName) => { dsName = $dsName; diff --git a/app/client/cypress/support/Objects/CommonLocators.ts b/app/client/cypress/support/Objects/CommonLocators.ts index 1b8951c4b8..34c563c2f3 100644 --- a/app/client/cypress/support/Objects/CommonLocators.ts +++ b/app/client/cypress/support/Objects/CommonLocators.ts @@ -58,13 +58,14 @@ export class CommonLocators { item + "']/parent::div[@role='menuitem'] | //div[text()='" + item + - "']/ancestor::div[@role='menuitem']| //span[text()='" + + "']/ancestor::div[@role='menuitem'] | //span[text()='" + item + "']/ancestor::div[@role='menuitem']"; _visibleTextDiv = (divText: string) => "//div[text()='" + divText + "']"; _visibleTextSpan = (spanText: string) => `//span[text()="` + spanText + `"]`; _openWidget = ".widgets .t--entity-add-btn"; _dropHere = ".t--drop-target"; + _editPage = "[data-testid=onboarding-tasks-datasource-text], .t--drop-target"; _crossBtn = "span.cancel-icon"; _createNew = ".t--entity-add-btn.group.files button"; _uploadFiles = "div.uppy-Dashboard-AddFiles input"; diff --git a/app/client/cypress/support/Pages/DataSources.ts b/app/client/cypress/support/Pages/DataSources.ts index 53bfb357bf..f9ee55395c 100644 --- a/app/client/cypress/support/Pages/DataSources.ts +++ b/app/client/cypress/support/Pages/DataSources.ts @@ -1390,7 +1390,7 @@ export class DataSources { public StartContainerNVerify( containerType: "MsSql" | "Arango" | "Elasticsearch", containerName: string, - timeout = 30000, + sleepTime = 30000, ) { let containerCommand = ""; switch (containerType) { @@ -1414,7 +1414,7 @@ export class DataSources { }).then((isReady) => { if (isReady) { cy.log("Run id of started container is:" + result.stdout); - this.agHelper.Sleep(timeout); //allow some time for container to settle start for CI + this.agHelper.Sleep(sleepTime); //allow some time for container to settle start for CI } else cy.log( `Error from ${containerName} container start action:` + diff --git a/app/client/cypress/support/Pages/DeployModeHelper.ts b/app/client/cypress/support/Pages/DeployModeHelper.ts index bf07d9d894..ad6cb175e4 100644 --- a/app/client/cypress/support/Pages/DeployModeHelper.ts +++ b/app/client/cypress/support/Pages/DeployModeHelper.ts @@ -97,7 +97,7 @@ export class DeployMode { ); //Assert that is not error toast in Edit mode when navigating back from Deploy mode this.assertHelper.AssertDocumentReady(); this.assertHelper.AssertNetworkStatus("@getWorkspace"); - this.agHelper.AssertElementVisible(this.locator._dropHere); //Assert if canvas is visible after Navigating back! + this.agHelper.AssertElementVisible(this.locator._editPage); //Assert if canvas is visible after Navigating back! } public NavigateToHomeDirectly() { diff --git a/app/client/cypress/support/Pages/GitSync.ts b/app/client/cypress/support/Pages/GitSync.ts index 57c70b6723..80890985f1 100644 --- a/app/client/cypress/support/Pages/GitSync.ts +++ b/app/client/cypress/support/Pages/GitSync.ts @@ -238,6 +238,8 @@ export class GitSync { this.agHelper.AssertContains( Cypress.env("MESSAGES").DISCARDING_AND_PULLING_CHANGES(), ); + this.assertHelper.AssertNetworkStatus("@discardChanges"); + this.assertHelper.AssertNetworkStatus("@gitStatus"); this.agHelper.AssertContains("Discarded changes successfully"); this.agHelper.AssertElementExist(this._bottomBarCommit, 0, 30000); } diff --git a/app/client/cypress/support/commands.js b/app/client/cypress/support/commands.js index 78ca7c4d4d..9c86acfaf9 100644 --- a/app/client/cypress/support/commands.js +++ b/app/client/cypress/support/commands.js @@ -1107,13 +1107,11 @@ Cypress.Commands.add("startServerAndRoutes", () => { }).as("sucessSave"); cy.intercept("POST", "https://api.segment.io/v1/b", (req) => { - req.reply((res) => { - res.send({ - //status: 200, - body: { - success: true, //since anything can be faked! - }, - }); + req.reply({ + statusCode: 200, + body: { + success: false, //since anything can be faked! + }, }); }); @@ -1126,6 +1124,7 @@ Cypress.Commands.add("startServerAndRoutes", () => { cy.intercept("PUT", "/api/v1/tenants", (req) => { req.headers["origin"] = "Cypress"; }).as("postTenant"); + cy.intercept("PUT", "/api/v1/git/discard/app/*").as("discardChanges"); }); Cypress.Commands.add("startErrorRoutes", () => {