PromucFlow_constructor/app/client/cypress/support/e2e.js
sharanya-appsmith a1fb4ba197
test: Cypress - Added cypress grep library (#29259)
Leveraging the library

[cypress-grep](https://github.com/cypress-io/cypress/tree/develop/npm/grep).
Using this we can tag testcases with relevant tags and use it to run
specific testcases.

**Command to run in local:** 
`CYPRESS_grepTags=@tag.Binding,@tag.Git npx cypress run
`
Pass the tags to CYPRESS_grepTags argument and only the test cases which
has the
tags passed will be picked to run. ex `@tag.Binding and @tag.Git` are
the tag names here.

**Tags can be added in the description on the test case like** 
`{ tags: ["@tag.Datasource"] }` for a single tag
`{ tags: ["@tag.Datasource", "@tag.Git"] }` for multiple tags 

**How to run In CI**
Single Tag - `/ok-to-test tags=@tag.Binding`
Multiple tag - `/ok-to-test tags=@tag.Binding,@tag.Git`


**TODOs in the next release:** 
- [ ] Add tags.ts file with all needed tags
- [ ] Add tags to remaining spec files. 
- [ ] Fail the PR run if tags added are not from tag.ts and post the
message on the same

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update

#### How Has This Been Tested?
- [x] Manual
- [ ] JUnit
- [ ] Jest
- [x] Cypress

## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [x] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [x] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed


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

- **New Features**
  - Added a search functionality to the app.

- **Enhancements**
- Integrated search bar at the top of the `Hero` component and a
`Search` component to the `App` component.
  - Added styles for the search bar.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2023-12-07 18:23:27 +05:30

182 lines
5.5 KiB
JavaScript

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
/// <reference types="Cypress" />
/// <reference types='cypress-tags' />
import "cypress-real-events/support";
import "cypress-wait-until";
import "cypress-network-idle";
import "cypress-xpath";
import * as MESSAGES from "../../../client/src/ce/constants/messages.ts";
import "./ApiCommands";
// Import commands.js using ES2015 syntax:
import "./commands";
import { initLocalstorage, addIndexedDBKey } from "./commands";
import "./dataSourceCommands";
import "./gitSync";
import { initLocalstorageRegistry } from "./Objects/Registry";
import RapidMode from "./RapidMode.ts";
import "cypress-mochawesome-reporter/register";
import installLogsCollector from "cypress-terminal-report/src/installLogsCollector";
import { CURRENT_REPO, REPO } from "../fixtures/REPO";
import "./WorkspaceCommands";
import "./queryCommands";
import "./widgetCommands";
import "./themeCommands";
import "./AdminSettingsCommands";
import "cypress-plugin-tab";
import {
FEATURE_WALKTHROUGH_INDEX_KEY,
WALKTHROUGH_TEST_PAGE,
} from "./Constants.js";
const registerCypressGrep = require("@cypress/grep");
/// <reference types="cypress-xpath" />
registerCypressGrep();
installLogsCollector();
Cypress.on("uncaught:exception", (error) => {
//cy.log(error.message);
return false; // returning false here prevents Cypress from failing the test
});
Cypress.on("fail", (error) => {
cy.log(error.message);
throw error; // throw error to have test fail
});
Cypress.env("MESSAGES", MESSAGES);
let dataSet; // Declare a variable to hold the test data
before(function () {
if (RapidMode.config.enabled) {
cy.startServerAndRoutes();
cy.getCookie("SESSION").then((cookie) => {
if (!cookie) {
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
}
});
//Cypress.Cookies.preserveOnce("SESSION", "remember_token");
if (!RapidMode.config.usesDSL) {
cy.visit(RapidMode.url());
cy.wait("@getWorkspace");
}
}
});
before(function () {
if (RapidMode.config.enabled) {
return;
}
//console.warn = () => {}; //to remove all warnings in cypress console
initLocalstorage();
initLocalstorageRegistry();
cy.startServerAndRoutes();
// Clear indexedDB
cy.window().then((window) => {
window.indexedDB.deleteDatabase("Appsmith");
});
cy.visit("/setup/welcome", { timeout: 60000 });
cy.wait("@getMe");
cy.wait(2000);
const username = Cypress.env("USERNAME");
const password = Cypress.env("PASSWORD");
cy.url().then((url) => {
if (url.indexOf("setup/welcome") > -1) {
cy.createSuperUser();
cy.SignupFromAPI(
Cypress.env("TESTUSERNAME1"),
Cypress.env("TESTPASSWORD1"),
);
cy.LogOut();
cy.SignupFromAPI(
Cypress.env("TESTUSERNAME2"),
Cypress.env("TESTPASSWORD2"),
);
cy.LogOut();
cy.SignupFromAPI(
Cypress.env("TESTUSERNAME3"),
Cypress.env("TESTPASSWORD3"),
);
cy.LogOut();
cy.SignupFromAPI(
Cypress.env("TESTUSERNAME4"),
Cypress.env("TESTPASSWORD4"),
);
cy.LogOut();
cy.LoginFromAPI(username, password);
} else if (url.indexOf("user/login") > -1) {
//Cypress.Cookies.preserveOnce("SESSION", "remember_token");
cy.LoginFromAPI(username, password);
cy.wait(3000);
}
});
if (CURRENT_REPO === REPO.EE) {
cy.wait(2000);
cy.url().then((url) => {
if (url.indexOf("/license") > -1) {
cy.validateLicense();
}
});
}
if (!Cypress.currentTest.titlePath[0].includes(WALKTHROUGH_TEST_PAGE)) {
// Adding key FEATURE_WALKTHROUGH (which is used to check if the walkthrough is already shown to the user or not) for non walkthrough cypress tests (to not show walkthrough)
addIndexedDBKey(FEATURE_WALKTHROUGH_INDEX_KEY, {
ab_ds_binding_enabled: true,
ab_ds_schema_enabled: true,
binding_widget: true,
});
}
//console.warn = () => {};
cy.CreateNewAppInNewWorkspace(); //Creating new workspace and app
cy.fixture("TestDataSet1").then(function (data) {
this.dataSet = data;
});
});
beforeEach(function () {
//cy.window().then((win) => (win.onbeforeunload = undefined));
if (!navigator.userAgent.includes("Cypress")) {
window.addEventListener("beforeunload", this.beforeunloadFunction);
}
initLocalstorage();
//Cypress.Cookies.preserveOnce("SESSION", "remember_token");
cy.startServerAndRoutes();
//-- Delete local storage data of entity explorer
cy.DeleteEntityStateLocalStorage();
cy.intercept("api/v1/admin/env", (req) => {
req.headers["origin"] = Cypress.config("baseUrl");
});
});
after(function () {
if (RapidMode.config.enabled) {
return;
}
//-- Deleting the application by Api---//
cy.DeleteAppByApi();
cy.DeleteWorkspaceByApi();
//-- LogOut Application---//
//cy.LogOut(false);
// Commenting until Upgrade Appsmith cases are fixed
// const tedUrl = "http://localhost:5001/v1/parent/cmd";
// cy.log("Start the appsmith container");
// cy.StartContainer(tedUrl, "appsmith"); // start the old container
});