## Description - This PR re-writes the entire Text_With_Different_Size_spec.ts spec to fix the master run flakyness and and improves the overall complexity of the test case format - cypress/e2e/Regression/ClientSide/Onboarding/StartFromScratch_spec.ts (agHelper.VisitNAssert improved) - Master runs pass at [Run1](https://github.com/appsmithorg/appsmith-ee/pull/3337#issuecomment-1899183181), [Run2](https://github.com/appsmithorg/appsmith-ee/pull/3337#issuecomment-1899197871) - cypress/e2e/Regression/ClientSide/BugTests/AbortAction_Spec.ts (1st test - replace with TED url) - getConsolidatedDataApi() separated, created new agHelper.CypressReload() - Removed cy.log statements from few places - homePage.LogOutviaAPI() removed static wait - Replaced homePage.LogOutviaAPI(); with homePage.Signout(); in places where its flaky - Split /Onboarding/StartFromScratch_spec.ts to 3 specs to reduce flakyness - Split /ClientSide/PartialImportExport/PartialExport_Widgets_spec.ts with failing test to run the other tests in CI - /Templates/Fork_Template_To_App_spec.ts - Added dynamic check to fix CI flakiness - agHelper.AssertURL(), assertHelper.AssertDocumentReady() improved - jsEditor.NavigateToNewJSEditor() improved - cypress/e2e/Regression/ClientSide/ExplorerTests/JSEditorContextMenu_Spec.ts - jsEditor.ValidateDefaultJSObjProperties improved - cypress/e2e/Regression/ServerSide/OnLoadTests/OnLoadActions_Spec.ts - (3rd case - flaky fix) #### 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 changes were reviewed <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **Tests** - Enhanced test flexibility by dynamically constructing API URLs. - Improved test setup and flow in onboarding and regression suites. - Added new test spec files for dynamic height, onboarding, bug tests, login failure, and starting from scratch scenarios. - **Refactor** - Updated function calls and parameters across various test files for consistency and efficiency. - Removed redundant code and streamlined test actions. - **Chores** - Updated intercepted HTTP methods and added new utility functions to support test operations. - **Bug Fixes** - Fixed issues related to element visibility assertions in test scripts. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
169 lines
4.5 KiB
TypeScript
169 lines
4.5 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() {
|
|
this.waitForCondition(() =>
|
|
cy.document().then((doc) => {
|
|
return doc.readyState === "complete";
|
|
}),
|
|
);
|
|
|
|
this.waitForCondition(() =>
|
|
cy.window().then((win) => {
|
|
return win.hasOwnProperty("onload");
|
|
}),
|
|
);
|
|
}
|
|
|
|
private waitForCondition(conditionFn: any) {
|
|
cy.waitUntil(() => conditionFn, {
|
|
timeout: Cypress.config("pageLoadTimeout"),
|
|
interval: 1000,
|
|
});
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|