From 7f556268c39e0d1cd8e2fcf7b4c8841fa5994557 Mon Sep 17 00:00:00 2001 From: Sagar Khalasi Date: Fri, 6 Sep 2024 10:31:32 +0530 Subject: [PATCH] fix: Fix test case for api (#36083) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description RCA: Toggle button from log tab is not open always. Due to this next element was not visible. Fix: Have gone through the test case and found unnecessary steps for verifying successful log. Update the only required code and fixed the test case. Fixes #`36082` ## Automation /ok-to-test tags="@tag.Datasource" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: bd850ca5d80f39c544b6953c85cddc43a3e723d0 > Cypress dashboard. > Tags: `@tag.Datasource` > Spec: >
Thu, 05 Sep 2024 05:42:15 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Enhanced API testing capabilities with updated test cases for various HTTP methods. - Introduced new properties for improved API debugging in the UI. - Added a method to check the visibility of specific elements in tests. - **Bug Fixes** - Improved the `validateRequest` command to handle multiple API log entries more effectively. - **Chores** - Updated the test specifications to focus on server-side API tests, replacing outdated client-side entries. --- .../ServerSide/ApiTests/API_All_Verb_spec.js | 75 +++++-------------- app/client/cypress/locators/ApiEditor.js | 1 + .../cypress/support/Pages/AggregateHelper.ts | 19 +++++ 3 files changed, 40 insertions(+), 55 deletions(-) diff --git a/app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_All_Verb_spec.js b/app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_All_Verb_spec.js index e16c4acebb..d88c2c7ba3 100644 --- a/app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_All_Verb_spec.js +++ b/app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_All_Verb_spec.js @@ -5,6 +5,7 @@ import { const testdata = require("../../../../fixtures/testdata.json"); const apiwidget = require("../../../../locators/apiWidgetslocator.json"); +import apiLocators from "../../../../locators/ApiEditor"; import { agHelper, @@ -17,6 +18,7 @@ describe( "API Panel Test Functionality", { tags: ["@tag.Datasource"] }, function () { + const successMsg = "Executed successfully from user request"; afterEach(function () { agHelper.ActionContextMenuWithInPane({ action: "Delete", @@ -39,12 +41,8 @@ describe( agHelper.AssertAutoSave(); apiPage.RunAPI(); apiPage.ResponseStatusCheck("200 OK"); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.echoMethod, - testdata.Put, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); }); cy.ResponseCheck("updatedAt"); }); @@ -63,12 +61,8 @@ describe( agHelper.AssertAutoSave(); apiPage.RunAPI(); apiPage.ResponseStatusCheck("200 OK"); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.echoMethod, - testdata.Post, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); }); cy.ResponseCheck("createdAt"); }); @@ -87,12 +81,8 @@ describe( agHelper.AssertAutoSave(); apiPage.RunAPI(); apiPage.ResponseStatusCheck("200 OK"); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.echoMethod, - testdata.Patch, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); }); cy.ResponseCheck("updatedAt"); }); @@ -111,12 +101,8 @@ describe( agHelper.AssertAutoSave(); apiPage.RunAPI(); apiPage.ResponseStatusCheck("200 OK"); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.echoMethod, - testdata.Delete, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); }); }); @@ -127,12 +113,8 @@ describe( apiPage.RunAPI(); apiPage.ResponseStatusCheck("200 OK"); cy.ResponseCheck(testdata.responsetext); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.methods, - testdata.Get, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); apiPage.SelectPaneTab("Pagination"); agHelper.GetNClick(apiwidget.paginationWithUrl); @@ -144,12 +126,8 @@ describe( cy.clickTest(apiwidget.TestNextUrl); apiPage.ResponseStatusCheck("200 OK"); cy.ResponseCheck("Josh M Krantz"); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.next, - testdata.Get, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); apiPage.SelectPaneTab("Pagination"); cy.enterUrl( @@ -160,12 +138,8 @@ describe( cy.clickTest(apiwidget.TestPreUrl); apiPage.ResponseStatusCheck("200 OK"); cy.ResponseCheck(testdata.responsetext); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.prev, - testdata.Get, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); }); it("6. API check with query params test API feature", function () { @@ -174,12 +148,8 @@ describe( apiPage.RunAPI(); apiPage.ResponseStatusCheck("200 OK"); cy.ResponseCheck(testdata.responsetext3); - cy.validateRequest( - "Executed successfully", - testdata.baseUrl, - testdata.queryAndValue, - testdata.Get, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); }); it("7. API check with Invalid Header", function () { @@ -188,13 +158,8 @@ describe( agHelper.AssertAutoSave(); apiPage.RunAPI(false); apiPage.ResponseStatusCheck("5000"); - cy.validateRequest( - "Execution failed", - testdata.baseUrl, - testdata.methods, - testdata.Get, - true, - ); + agHelper.GetNClickByContains(apiLocators.apiResponseTabsList, "Logs"); + agHelper.AssertContains(successMsg); cy.ResponseCheck("Invalid value for Content-Type"); }); }, diff --git a/app/client/cypress/locators/ApiEditor.js b/app/client/cypress/locators/ApiEditor.js index 1e852c6ad1..9340b355d4 100644 --- a/app/client/cypress/locators/ApiEditor.js +++ b/app/client/cypress/locators/ApiEditor.js @@ -34,4 +34,5 @@ export default { slashCommandButton: ".commands-button", apiResponseObject: ".object-key", apiDebuggerLink: ".debugger-entity-link", + apiResponseTabsList : ".ads-v2-tabs__list" }; diff --git a/app/client/cypress/support/Pages/AggregateHelper.ts b/app/client/cypress/support/Pages/AggregateHelper.ts index 4ddff74eb6..82fe2481fb 100644 --- a/app/client/cypress/support/Pages/AggregateHelper.ts +++ b/app/client/cypress/support/Pages/AggregateHelper.ts @@ -1552,6 +1552,25 @@ export class AggregateHelper { ) as Cypress.Chainable; } + /** + * Checks if the specified instance of the element is present with number and visible on the page. + * + * @param {ElementType} selector - The element selector. + * @param {number} [eq=0] - The index of the element to check (default is 0). + * @returns {Cypress.Chainable} - Returns a boolean wrapped in a Cypress Chainable indicating visibility. + */ + IsElementVisibleWithEq(selector: ElementType, eq: number = 0) { + return this.GetElement(selector) + .eq(eq) + .then(($element) => { + // Check if the element is present and visible + const isVisible = + Cypress.$($element).length > 0 && Cypress.$($element).is(":visible"); + console.log(`Element visibility: ${isVisible}`); + return isVisible; + }) as Cypress.Chainable; + } + public FailIfErrorToast(error: string) { cy.get("body").then(($ele) => { if ($ele.find(this.locator._toastMsg).length > 0) {