PromucFlow_constructor/app/client/cypress/support/Pages/AssertHelper.ts
Aishwarya-U-R e9a1f86e22
test: Cypress | CI Stablize + Other improvements (#28254)
## Description
**This PR does the below improvements:**
- Handles initial empty error toast- with cy.LogOut()
- Calling cy.LoginFromAPI() per need only - to improve execution time 
- Update agHelper.UpdateCodeInput()
- Added waitForNetworkCall for AsserHelper methods to only get api call
& validate
- Added gitSync.AuthorizeKeyToGitea() - to validate keyGenerate success
- Adding validationg for 'Unable to import application in workspace'
- cy.CreateNewAppInNewWorkspace() improved
- agHelper.RemoveUIElement() created to handle tooltip, toast,
evaluatedpopup & removed duplicates
- cy.merge() improved to call assertHelper
- assertHelper.AssertNetworkStatus() to handle both array & individual
status checks & return actual responseCode
- createBranch & generatedKey intercepts added to git operation
validations
- homePage.AssertApplication() created
- Removed cy.Logout() & Login improved - brings down total run time to
less than 1 hr from 1+ hrs
- entityExplorer.NavigateToSwitcher() improved to check status
- dataSources.ValidateDSDeletion() improved to handle one of array toast
for array value also
- assertHelper.WaitForNetworkCall() improved to wait & return latest
request
- Private methods processNetworkStatus() & processNetworkResponseData()
created
  
**Also flaky fixes below:**
- ServerSide/QueryPane/S3_2_spec.ts - Adding sleep for CI flaky
behaviour
- Trial fix for
cypress/e2e/Regression/ClientSide/OtherUIFeatures/PageOnLoad_spec.ts
- GitWithJSLibrary/GitwithCustomJSLibrary_spec.js - Handling Import
failure at various points in the flow
- ExplorerTests/Widgets_Copy_Paste_Delete_Undo_Keyboard_Event_spec.js
   - ClientSide/JSLibrary/Library_spec.ts - asserting success import
   - /OtherUIFeatures/ApplicationURL_spec.js - using cy.url()
   - /ClientSide/Templates/Fork_Template_spec.js
- ServerSide/Postgres_DataTypes/Binary_Spec.ts &
/Postgres_DataTypes/Json_Spec.ts - Adding sleep for CI flaky behaviour
   - ClientSide/Widgets/List/List4_2_spec.js
   - /Git/ExistingApps/v1.9.24/DSCrudAndBindings_Spec.ts

#### 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 Cypress tests were reviewed
2023-10-25 19:33:07 +05:30

160 lines
4.6 KiB
TypeScript

import "cypress-wait-until";
import { ObjectsRegistry } from "../Objects/Registry";
import { ReusableHelper } from "../Objects/ReusableHelper";
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 extends ReusableHelper {
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().then((doc) => doc.readyState === "complete"),
cy.document().should((doc) => {
expect(doc.readyState).to.equal("complete");
}),
);
//cy.window({ timeout: 60000 }).should("have.property", "onload");//commenting to reduce time
}
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);
}
}