chore: Refactor RapidMode and add optimization if a test uses DSL (#23338)
Fixes #23264
This commit is contained in:
parent
4527630e4b
commit
e6c9a4d0aa
46
app/client/cypress/support/RapidMode.ts
Normal file
46
app/client/cypress/support/RapidMode.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Sample configuration to be appended to cypress.env.json file
|
||||
* Documentation on using it is here : https://github.com/appsmithorg/appsmith/blob/release/contributions/docs/TestAutomation.md
|
||||
*
|
||||
* "RAPID_MODE": {
|
||||
"enabled" : true, // Set it to true to enable rapid mode, otherwise set it to false
|
||||
"appName": "5f8e1666", // Pass your app name here. Given value is a sample value for reference
|
||||
"pageName": "page-1", // Pass your page name here. Given value is a sample value for reference
|
||||
"pageID": "64635173cc2cee025a77f489", // Pass your PageID here. Given value is a sample value for reference
|
||||
"url": "https://dev.appsmith.com/app/5f8e1666/page1-64635173cc2cee025a77f489/edit", // You can choose to pass in url of your app instead of individual parameters above.
|
||||
"usesDSL": true // Set it to false, if your test doesn't use DSL. If your test uses DSL, you can choose to enable this flag to skip multiple visits to the workspace page.
|
||||
}
|
||||
*/
|
||||
class RapidModeConfig {
|
||||
config: Record<string, any>;
|
||||
static _instance: RapidModeConfig;
|
||||
|
||||
private constructor() {
|
||||
this.config = Cypress.env("RAPID_MODE") || {};
|
||||
}
|
||||
|
||||
static getInstance() {
|
||||
if (!RapidModeConfig._instance) {
|
||||
RapidModeConfig._instance = new RapidModeConfig();
|
||||
}
|
||||
|
||||
return RapidModeConfig._instance;
|
||||
}
|
||||
|
||||
url() {
|
||||
const appName = this.config.appName;
|
||||
const pageName = this.config.pageName;
|
||||
const pageID = this.config.pageID;
|
||||
const parsedURL = this.config.url;
|
||||
|
||||
if (parsedURL.length > 0) {
|
||||
return parsedURL;
|
||||
} else {
|
||||
return `app/${appName}/${pageName}-${pageID}/edit`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const RapidMode = RapidModeConfig.getInstance();
|
||||
|
||||
export default RapidMode;
|
||||
|
|
@ -32,6 +32,7 @@ const queryLocators = require("../locators/QueryEditor.json");
|
|||
const welcomePage = require("../locators/welcomePage.json");
|
||||
const publishWidgetspage = require("../locators/publishWidgetspage.json");
|
||||
import { ObjectsRegistry } from "../support/Objects/Registry";
|
||||
import RapidMode from "./RapidMode";
|
||||
|
||||
const propPane = ObjectsRegistry.PropertyPane;
|
||||
const agHelper = ObjectsRegistry.AggregateHelper;
|
||||
|
|
@ -607,10 +608,13 @@ Cypress.Commands.add("generateUUID", () => {
|
|||
});
|
||||
|
||||
Cypress.Commands.add("addDsl", (dsl) => {
|
||||
let currentURL, pageid, layoutId, appId;
|
||||
let pageid, layoutId, appId;
|
||||
cy.url().then((url) => {
|
||||
currentURL = url;
|
||||
pageid = currentURL.split("/")[5]?.split("-").pop();
|
||||
if (RapidMode.config.enabled && RapidMode.config.usesDSL) {
|
||||
pageid = RapidMode.config.pageID;
|
||||
} else {
|
||||
pageid = url.split("/")[5]?.split("-").pop();
|
||||
}
|
||||
|
||||
//Fetch the layout id
|
||||
cy.request("GET", "api/v1/pages/" + pageid).then((response) => {
|
||||
|
|
@ -635,7 +639,12 @@ Cypress.Commands.add("addDsl", (dsl) => {
|
|||
}).then((response) => {
|
||||
cy.log(response.body);
|
||||
expect(response.status).equal(200);
|
||||
if (RapidMode.config.enabled && RapidMode.config.usesDSL) {
|
||||
cy.visit(RapidMode.url());
|
||||
} else {
|
||||
cy.reload();
|
||||
}
|
||||
|
||||
cy.wait("@getWorkspace");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import { initLocalstorage } from "./commands";
|
|||
import "./dataSourceCommands";
|
||||
import "./gitSync";
|
||||
import { initLocalstorageRegistry } from "./Objects/Registry";
|
||||
import RapidMode from "./RapidMode.ts";
|
||||
|
||||
import "./WorkspaceCommands";
|
||||
import "./queryCommands";
|
||||
import "./widgetCommands";
|
||||
|
|
@ -34,17 +36,6 @@ 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
|
||||
|
|
@ -58,7 +49,7 @@ Cypress.on("fail", (error) => {
|
|||
Cypress.env("MESSAGES", MESSAGES);
|
||||
|
||||
before(function () {
|
||||
if (rapidMode.enabled) {
|
||||
if (RapidMode.config.enabled) {
|
||||
cy.startServerAndRoutes();
|
||||
cy.getCookie("SESSION").then((cookie) => {
|
||||
if (!cookie) {
|
||||
|
|
@ -67,13 +58,15 @@ before(function () {
|
|||
});
|
||||
|
||||
Cypress.Cookies.preserveOnce("SESSION", "remember_token");
|
||||
cy.visit(rapidMode.url());
|
||||
if (!RapidMode.config.usesDSL) {
|
||||
cy.visit(RapidMode.url());
|
||||
cy.wait("@getWorkspace");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
before(function () {
|
||||
if (rapidMode.enabled) {
|
||||
if (RapidMode.config.enabled) {
|
||||
return;
|
||||
}
|
||||
//console.warn = () => {}; //to remove all warnings in cypress console
|
||||
|
|
@ -116,7 +109,7 @@ before(function () {
|
|||
});
|
||||
|
||||
before(function () {
|
||||
if (rapidMode.enabled) {
|
||||
if (RapidMode.config.enabled) {
|
||||
return;
|
||||
}
|
||||
//console.warn = () => {};
|
||||
|
|
@ -154,7 +147,7 @@ beforeEach(function () {
|
|||
});
|
||||
|
||||
after(function () {
|
||||
if (rapidMode.enabled) {
|
||||
if (RapidMode.config.enabled) {
|
||||
return;
|
||||
}
|
||||
//-- Deleting the application by Api---//
|
||||
|
|
|
|||
|
|
@ -41,6 +41,27 @@
|
|||
If you want to add a new env variable to cypress tests, add it to the `cypress.env.json` file and also in the documentation above.
|
||||
|
||||
All ENV variables from your `.env` file and all `APPSMITH_*` env variables from `process.env` are accessible with the `Cypress.env()` method.
|
||||
|
||||
## Speeding up debugging/writing tests
|
||||
|
||||
- The test suite has a flag to enable rapid mode, which skips a few test environment setup steps if it is already setup.
|
||||
- This speeds up the execution of the test run and is helpful during debugging and writing tests. Some of the steps that it skips are,
|
||||
- Creation of a new test app everytime. We can pass an app id to the test so that it can reuse it and avoid creating a new app everytime.
|
||||
- Skip login if the user is already logged in from previous test run session.
|
||||
- Skip multiple visit to the workspace page if a test uses DSL for loading fixtures. If a test uses DSL, a visit to the workspace is mandatory. Thus avoiding multiple visits to the workspace page saves time during test run.
|
||||
- To enable rapid mode for your test, you can add following configuration to your `cypress.env.json` file created above,
|
||||
```
|
||||
"RAPID_MODE": {
|
||||
"enabled" : true, // Set it to true to enable rapid mode, otherwise set it to false
|
||||
"appName": "5f8e1666", // Pass your app name here. Given value is a sample value for reference
|
||||
"pageName": "page-1", // Pass your page name here. Given value is a sample value for reference
|
||||
"pageID": "64635173cc2cee025a77f489", // Pass your PageID here. Given value is a sample value for reference
|
||||
"url": "https://dev.appsmith.com/app/5f8e1666/page1-64635173cc2cee025a77f489/edit", // You can choose to pass in url of your app instead of individual parameters above.
|
||||
"usesDSL": true // Set it to false, if your test doesn't use DSL. If your test uses DSL, you can choose to enable this flag to skip multiple visits to the workspace page.
|
||||
}
|
||||
```
|
||||
- You can either pass in complete url for your app in the test or pass in parameters for your app and the url will be generated on its own.
|
||||
|
||||
## How do I add environment variables required for Cypress tests?
|
||||
|
||||
**Note:** This can only be done by the project maintainers. Please contact one of them if you require this step to be accomplished.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user