chore: Add rapid mode to skip new app creation in cypress test (#22854)

Fixes #22878

This pr adds a flag called 'rapidMode' in cypress index file.

```
cypress/support/index.js

let rapidMode = {
  enabled: false, // Set it to true to skip app creation during a test re-run
  appName: "4a9b62a0", // Replace it with your app name
  pageName: "page1", // Replace it with the page name
  pageID: "644f8d6e21506c33a366854b", // Replace it with pageID

  url: function () {
    return `app/${this.appName}/${this.pageName}-${this.pageID}/edit`;
  },
};
```
When rapid mode is enabled, the cypress test will

1. Skip relogin if the test user is already logged in.
2. Skip creation of a new app and use a previously created app, passed
as param.

The flag needs to be disabled when the code needs to be merged to
release, and is meant for debugging/testing while writing tests on local
development setup only.

When enabled, a cypress test saves around 25 sec per rerun.

Future fixes would include skipping multiple workspace page visit if a
developer is using dsl for setting up fixtures. It would save around
another 10-15 seconds per test re-run.
This commit is contained in:
Rajat Agrawal 2023-05-02 16:17:23 +05:30 committed by GitHub
parent ab1e0e6cce
commit 58fea85a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 19 deletions

View File

@ -193,6 +193,7 @@ describe("Table widget Add new row feature's", () => {
describe("Validation flow", () => {
before(() => {
cy.startServerAndRoutes();
agHelper.RestoreLocalStorageCache();
cy.addDsl(dsl);
});
@ -350,6 +351,7 @@ describe("Table widget Add new row feature's", () => {
describe("Actions flow (save, discard)", () => {
before(() => {
cy.startServerAndRoutes();
agHelper.RestoreLocalStorageCache();
cy.addDsl(dsl);
});

View File

@ -56,11 +56,6 @@ describe("Create new workspace and share with a user", function () {
it("3. Enable public access to Application", function () {
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
cy.wait("@applications").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.SearchApp(appid);
cy.wait("@getPagesForCreateApp").should(
"have.nested.property",
@ -117,11 +112,6 @@ describe("Create new workspace and share with a user", function () {
it("6. login as Owner and disable public access", function () {
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
cy.wait("@applications").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.SearchApp(appid);
cy.wait("@getPagesForCreateApp").should(
"have.nested.property",

View File

@ -274,11 +274,14 @@ Cypress.Commands.add("Signup", (uname, pword) => {
Cypress.Commands.add("LoginFromAPI", (uname, pword) => {
cy.location().then((loc) => {
let baseURL = Cypress.config().baseUrl;
baseURL = baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL;
cy.visit({
method: "POST",
url: "api/v1/login",
headers: {
origin: loc.origin,
origin: baseURL,
},
followRedirect: true,
body: {
@ -289,9 +292,15 @@ Cypress.Commands.add("LoginFromAPI", (uname, pword) => {
.then(() => cy.location())
.then((loc) => {
expect(loc.href).to.equal(loc.origin + "/applications");
cy.wait("@getMe");
cy.wait("@applications").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.wait("@getReleaseItems");
});
});
cy.wait(2000); //for the page elements to load!
});
Cypress.Commands.add("DeleteApp", (appName) => {
@ -599,18 +608,16 @@ Cypress.Commands.add("generateUUID", () => {
Cypress.Commands.add("addDsl", (dsl) => {
let currentURL, pageid, layoutId, appId;
appId = localStorage.getItem("applicationId");
cy.url().then((url) => {
currentURL = url;
pageid = currentURL.split("/")[5]?.split("-").pop();
cy.log(pageidcopy + "page id copy");
cy.log(pageid + "page id");
appId = localStorage.getItem("applicationId");
//Fetch the layout id
cy.request("GET", "api/v1/pages/" + pageid).then((response) => {
const respBody = JSON.stringify(response.body);
layoutId = JSON.parse(respBody).data.layouts[0].id;
cy.log("appid:" + appId);
const data = JSON.parse(respBody).data;
layoutId = data.layouts[0].id;
appId = data.applicationId;
// Dumping the DSL to the created page
cy.request({
method: "PUT",
@ -629,6 +636,7 @@ Cypress.Commands.add("addDsl", (dsl) => {
cy.log(response.body);
expect(response.status).equal(200);
cy.reload();
cy.wait("@getWorkspace");
});
});
});
@ -926,6 +934,7 @@ Cypress.Commands.add("startServerAndRoutes", () => {
cy.route("GET", "/api/v1/datasources?workspaceId=*").as("getDataSources");
cy.route("GET", "/api/v1/pages?*mode=EDIT").as("getPagesForCreateApp");
cy.route("GET", "/api/v1/pages?*mode=PUBLISHED").as("getPagesForViewApp");
cy.route("GET", "/api/v1/applications/releaseItems").as("getReleaseItems");
cy.route("POST");
cy.route("GET", "/api/v1/pages/*").as("getPage");

View File

@ -33,6 +33,17 @@ import "./AdminSettingsCommands";
import "cypress-plugin-tab";
/// <reference types="cypress-xpath" />
let rapidMode = {
enabled: false, // Set to true to disable app creation
appName: "cf023e29", // Replace it with your app name
pageName: "page1", // Replace it with the page name
pageID: "644d0ec870cec01248edfc9a", // Replace it with pageID
url: function () {
return `app/${this.appName}/${this.pageName}-${this.pageID}/edit`;
},
};
Cypress.on("uncaught:exception", () => {
// returning false here prevents Cypress from
// failing the test
@ -46,6 +57,24 @@ Cypress.on("fail", (error) => {
Cypress.env("MESSAGES", MESSAGES);
before(function () {
if (rapidMode.enabled) {
cy.startServerAndRoutes();
cy.getCookie("SESSION").then((cookie) => {
if (!cookie) {
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
}
});
Cypress.Cookies.preserveOnce("SESSION", "remember_token");
cy.visit(rapidMode.url());
cy.wait("@getWorkspace");
}
});
before(function () {
if (rapidMode.enabled) {
return;
}
//console.warn = () => {}; //to remove all warnings in cypress console
initLocalstorage();
initLocalstorageRegistry();
@ -86,12 +115,14 @@ before(function () {
});
before(function () {
if (rapidMode.enabled) {
return;
}
//console.warn = () => {};
Cypress.Cookies.preserveOnce("SESSION", "remember_token");
const username = Cypress.env("USERNAME");
const password = Cypress.env("PASSWORD");
cy.LoginFromAPI(username, password);
cy.wait("@getMe");
cy.wait(3000);
cy.get(".t--applications-container .createnew")
.should("be.visible")
@ -122,6 +153,9 @@ beforeEach(function () {
});
after(function () {
if (rapidMode.enabled) {
return;
}
//-- Deleting the application by Api---//
cy.DeleteAppByApi();
//-- LogOut Application---//