From 5c29d67113375be099c52c70fc3e956f6d60749c Mon Sep 17 00:00:00 2001 From: Aabid Sofi Date: Mon, 16 Dec 2024 00:01:07 +0530 Subject: [PATCH] fix crash on removing undefined elements Signed-off-by: Aabid Sofi --- cypress-action/cypress/e2e/e2e/loadDesign.js | 98 +++++++++++--------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/cypress-action/cypress/e2e/e2e/loadDesign.js b/cypress-action/cypress/e2e/e2e/loadDesign.js index 03556d1..0fcdf42 100644 --- a/cypress-action/cypress/e2e/e2e/loadDesign.js +++ b/cypress-action/cypress/e2e/e2e/loadDesign.js @@ -3,73 +3,85 @@ import { TIME, canvasContainer } from "../../support/constants"; import { - beforeEachCallbackForCustomUrl, - doSnapshotSetup, - waitFor, + beforeEachCallbackForCustomUrl, + doSnapshotSetup, + waitFor, } from "../../support/helpers"; const InfraShot = (theme) => { - return describe(`Infra Shot Automated Runner ${theme} Mode`, () => { - beforeEach(() => - beforeEachCallbackForCustomUrl( - `/extension/meshmap?mode=design&design=${getDesignId()}`, - theme - ) - ); + return describe(`Infra Shot Automated Runner ${theme} Mode`, () => { + beforeEach(() => + beforeEachCallbackForCustomUrl( + `/extension/meshmap?mode=design&design=${getDesignId()}`, + theme, + ), + ); - it(`take light mode infra shot`, () => { - const designId = getDesignId(); - waitForDesignRender(); - cy.window().then((window) => { - cy.wait(TIME.MEDIUM); - captureSnapshot({ - window, - designId: designId, - theme, - }); - }); + it(`take light mode infra shot`, () => { + const designId = getDesignId(); + waitForDesignRender(); + cy.window().then((window) => { + cy.wait(TIME.MEDIUM); + captureSnapshot({ + window, + designId: designId, + theme, }); + }); }); + }); }; const getDesignId = () => { - return Cypress.env("applicationId").replace(/['"]+/g, ""); + return Cypress.env("applicationId").replace(/['"]+/g, ""); }; const waitForDesignRender = () => { - waitFor(canvasContainer.query, { timeout: 60_000 }); - cy.wait(TIME.X4LARGE); + waitFor(canvasContainer.query, { timeout: 60_000 }); + cy.wait(TIME.X4LARGE); }; const snapshotPath = (designId, theme) => { - return `snapshot-${theme}`; + return `snapshot-${theme}`; }; const captureSnapshot = ({ window, designId, theme }) => { - console.log("Taking snapshot", designId, theme); - removeWidgets(); - cy.window().then((win) => { - const cytoscape = win.cyto; - cytoscape.fit(); - cytoscape.center(); - }) - const path = snapshotPath(designId, theme); - cy.wait(2000) - - cy.get(canvasContainer.query, { timeout: 10 * 1000 }).should("exist").screenshot(path, { - scale: true, + console.log("Taking snapshot", designId, theme); + removeWidgets(); + cy.window().then((win) => { + const cytoscape = win.cyto; + cytoscape.fit(); + cytoscape.center(); + }); + const path = snapshotPath(designId, theme); + cy.wait(2000); + + cy.get(canvasContainer.query, { timeout: 10 * 1000 }) + .should("exist") + .screenshot(path, { + scale: true, }); - console.log(`Snapshot taken at ${path}`); + console.log(`Snapshot taken at ${path}`); }; const removeWidgets = () => { - const ids = ["action-toolbar", "kanvas-bottom-dock", "design-drawer", "visualiser-drawer", "left-navigation-bar", "top-navigation-bar"]; + const ids = [ + "action-toolbar", + "kanvas-bottom-dock", + "design-drawer", + "left-navigation-bar", + "top-navigation-bar", + ]; - ids.forEach((className) => { - cy.get(`#${className}`).invoke('remove'); - }); + ids.forEach((className) => { + try { + cy.get(`#${className}`).invoke("remove"); + } catch (error) { + console.log(`Error removing ${className}`); + } + }); }; ["light", "dark"].forEach((theme) => { - InfraShot(theme); + InfraShot(theme); });