## Description - This PR fixes the RenameApplication flakyness in CI with added dynamic check - Also replacing js cy.renameApp to TS helper - Flaky fixes - cypress/e2e/Regression/ClientSide/Workspace/MemberRoles_Spec.ts (entire spec updates for EnableGAC, removed signout from 'it' blocks) - cypress/e2e/Regression/ClientSide/Workspace/ShareAppTests_Spec.ts (7th flaky fixed) - cypress/e2e/Regression/ClientSide/SetProperty/WidgetPropertySetters2_spec.ts (5th test) - cypress/e2e/Regression/ClientSide/Templates/Fork_Template_Existing_app_spec.js (2nd - added validation to match the test description, 1st & 3rd - removed static waits, Added multiple dynamic checks) - cypress/e2e/Regression/ClientSide/OtherUIFeatures/ApplicationURL_spec.js (3rd & 4th flaky tests) - homePage.AssertViewPageLoad() created - homePage.LaunchAppFromAppHover() improved - homePage.Signout() - added dynamic checks - Added more validation to homePage.Signup() method with Dynamic checks - homePage.LeaveWorkspace() removed redundant SelectWorkspace call - admingSettings.EnableGAC() - added dynamic checks - featureFlagIntercept - removed static sleep, reload check improved - agHelper.VisitNAssert() - removed static sleep - homePage.OpenMembersPageForWorkspace() - removed sleep, added dynamic checks #### 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 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **Refactor** - Enhanced Cypress test commands across multiple test suites for improved efficiency and readability. - Refactored conditional checks and method invocations for better test scenario handling. - **Tests** - Updated testing approaches for application deployment, workspace management, and error handling. - Introduced new assertions for UI visibility and functional behavior in automated tests. - **Chores** - Optimized GitHub Actions workflow by adjusting the matrix count for build processes. - Added new test specs for limited tests in the client-side regression suite. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
503 lines
16 KiB
JavaScript
503 lines
16 KiB
JavaScript
/* eslint-disable cypress/no-unnecessary-waiting */
|
|
/* eslint-disable cypress/no-assigning-return-values */
|
|
|
|
import { AppSidebar } from "./Pages/EditorNavigation";
|
|
|
|
require("cy-verify-downloads").addCustomCommand();
|
|
require("cypress-file-upload");
|
|
import gitSyncLocators from "../locators/gitSyncLocators";
|
|
import homePage from "../locators/HomePage";
|
|
import { ObjectsRegistry } from "../support/Objects/Registry";
|
|
|
|
let gitSync = ObjectsRegistry.GitSync,
|
|
agHelper = ObjectsRegistry.AggregateHelper,
|
|
dataManager = ObjectsRegistry.DataManager,
|
|
assertHelper = ObjectsRegistry.AssertHelper,
|
|
homePageTS = ObjectsRegistry.HomePage;
|
|
|
|
const commonLocators = require("../locators/commonlocators.json");
|
|
const GITHUB_API_BASE = "https://api.github.com";
|
|
|
|
Cypress.Commands.add("revokeAccessGit", (appName) => {
|
|
cy.xpath("//span[text()= `${appName}`]").parent().next().click();
|
|
cy.get(gitSyncLocators.disconnectAppNameInput).type(appName);
|
|
cy.get(gitSyncLocators.disconnectButton).click();
|
|
cy.intercept("POST", "api/v1/git/disconnect/app/*").as("disconnect");
|
|
cy.get(gitSyncLocators.disconnectButton).click();
|
|
cy.wait("@disconnect").should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
200,
|
|
);
|
|
cy.window()
|
|
.its("store")
|
|
.invoke("getState")
|
|
.then((state) => {
|
|
const { id, name } = state.ui.gitSync.disconnectingGitApp;
|
|
expect(name).to.eq("");
|
|
expect(id).to.eq("");
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add(
|
|
"connectToGitRepo",
|
|
(repo, shouldCommit = true, assertConnectFailure) => {
|
|
const testEmail = "test@test.com";
|
|
const testUsername = "testusername";
|
|
const owner = Cypress.env("TEST_GITHUB_USER_NAME");
|
|
|
|
let generatedKey;
|
|
// open gitSync modal
|
|
cy.get(homePage.deployPopupOptionTrigger).click();
|
|
cy.get(homePage.connectToGitBtn).click({ force: true });
|
|
|
|
// cy.intercept(
|
|
// {
|
|
// url: "api/v1/git/connect/app/*",
|
|
// hostname: window.location.host,
|
|
// },
|
|
// (req) => {
|
|
// req.headers["origin"] = "Cypress";
|
|
// },
|
|
// );
|
|
|
|
cy.intercept("POST", "/api/v1/applications/ssh-keypair/*").as(
|
|
`generateKey-${repo}`,
|
|
);
|
|
|
|
cy.get(gitSyncLocators.gitRepoInput).type(
|
|
`git@github.com:${owner}/${repo}.git`,
|
|
);
|
|
cy.get(gitSyncLocators.generateDeployKeyBtn).click();
|
|
cy.wait(`@generateKey-${repo}`).then((result) => {
|
|
generatedKey = result.response.body.data.publicKey;
|
|
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
|
|
// fetch the generated key and post to the github repo
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${GITHUB_API_BASE}/repos/${Cypress.env(
|
|
"TEST_GITHUB_USER_NAME",
|
|
)}/${repo}/keys`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
|
|
},
|
|
body: {
|
|
title: "key0",
|
|
key: generatedKey,
|
|
},
|
|
});
|
|
|
|
cy.get(gitSyncLocators.useGlobalGitConfig).click({ force: true });
|
|
|
|
cy.get(gitSyncLocators.gitConfigNameInput).type(
|
|
`{selectall}${testUsername}`,
|
|
);
|
|
cy.get(gitSyncLocators.gitConfigEmailInput).type(
|
|
`{selectall}${testEmail}`,
|
|
);
|
|
// click on the connect button and verify
|
|
cy.get(gitSyncLocators.connectSubmitBtn).click();
|
|
|
|
if (!assertConnectFailure) {
|
|
// check for connect success
|
|
cy.wait("@connectGitLocalRepo").should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
200,
|
|
);
|
|
}
|
|
|
|
// click commit button
|
|
/* if (shouldCommit) {
|
|
cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit");
|
|
cy.get(gitSyncLocators.commitButton).click();
|
|
// check for commit success
|
|
cy.wait("@commit").should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
201,
|
|
);
|
|
|
|
cy.get(gitSyncLocators.closeGitSyncModal).click();
|
|
}
|
|
} else {
|
|
cy.wait("@connectGitLocalRepo").then((interception) => {
|
|
const status = interception.response.body.responseMeta.status;
|
|
expect(status).to.be.gte(400);
|
|
});
|
|
} */
|
|
cy.get(gitSyncLocators.closeGitSyncModal).click();
|
|
});
|
|
},
|
|
);
|
|
|
|
Cypress.Commands.add("latestDeployPreview", () => {
|
|
cy.intercept("POST", "/api/v1/applications/publish/*").as("publishApp");
|
|
// Wait before publish
|
|
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
|
cy.wait(2000);
|
|
cy.assertPageSave();
|
|
|
|
// Stubbing window.open to open in the same tab
|
|
cy.window().then((window) => {
|
|
cy.stub(window, "open").callsFake((url) => {
|
|
window.location.href = Cypress.config().baseUrl + url.substring(1);
|
|
window.location.target = "_self";
|
|
});
|
|
});
|
|
cy.get(gitSyncLocators.bottomBarCommitButton).click();
|
|
cy.wait(2000); // wait for modal to load
|
|
cy.xpath("//span[text()='Latest deployed preview']").click();
|
|
cy.log("pagename: " + localStorage.getItem("PageName"));
|
|
cy.wait(5000); //wait time for page to load!
|
|
});
|
|
|
|
Cypress.Commands.add("createGitBranch", (branch) => {
|
|
agHelper.AssertElementVisibility(gitSync._bottomBarPull);
|
|
cy.get(gitSyncLocators.branchButton).click({ force: true });
|
|
agHelper.AssertElementVisibility(gitSyncLocators.branchSearchInput);
|
|
agHelper.ClearNType(gitSyncLocators.branchSearchInput, `${branch}`);
|
|
// increasing timeout to reduce flakyness
|
|
cy.get(".ads-v2-spinner", {
|
|
timeout: Cypress.config().pageLoadTimeout,
|
|
}).should("exist");
|
|
cy.get(".ads-v2-spinner", {
|
|
timeout: Cypress.config().pageLoadTimeout,
|
|
}).should("not.exist");
|
|
assertHelper.AssertDocumentReady();
|
|
AppSidebar.assertVisible(Cypress.config().pageLoadTimeout);
|
|
});
|
|
|
|
Cypress.Commands.add("switchGitBranch", (branch, expectError) => {
|
|
agHelper.AssertElementVisibility(gitSync._bottomBarPull);
|
|
cy.get(gitSyncLocators.branchButton).click({ force: true });
|
|
agHelper.AssertElementVisibility(gitSyncLocators.branchSearchInput);
|
|
agHelper.ClearNType(gitSyncLocators.branchSearchInput, `${branch}`);
|
|
cy.get(gitSyncLocators.branchListItem).contains(branch).click();
|
|
if (!expectError) {
|
|
// increasing timeout to reduce flakyness
|
|
cy.get(".ads-v2-spinner", {
|
|
timeout: Cypress.config().pageLoadTimeout,
|
|
}).should("exist");
|
|
cy.get(".ads-v2-spinner", {
|
|
timeout: Cypress.config().pageLoadTimeout,
|
|
}).should("not.exist");
|
|
}
|
|
assertHelper.AssertDocumentReady();
|
|
AppSidebar.assertVisible(Cypress.config().pageLoadTimeout);
|
|
});
|
|
|
|
Cypress.Commands.add("createTestGithubRepo", (repo, privateFlag = false) => {
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${GITHUB_API_BASE}/user/repos`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
|
|
},
|
|
body: {
|
|
name: repo,
|
|
private: privateFlag,
|
|
},
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add("mergeViaGithubApi", ({ base, head, repo }) => {
|
|
const owner = Cypress.env("TEST_GITHUB_USER_NAME");
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${GITHUB_API_BASE}/repos/${owner}/${repo}/merges`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
|
|
},
|
|
body: {
|
|
base,
|
|
head,
|
|
},
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add("deleteTestGithubRepo", (repo) => {
|
|
cy.request({
|
|
method: "DELETE",
|
|
url: `${GITHUB_API_BASE}/repos/${Cypress.env(
|
|
"TEST_GITHUB_USER_NAME",
|
|
)}/${repo}`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
|
|
},
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add(
|
|
"renameBranchViaGithubApi",
|
|
(repo, currentName, newName) => {
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${GITHUB_API_BASE}/repos/${Cypress.env(
|
|
"TEST_GITHUB_USER_NAME",
|
|
)}/${repo}/branches/${currentName}/rename`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
|
|
},
|
|
body: {
|
|
new_name: newName,
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
Cypress.Commands.add("commitAndPush", (assertFailure) => {
|
|
cy.get(homePage.publishButton).click();
|
|
agHelper.AssertElementExist(gitSync._bottomBarPull);
|
|
cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit");
|
|
cy.get(gitSyncLocators.commitButton).click();
|
|
if (!assertFailure) {
|
|
// check for commit success
|
|
//adding timeout since commit is taking longer sometimes
|
|
cy.wait("@commit", { timeout: 35000 }).should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
201,
|
|
);
|
|
cy.wait(3000);
|
|
} else {
|
|
cy.wait("@commit", { timeout: 35000 }).then((interception) => {
|
|
const status = interception.response.body.responseMeta.status;
|
|
expect(status).to.be.gte(400);
|
|
});
|
|
}
|
|
|
|
cy.get(gitSyncLocators.closeGitSyncModal).click();
|
|
});
|
|
|
|
// todo rishabh s: refactor
|
|
Cypress.Commands.add(
|
|
"createAppAndConnectGit",
|
|
(appname, shouldConnect = true, assertConnectFailure) => {
|
|
cy.get(homePage.homeIcon).click({ force: true });
|
|
cy.get(homePage.createNew).first().click({ force: true });
|
|
cy.wait("@createNewApplication").should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
201,
|
|
);
|
|
cy.get("#loading").should("not.exist");
|
|
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
|
cy.wait(2000);
|
|
|
|
homePageTS.RenameApplication(appname);
|
|
|
|
cy.createTestGithubRepo(appname, true);
|
|
cy.connectToGitRepo(appname, false, assertConnectFailure);
|
|
cy.get(gitSyncLocators.closeGitSyncModal).click({ force: true });
|
|
},
|
|
);
|
|
|
|
Cypress.Commands.add("merge", (destinationBranch) => {
|
|
agHelper.AssertElementExist(gitSync._bottomBarPull);
|
|
cy.get(gitSyncLocators.bottomBarMergeButton).click({ force: true });
|
|
//cy.wait(6000); // wait for git status call to finish
|
|
/*cy.wait("@gitStatus").should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
200,
|
|
); */
|
|
|
|
agHelper.AssertElementEnabledDisabled(
|
|
gitSyncLocators.mergeBranchDropdownDestination,
|
|
0,
|
|
false,
|
|
);
|
|
cy.wait(6000);
|
|
cy.get(gitSyncLocators.mergeBranchDropdownDestination).click();
|
|
cy.get(commonLocators.dropdownmenu).contains(destinationBranch).click();
|
|
agHelper.AssertElementAbsence(gitSync._checkMergeability, 35000);
|
|
assertHelper.WaitForNetworkCall("mergeStatus");
|
|
cy.get("@mergeStatus").should(
|
|
"have.nested.property",
|
|
"response.body.data.isMergeAble",
|
|
true,
|
|
);
|
|
cy.wait(2000);
|
|
cy.contains(Cypress.env("MESSAGES").NO_MERGE_CONFLICT());
|
|
cy.get(gitSyncLocators.mergeCTA).click();
|
|
assertHelper.AssertNetworkStatus("mergeBranch", 200);
|
|
agHelper.AssertContains(Cypress.env("MESSAGES").MERGED_SUCCESSFULLY());
|
|
});
|
|
|
|
Cypress.Commands.add(
|
|
"importAppFromGit",
|
|
(repo, assertConnectFailure, failureMessage) => {
|
|
const testEmail = "test@test.com";
|
|
const testUsername = "testusername";
|
|
const owner = Cypress.env("TEST_GITHUB_USER_NAME");
|
|
|
|
let generatedKey;
|
|
// cy.intercept(
|
|
// {
|
|
// url: "api/v1/git/connect/app/*",
|
|
// hostname: window.location.host,
|
|
// },
|
|
// (req) => {
|
|
// req.headers["origin"] = "Cypress";
|
|
// },
|
|
// );
|
|
cy.intercept("GET", "api/v1/git/import/keys?keyType=ECDSA").as(
|
|
`generateKey-${repo}`,
|
|
);
|
|
cy.get(gitSyncLocators.gitRepoInput).type(
|
|
//`git@github.com:${owner}/${repo}.git`,
|
|
`${dataManager.GITEA_API_URL_TED}/${repo}.git`,
|
|
);
|
|
cy.get(gitSyncLocators.generateDeployKeyBtn).click();
|
|
cy.wait(`@generateKey-${repo}`).then((result) => {
|
|
generatedKey = result.response.body.data.publicKey;
|
|
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
|
|
// fetch the generated key and post to the github repo
|
|
// cy.request({
|
|
// method: "POST",
|
|
// url: `${GITHUB_API_BASE}/repos/${Cypress.env(
|
|
// "TEST_GITHUB_USER_NAME",
|
|
// )}/${repo}/keys`,
|
|
// headers: {
|
|
// Authorization: `token ${Cypress.env("GITHUB_PERSONAL_ACCESS_TOKEN")}`,
|
|
// },
|
|
// body: {
|
|
// title: "key0",
|
|
// key: generatedKey,
|
|
// },
|
|
// });
|
|
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${dataManager.GITEA_API_BASE_TED}:${dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repo}/keys`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
|
|
},
|
|
body: {
|
|
title: "key1",
|
|
key: generatedKey,
|
|
read_only: false,
|
|
},
|
|
});
|
|
|
|
cy.get(gitSyncLocators.useGlobalGitConfig).click({ force: true });
|
|
|
|
cy.get(gitSyncLocators.gitConfigNameInput).type(
|
|
`{selectall}${testUsername}`,
|
|
);
|
|
cy.get(gitSyncLocators.gitConfigEmailInput).type(
|
|
`{selectall}${testEmail}`,
|
|
);
|
|
// click on the connect button and verify
|
|
cy.get(gitSyncLocators.connectSubmitBtn).click();
|
|
|
|
if (!assertConnectFailure) {
|
|
// check for connect success
|
|
cy.wait("@importFromGit").should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
201,
|
|
);
|
|
} else {
|
|
cy.wait("@importFromGit").then((interception) => {
|
|
const status = interception.response.body.responseMeta.status;
|
|
const message = interception.response.body.responseMeta.error.message;
|
|
expect(status).to.be.gte(400);
|
|
expect(message).to.contain(failureMessage);
|
|
});
|
|
}
|
|
});
|
|
},
|
|
);
|
|
|
|
Cypress.Commands.add("gitDiscardChanges", () => {
|
|
cy.get(gitSyncLocators.bottomBarCommitButton).click();
|
|
cy.get(gitSyncLocators.discardChanges).should("be.visible");
|
|
cy.get(gitSyncLocators.discardChanges)
|
|
.children()
|
|
.should("have.text", "Discard & pull");
|
|
cy.get(gitSyncLocators.discardChanges).click();
|
|
cy.contains(Cypress.env("MESSAGES").DISCARD_CHANGES_WARNING());
|
|
cy.get(gitSyncLocators.discardChanges)
|
|
.children()
|
|
.should("have.text", "Are you sure?");
|
|
cy.get(gitSyncLocators.discardChanges).click();
|
|
cy.contains(Cypress.env("MESSAGES").DISCARDING_AND_PULLING_CHANGES());
|
|
cy.validateToastMessage("Discarded changes successfully.");
|
|
cy.wait(2000);
|
|
assertHelper.AssertContains(
|
|
"Unable to import application in workspace",
|
|
"not.exist",
|
|
);
|
|
});
|
|
|
|
Cypress.Commands.add(
|
|
"regenerateSSHKey",
|
|
(repo, generateKey = true, protocol = "ECDSA") => {
|
|
let generatedKey;
|
|
cy.get(gitSyncLocators.bottomBarCommitButton).click();
|
|
cy.get("[data-testid=t--tab-GIT_CONNECTION]").click();
|
|
cy.wait(2000);
|
|
cy.get(gitSyncLocators.SSHKeycontextmenu).eq(2).click();
|
|
if (protocol === "ECDSA") {
|
|
cy.get(gitSyncLocators.regenerateSSHKeyECDSA).click();
|
|
} else if (protocol === "RSA") {
|
|
cy.get(gitSyncLocators.regenerateSSHKeyRSA).click();
|
|
}
|
|
cy.contains(Cypress.env("MESSAGES").REGENERATE_KEY_CONFIRM_MESSAGE());
|
|
cy.xpath(gitSyncLocators.confirmButton).click();
|
|
if (protocol === "ECDSA") {
|
|
cy.intercept("POST", "/api/v1/applications/ssh-keypair/*").as(
|
|
`generateKey-${repo}`,
|
|
);
|
|
} else if (protocol === "RSA") {
|
|
cy.intercept("POST", "/api/v1/applications/ssh-keypair/*?keyType=RSA").as(
|
|
`generateKey-${repo}-RSA`,
|
|
);
|
|
}
|
|
|
|
if (generateKey) {
|
|
if (protocol === "ECDSA") {
|
|
cy.wait(`@generateKey-${repo}`).then((result) => {
|
|
generatedKey = result.response.body.data.publicKey;
|
|
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
|
|
// fetch the generated key and post to the github repo
|
|
// cy.request({
|
|
// method: "POST",
|
|
// url: `${GITHUB_API_BASE}/repos/${Cypress.env(
|
|
// "TEST_GITHUB_USER_NAME",
|
|
// )}/${repo}/keys`,
|
|
// headers: {
|
|
// Authorization: `token ${Cypress.env(
|
|
// "GITHUB_PERSONAL_ACCESS_TOKEN",
|
|
// )}`,
|
|
// },
|
|
// body: {
|
|
// title: "key0",
|
|
// key: generatedKey,
|
|
// },
|
|
// });
|
|
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${dataManager.GITEA_API_BASE_TED}:${dataManager.GITEA_API_PORT_TED}/api/v1/repos/Cypress/${repo}/keys`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
|
|
},
|
|
body: {
|
|
title: "key1",
|
|
key: generatedKey,
|
|
read_only: false,
|
|
},
|
|
});
|
|
|
|
cy.get(gitSyncLocators.closeGitSyncModal);
|
|
});
|
|
} else if (protocol === "RSA") {
|
|
// doesn't work with github
|
|
}
|
|
}
|
|
},
|
|
);
|