PromucFlow_constructor/app/client/cypress/support/Pages/AssertHelper.ts
Aishwarya-U-R 7a18d4ac4c
test: Cypress | Flaky fixes + Replacing static waits (#30067)
## Description
- This PR includes the flaky fixes of the below specs:
- jsEditor.NavigateToNewJSEditor() using TS helpers (Addressing
flakyness in specs /BugTests/JS_Bug29131_spec.ts,
BugTests/invalidLintError_Spec.ts,
ClientSide/BugTests/JS_Bug28764_Spec.ts,
/ClientSide/BugTests/Bug29566_Spec.ts,
ServerSide/JsFunctionExecution/JSFunctionExecution_spec.ts)
- /Widgets/ListV2/Listv2_onItemClick_spec.js (toast validation updated
to ts helper)
           - /Apps/MongoDBShoppingCart_spec.ts (Flaky fix 2nd case)
           - /Regression/Apps/PromisesApp_spec.js (1st test)
- /ClientSide/OtherUIFeatures/ApplicationURL_spec.js (whole spec for
static wait removal + flaky fixes)
- /ClientSide/Templates/Fork_Template_spec.js (complete spec fixes,
cypress exception fix)
           - /Sanity/Datasources/Arango_Basic_Spec.ts (3rd test)
- /ServerSide/OnLoadTests/JSOnLoad2_Spec.ts (8th case flaky fix)
- /ClientSide/MobileResponsiveTests/AutoFillWidgets_Reflow_spec.ts (2nd
testcase, flow update)
           - /ClientSide/OtherUIFeatures/Resize_spec.js (import update)
- /ClientSide/Templates/Fork_Template_spec.js (1st & 3rd for flaky fix,
removed 2nd - redundant check)
- /Git/GitSync/RepoLimitExceededErrorModal_spec.js flaky fix for EE repo
failure
- /ServerSide/ApiTests/API_Bugs_Spec.js (3rd case, removed waits, moved
to TED Api)
           - /Apps/EchoApiCMS_spec.js (removed redundant action)
- /AppNavigation/Sidebar_spec.ts, /AppNavigation/TopInline_spec.ts,
/AppNavigation/TopStacked_spec.ts - added refresh calls for CI flakyness
- homePage.RenameWorkspace() & homePage.NavigateToHome() &
homePage.Signout() - removed static wait, added dynamic check
- homePage.CreateNewApplication() - removed static wait
- homePage.CreateAppInWorkspace() - removed commented code
- homePage.CreateNewWorkspace() - logic improved
- agHelper.AssertURL() - added timeout, removed static wait, calling
assertHelper.AssertDocumentReady()
- Few of agHelper methods timeout & error mesg text update
- cy.Signup() - updated validations
- agHelper.CheckForErrorToast() to agHelper.FailIfErrorToast() - method
name
- /ClientSide/BugTests/DSDiscardBugs_spec.ts - removed unnecessary
method call

#### Type of change
- Script fix (non-breaking change which fixes an issue)

## Testing
#### How Has This Been Tested?
- [X] Cypress CI runs

## Checklist:
#### QA activity:
- [X] Added `Test Plan Approved` label after all changes were reviewed

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Enhanced timeout handling across various helper methods for improved
stability.
- Streamlined interactions with UI elements using updated helper
methods.
- Adjusted test suites to utilize configuration values for consistency.

- **Tests**
  - Temporarily disabled specific test suites to address current issues.
- Updated test assertions and interaction patterns for clarity and
reliability.
- Added new test cases and assertions to cover additional
functionalities.

- **Chores**
  - Updated workflow variables for more efficient CI processes.
- Curated the list of limited tests to focus on critical test scenarios.

- **Documentation**
  - Clarified test descriptions and intentions for better understanding.

- **Bug Fixes**
- Fixed UI element interactions to prevent test flakiness and improve
user experience.
- Implemented page refresh before application imports to ensure clean
state for tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-01-12 12:00:12 +05:30

161 lines
4.4 KiB
TypeScript

import "cypress-wait-until";
export const EntityItems = {
Page: 0,
Query: 1,
Api: 2,
JSObject: 3,
Widget: 4,
Datasource: 5,
} as const;
export type EntityItemsType = (typeof EntityItems)[keyof typeof EntityItems];
export class AssertHelper {
public _modifierKey = Cypress.platform === "darwin" ? "meta" : "ctrl";
public isMac = Cypress.platform === "darwin";
public Sleep(timeout = 1000) {
cy.wait(timeout);
}
public AssertDocumentReady() {
cy.waitUntil(() =>
cy.document().should((doc) => {
expect(doc.readyState).to.equal("complete");
}),
);
cy.waitUntil(() =>
cy
.window({ timeout: Cypress.config().pageLoadTimeout })
.then((win) => expect(win).haveOwnProperty("onload")),
);
}
public AssertDelete(entityType: EntityItemsType) {
let networkCall = "";
switch (entityType) {
case EntityItems.Api:
case EntityItems.Query:
networkCall = "deleteAction";
break;
case EntityItems.Widget:
networkCall = "updateLayout";
break;
case EntityItems.JSObject:
networkCall = "deleteJSCollection";
this.AssertContains("deleted successfully");
break;
case EntityItems.Datasource:
networkCall = "deleteDatasource";
break;
case EntityItems.Page:
networkCall = "deletePage";
break;
default:
networkCall && this.AssertNetworkStatus(networkCall);
}
}
public GetAliasName(aliasName: string) {
aliasName = aliasName.startsWith("@") ? aliasName : "@" + aliasName;
return aliasName;
}
public WaitForNetworkCall(aliasName: string, responseTimeout = 150000) {
// cy.wait(aliasName).then(($apiCall: any) => {
// expect($apiCall.response.body.responseMeta.status).to.eq(expectedStatus);
// });
this.Sleep(); //wait a bit to avoid flaky tests
return cy
.wait(this.GetAliasName(aliasName), { timeout: responseTimeout })
.then((interceptions) => {
return cy
.get(this.GetAliasName(aliasName), { timeout: responseTimeout })
.its("response");
});
}
public AssertNetworkStatus(
aliasName: string,
expectedStatus: number | number[] = 200,
waitForNetworkCall = true,
) {
if (waitForNetworkCall) {
// If waitForNetworkCall is true, then use the response from WaitForNetworkCall call
return this.WaitForNetworkCall(aliasName).then((response: any) =>
this.processNetworkStatus(response, expectedStatus),
);
} else {
// If interception is not available, directly get the alias & use it
return cy
.get(this.GetAliasName(aliasName))
.its("response")
.then((interception: any) =>
this.processNetworkStatus(interception, expectedStatus),
);
}
}
private processNetworkStatus(
response: any,
expectedStatus: number | number[],
) {
const responseStatus = Number(response.body.responseMeta.status);
const expectedStatusArray = Array.isArray(expectedStatus)
? expectedStatus
: [expectedStatus];
expect(expectedStatusArray).to.include(responseStatus);
return responseStatus;
}
public AssertNetworkResponseData(
aliasName: string,
waitForNetworkCall = true,
) {
if (waitForNetworkCall) {
// If waitForNetworkCall is true, then use the interception from received call
this.WaitForNetworkCall(aliasName).then((interception: any) => {
this.processNetworkResponseData(interception);
});
} else {
// If interception is not available, directly get the alias & use it
cy.get(this.GetAliasName(aliasName))
.its("response")
.then((interception: any) => {
this.processNetworkResponseData(interception);
});
}
}
private processNetworkResponseData(response: any) {
expect(response.body.data).to.not.be.empty;
}
public AssertNetworkExecutionSuccess(
aliasName: string,
expectedRes = true,
waitForNetworkCall = true,
) {
waitForNetworkCall && this.WaitForNetworkCall(aliasName);
cy.get(aliasName)
.its("response.body.data.isExecutionSuccess")
.should("eq", expectedRes);
}
public AssertContains(
text: string | RegExp,
exists: "exist" | "not.exist" | "be.visible" = "exist",
selector?: string,
) {
if (selector) {
return cy.contains(selector, text).should(exists);
}
return cy.contains(text).should(exists);
}
}