From a67f1fafcd7793b4f242acd549c2137d8e6fb4a6 Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Tue, 17 Oct 2023 20:58:50 +0530 Subject: [PATCH] fix: cypress tests as per new hash naming Some Cypress Tests are using hardcoded numbers in them. As new naming is based on random hash i have changed them accordingly. --- cypress/integration/control_attach.js | 10 ++++++++-- cypress/integration/control_data.js | 7 +++++-- cypress/integration/dashboard_chart.js | 2 +- cypress/integration/grid_keyboard_shortcut.js | 17 ++++++++++++----- cypress/integration/timeline.js | 2 +- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cypress/integration/control_attach.js b/cypress/integration/control_attach.js index ddaa22884d..6bb681a03e 100644 --- a/cypress/integration/control_attach.js +++ b/cypress/integration/control_attach.js @@ -107,7 +107,10 @@ context("Attach Control", () => { }; }, }); - cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); + cy.get("body").should(($body) => { + const dataRoute = $body.attr("data-route"); + expect(dataRoute).to.match(new RegExp(`^Form/${doctype}/new-${dt_in_route}-`)); + }); cy.get("body").should("have.attr", "data-ajax-state", "complete"); //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype @@ -127,7 +130,10 @@ context("Attach Control", () => { delete win.navigator.mediaDevices; }, }); - cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); + cy.get("body").should(($body) => { + const dataRoute = $body.attr("data-route"); + expect(dataRoute).to.match(new RegExp(`^Form/${doctype}/new-${dt_in_route}-`)); + }); cy.get("body").should("have.attr", "data-ajax-state", "complete"); //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype diff --git a/cypress/integration/control_data.js b/cypress/integration/control_data.js index 4c7ee589ab..019ce68214 100644 --- a/cypress/integration/control_data.js +++ b/cypress/integration/control_data.js @@ -49,7 +49,7 @@ context("Data Control", () => { cy.new_form("Test Data Control"); //Checking the URL for the new form of the doctype - cy.location("pathname").should("eq", "/app/test-data-control/new-test-data-control-1"); + cy.location("pathname").should("contains", "/app/test-data-control/new-test-data-control"); cy.get(".title-text").should("have.text", "New Test Data Control"); cy.get('.frappe-control[data-fieldname="name1"]') .find("label") @@ -128,7 +128,10 @@ context("Data Control", () => { cy.fill_field("phone", "9432380001", "Data"); cy.findByRole("button", { name: "Save" }).click({ force: true }); //Checking if the fields contains the data which has been filled in - cy.location("pathname").should("not.be", "/app/test-data-control/new-test-data-control-1"); + cy.location("pathname").should( + "not.contains", + "/app/test-data-control/new-test-data-control" + ); cy.get_field("name1").should("have.value", "Komal"); cy.get_field("email").should("have.value", "komal@test.com"); cy.get_field("phone").should("have.value", "9432380001"); diff --git a/cypress/integration/dashboard_chart.js b/cypress/integration/dashboard_chart.js index 6023a50abe..d7075f788f 100644 --- a/cypress/integration/dashboard_chart.js +++ b/cypress/integration/dashboard_chart.js @@ -5,7 +5,7 @@ context("Dashboard Chart", () => { }); it("Check filter populate for child table doctype", () => { - cy.visit("/app/dashboard-chart/new-dashboard-chart-1"); + cy.visit("/app/dashboard-chart/new-dashboard-chart"); cy.get('[data-fieldname="parent_document_type"]').should("have.css", "display", "none"); cy.get_field("document_type", "Link"); diff --git a/cypress/integration/grid_keyboard_shortcut.js b/cypress/integration/grid_keyboard_shortcut.js index 414e822516..adc3541149 100644 --- a/cypress/integration/grid_keyboard_shortcut.js +++ b/cypress/integration/grid_keyboard_shortcut.js @@ -1,18 +1,25 @@ context("Grid Keyboard Shortcut", () => { let total_count = 0; + let contact_email_name = null; before(() => { cy.login(); }); beforeEach(() => { cy.reload(); - cy.visit("/app/contact/new-contact-1"); + cy.visit("/app/contact/new-contact"); cy.get('.frappe-control[data-fieldname="email_ids"]').find(".grid-add-row").click(); + // as new names uses hash instead of numbers get row's data-name dynamically. + cy.get('.frappe-control[data-fieldname="email_ids"]') + .find(".grid-body .grid-row") + .should(($row) => { + contact_email_name = $row.attr("data-name"); + }); }); it("Insert new row at the end", () => { cy.add_new_row_in_grid( "{ctrl}{shift}{downarrow}", (cy, total_count) => { - cy.get('[data-name="new-contact-email-1"]').should( + cy.get(`[data-name="${contact_email_name}"]`).should( "have.attr", "data-idx", `${total_count + 1}` @@ -23,17 +30,17 @@ context("Grid Keyboard Shortcut", () => { }); it("Insert new row at the top", () => { cy.add_new_row_in_grid("{ctrl}{shift}{uparrow}", (cy) => { - cy.get('[data-name="new-contact-email-1"]').should("have.attr", "data-idx", "2"); + cy.get(`[data-name="${contact_email_name}"]`).should("have.attr", "data-idx", "2"); }); }); it("Insert new row below", () => { cy.add_new_row_in_grid("{ctrl}{downarrow}", (cy) => { - cy.get('[data-name="new-contact-email-1"]').should("have.attr", "data-idx", "1"); + cy.get(`[data-name^="${contact_email_name}"]`).should("have.attr", "data-idx", "1"); }); }); it("Insert new row above", () => { cy.add_new_row_in_grid("{ctrl}{uparrow}", (cy) => { - cy.get('[data-name="new-contact-email-1"]').should("have.attr", "data-idx", "2"); + cy.get(`[data-name^="${contact_email_name}"]`).should("have.attr", "data-idx", "2"); }); }); }); diff --git a/cypress/integration/timeline.js b/cypress/integration/timeline.js index c6076088fb..b02a1d1734 100644 --- a/cypress/integration/timeline.js +++ b/cypress/integration/timeline.js @@ -8,7 +8,7 @@ context("Timeline", () => { it("Adding new ToDo, adding new comment, verifying comment addition & deletion and deleting ToDo", () => { //Adding new ToDo - cy.visit("/app/todo/new-todo-1"); + cy.visit("/app/todo/new-todo"); cy.get('[data-fieldname="description"] .ql-editor.ql-blank') .type("Test ToDo", { force: true }) .wait(200);