From cded3fead6c378a59b21104e7b2213a28b3ff46f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 6 Jun 2024 05:13:48 +0530 Subject: [PATCH] feat: check if given selectors are visible on page at same time --- server/src/workflow-management/selector.ts | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/server/src/workflow-management/selector.ts b/server/src/workflow-management/selector.ts index 79bbbc07..afc990ea 100644 --- a/server/src/workflow-management/selector.ts +++ b/server/src/workflow-management/selector.ts @@ -705,6 +705,43 @@ export const selectorAlreadyInWorkflow = (selector: string, workflow: Workflow) }); }; +/** + * Checks whether the given selectors are visible on the page at the same time. + * @param selectors The selectors to check. + * @param page The page to use for the validation. + * @category WorkflowManagement + */ +export const isRuleOvershadowing = async(selectors: string[], page:Page): Promise => { + for (const selector of selectors){ + const areElsVisible = await page.$$eval(selector, + (elems) => { + const isVisible = ( elem: HTMLElement | SVGElement ) => { + if (elem instanceof HTMLElement) { + return !!(elem.offsetWidth + || elem.offsetHeight + || elem.getClientRects().length + && window.getComputedStyle(elem).visibility !== "hidden"); + } else { + return !!(elem.getClientRects().length + && window.getComputedStyle(elem).visibility !== "hidden"); + } + }; + + const visibility: boolean[] = []; + elems.forEach((el) => visibility.push(isVisible(el))) + return visibility; + }) + if (areElsVisible.length === 0) { + return false + } + + if (areElsVisible.includes(false)){ + return false; + } + } + return true; +} +