import fetch from "node-fetch"; import { DewElement } from './element'; import { logger } from '../Logger/logger'; import { CommonKeyword } from './commonKeyword'; import { Wait } from "./dewWait"; /** * CNS Class */ export class CNS { /** * * This method is used to check if CNS is set on a specified prodcut. * * ```js * await CNS.checkIfActive("iSource"); * ``` * * @param {string} productName */ static async checkIfCNSActive(productName: string) { const companyObject = await CommonKeyword.executeScript(`return sessionStorage.COMPANY_OBJECT`); const jsonCompanyObject = await JSON.parse(companyObject); const tenantId = jsonCompanyObject.companyId; const homeURL = await CommonKeyword.executeScript(`return sessionStorage.ddHomeUrl`); const apiURl = homeURL + `/api/u/cns/notifications/downtime`; const raw = JSON.stringify({ "perPageRecords": 10, "pageNo": 1, "criteriaGroup": { "logicalOperator": `AND`, "criteria": [{ "fieldName": `COMPANIES`, "operation": `IN`, "multivalue": [`` + tenantId + ``] }, { "fieldName": `ACTIVE_DOWNTIME`, "operation": `EQUALS`, "value": `true` }] } }); const response: string = await fetch(apiURl, { method: `POST`, body: raw, redirect: `follow` }) .then(function(response: any) { return response.text(); }) .then(function(result: any) { return result; }) .catch(function(error: any) { console.log(`error`, error); }); if (response.includes(productName) || response.includes(`All Prodcuts`)) { return true; } else { return false; } } /** * Method is use to click on dismiss button of CNS notification */ static async dismissNotification() { const locator = `//dew-notification-tray//button[@aria-label='Dismiss']`; try { if (await DewElement.checkIfElementVisible(`//dew-notification-tray//button[@aria-label='Dismiss']`)) { await CommonKeyword.clickWrapper(`//dew-notification-tray//button[@aria-label='Dismiss']`); await Wait.waitForDefaultTimeout(1); if (await DewElement.checkIfElementVisible(`//div[contains(@class,'dropdown-item')]/p[contains(text(),'Dismiss All')]`)) { await CommonKeyword.clickWrapper(`//div[contains(@class,'dropdown-item')]/p[contains(text(),'Dismiss All')]`); } await CommonKeyword.clickWrapper(`//dew-notification-tray//button[@aria-label='Yes']`); } else { logger.info(`CNS Notification not present`); } } catch (err) { logger.info(`Issue while performing operation in DDCC: Unable to perform dismiss notification ` + locator); throw err; } } }