Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ describe(
cy.log("Creation of FirstAPI Action successful");
cy.enterDatasourceAndPath(testdata.baseUrl, testdata.methods);
cy.get(apiwidget.settings).click({ force: true });
cy.get(apiwidget.confirmBeforeExecute).click({ force: true });
cy.get("body").then((body) => {
if (body.find(apiwidget.confirmBeforeExecute).length > 0) {
cy.get(apiwidget.confirmBeforeExecute).click({ force: true });
} else {
cy.get(apiwidget.settings).click({ force: true });
cy.get(apiwidget.confirmBeforeExecute).click({ force: true });
}
});
Comment on lines +59 to +66

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve element interaction strategy

The current implementation uses jQuery-style DOM checks and forced clicks, which can lead to flaky tests. Consider using Cypress's built-in retry-ability and assertions instead.

Here's a more robust approach:

-      cy.get("body").then((body) => {
-        if (body.find(apiwidget.confirmBeforeExecute).length > 0) {
-          cy.get(apiwidget.confirmBeforeExecute).click({ force: true });
-        } else {
-          cy.get(apiwidget.settings).click({ force: true });
-          cy.get(apiwidget.confirmBeforeExecute).click({ force: true });
-        }
-      });
+      cy.get(apiwidget.settings).click();
+      cy.get(apiwidget.confirmBeforeExecute)
+        .should('be.visible')
+        .click();

Key improvements:

  1. Removes force: true clicks which bypass Cypress's actionability checks
  2. Uses Cypress's built-in retry-ability with should('be.visible')
  3. Simplifies the flow by letting Cypress handle the element's visibility

Committable suggestion skipped: line range outside the PR's diff.

cy.get(apiwidget.runQueryButton).click();
cy.get(".ads-v2-modal__content").find("button").contains("No").click();
cy.get(apiwidget.runQueryButton).children().should("have.length", 1);
Expand Down
2 changes: 1 addition & 1 deletion app/client/cypress/limited-tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# To run only limited tests - give the spec names in below format:
cypress/e2e/Regression/ClientSide/Templates/Fork_Template_spec.js
cypress/e2e/Regression/ServerSide/ApiTests/API_Edit_spec.js
# For running all specs - uncomment below:
#cypress/e2e/**/**/*

Expand Down