import 'codeceptjs'; import { lmt } from '../Helpers/readI18NProp'; import { logger } from '../Logger/logger'; import { CommonKeyword } from "./commonKeyword"; import { Wait } from './dewWait'; import { DewElement } from './element'; // import { DewFileUpload } from './dewFileUpload'; import { Tab } from './tab'; import { TextField } from './textfield'; import { z } from './z'; declare const inject: any; const { I } = inject(); const assert = require(`assert`); /** * Flexihelp class */ export class FlexiHelp extends Helper { /** * View Help Icon in a page by label * * Flexihelp.viewHelpIconByLabel("name") * * @param {String} label */ static async viewHelpIconByLabel(label: string) { if (label == `One View`) { await Wait.waitUntilVisibilityOfElement(`//h1[text()[normalize-space()='${label}']]//..//..//preceding-sibling::dew-self-help-tool//div[@class='sht-tooltip']`, 30); await DewElement.verifyIfISeeElement(`//h1[text()[normalize-space()='${label}']]//..//..//preceding-sibling::dew-self-help-tool//div[@class='sht-tooltip']`); } else { await Wait.waitUntilVisibilityOfElement(`//*[div[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip'] | //*[text()[normalize-space()='${label}']]//div[contains(@class,'sht-tooltip')] | //*[h1[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip']`, 30); await DewElement.verifyIfISeeElement(`//*[div[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip'] | //*[text()[normalize-space()='${label}']]//div[contains(@class,'sht-tooltip')] | //*[h1[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip']`); } } /** * Get attached file name by label * * `` * Flexihelp.getAttachedFileNameByLabel("Name") * * @param {String} label */ static async getAttachedFileNameByLabel(label: string) { await this.clickOnHelpIcon(label); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await CommonKeyword.clickElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'modal-dialog modal-dialog-centered modal-md')]/div`); await CommonKeyword.scrollTo(`//dew-row[contains(@class,'padding-btm row')]//label[contains(text(),'${await lmt.getLabel(`HelpVideos`)}')]`); try { const filename = await DewElement.grabTextFrom(`(//dew-card[contains(@class,'card-width card')]/div[contains(@class,'document')]/*[contains(@class,'text')])[1]`); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'centered modal-md')]//div[@class='modal-content']/button[contains(@class,'close close')]`); await CommonKeyword.clickElement(`//div[contains(@class,'centered modal-md')]//div[@class='modal-content']/button[contains(@class,'close close')]`); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); return filename; } catch (error) { console.log(error); throw error; } } /** * Get attached video name by label * * `` * Flexihelp.getAttachedVideoNameByLabel("Name") * * @param {String} label */ static async getAttachedVideoNameByLabel(label: string) { await this.clickOnHelpIcon(label); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await CommonKeyword.clickElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'modal-dialog modal-dialog-centered modal-md')]/div`); await CommonKeyword.scrollTo(`//dew-row[contains(@class,'padding-btm row')]//label[contains(text(),'${await lmt.getLabel(`HelpVideos`)}')]`); try { const filename = await DewElement.grabTextFrom(`(//dew-card[contains(@class,'card-width card')]/div[contains(@class,'video-tag')]/*[contains(@class,'text')])[1]`); await CommonKeyword.clickElement(`//div[contains(@class,'centered modal-md')]//div[@class='modal-content']/button[contains(@class,'close close')]`); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); return filename; } catch (error) { console.log(error); throw error; } } /** * Fill mandatory fields for an attachment * * `` * * Flexihelp.FillMandatoryFields(`Title_123`) * * * @param {String} title */ static async fillMandatoryFields(title: string) { let value = null; try { value = title; await CommonKeyword.clickElement(`//input[@placeholder='${await lmt.getLabel(`Title`)}']`); await TextField.enterTextUsingLocator(`//input[@placeholder='${await lmt.getLabel(`Title`)}']`, value); const frame = await DewElement.grabAttributeFrom(`//iframe`, `title`); console.log(frame); const editframe = frame.slice(-1); console.log(editframe); try { await z.switchTo(`//iframe[@title='${editframe}']`); await CommonKeyword.scrollTo(`//body`); await CommonKeyword.clickElement(`//body`); await TextField.enterTextUsingLocator(`//body`, `Test Automationdfill`); await z.switchTo(); } catch (error) { console.log(error); } await this.clickOnSHTFooterButton(await lmt.getLabel(`Upload`)); return value; } catch (error) { console.log(error); return value; } } /** * Attach video by specifying path and label * * `` * * Flexihelp.CreateorEditUsingVideo(`name`, `Title_123`, `resources\video.mp4`) * * @param {String} label * @param {String} title video link * @param {String} video */ static async createorEditUsingVideoByLabel(label: string, title: string, video: string) { let value = null; try { await this.clickOnHelpIcon(label); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'self-help-tooltip')]`, 30); await CommonKeyword.clickElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await DewElement.verifyIfISeeElement(`//div[contains(@class,'modal-dialog modal-dialog-centered modal-md')]/div`); await CommonKeyword.clickElement(`//div[contains(text(),'${await lmt.getLabel(`Add_Video`)}')]`); await z.attachFile(`//div[contains(@class,'input-group w-100 align-items-center d-inline-flex')]/input[1]`, video); await Wait.waitForDefaultTimeout(10); value = await this.fillMandatoryFields(title); const frame = await DewElement.grabAttributeFrom(`//iframe`, `title`); console.log(frame); const editframeN = frame.slice(-1); console.log(editframeN); try { await z.switchTo(`//iframe[@title='${editframeN}']`); await CommonKeyword.scrollTo(`//body`); await CommonKeyword.clickElement(`//body`); await TextField.enterTextUsingLocator(`//body`, `Test Automationdfill`); await z.switchTo(); } catch (error) { console.log(error); } await CommonKeyword.scrollTo(`//button[text()='${await lmt.getLabel(`Save`)}']`); await CommonKeyword.clickElement(`//button[text()='${await lmt.getLabel(`Save`)}']`); try { if (await DewElement.grabNumberOfVisibleElements(`//*[text()[normalize-space()='${await lmt.getLabel(`Confirm`)}']]`) > 0) { await CommonKeyword.clickElement(`//div[contains(@class,'confirmModal')]//dew-btn/button[div/span[text()[normalize-space()='${await lmt.getLabel(`Yes`)}']] and not(@disabled)]`); } } catch (err) { } await DewElement.verifyIfISeeElement(`//*[contains(text(),'${await lmt.getLabel(`Successful`)}')]`); await CommonKeyword.clickElement(`//button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`Ok`)}'] | //button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`OK`)}'] | //button[contains(@class,'btn primary')][@aria-label='OK']`); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); return value; } catch (error) { console.log(error); return value; } } /** * Removes attachment by label * * `` * * Flexihelp.removeAttachmentByLabel(`name`,`Test`) * * @param {String} label * @param {String} link */ static async removeAttachmentByLabel(label: string, link: string) { await this.clickOnHelpIcon(label); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'self-help-tooltip')]`, 30); await CommonKeyword.clickElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await CommonKeyword.clickElement(`//*[@title='${link}']//ancestor::dew-card/span`); await CommonKeyword.clickElement(`//div[contains(@class,'fixed-footer pb-2 ')]/button[2] | //button[contains(@class,'btn btn primary')]//span[text()='${await lmt.getLabel(`Proceed`)}']`); // await DewButton.click(`Proceed`) await CommonKeyword.scrollTo(`//button[@class='btn btn-success mr-2']`); await CommonKeyword.clickElement(`//button[@class='btn btn-success mr-2']`); try { if (await DewElement.grabNumberOfVisibleElements(`//*[text()[normalize-space()='${await lmt.getLabel(`Confirm`)}']]`) > 0) { await CommonKeyword.clickElement(`//div[contains(@class,'confirmModal')]//dew-btn/button[div/span[text()[normalize-space()='${await lmt.getLabel(`Yes`)}']] and not(@disabled)]`); } } catch (err) { } await CommonKeyword.clickElement(`//button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`Ok`)}'] | //button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`OK`)}'] | //button[contains(@class,'btn primary')][@aria-label='OK']`); await Wait.waitUntilVisibilityOfElement(`//button[contains(@class,'close close-sm float-right')]`); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); } /** * Create or edit using file by label * * `` * * Flexihelp.CreateorEditUsingfileByLabel("name","Sprint.xlsx","Test") * * @param {String} label * @param {String} link * @param {String} title */ static async createorEditUsingfileByLabel(label: string, link: string, title: string) { let editframe; try { await this.clickOnHelpIcon(label); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'self-help-tooltip')]`, 30); await CommonKeyword.clickElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await DewElement.verifyIfISeeElement(`//div[contains(@class,'modal-dialog modal-dialog-centered modal-md')]/div`); await Wait.waitUntilVisibilityOfElement(`//div[contains(text(),'${await lmt.getLabel(`Add_Help_Documents`)}')]`, 30); await CommonKeyword.clickElement(`//div[contains(text(),'${await lmt.getLabel(`Add_Help_Documents`)}')]`); await z.attachFile(`//div[contains(@class,'input-group w-100 align-items-center d-inline-flex')]/input[1]`, link); await Wait.waitForDefaultTimeout(10); await this.fillMandatoryFields(title); const frame = await DewElement.grabAttributeFrom(`//iframe`, `title`); console.log(frame); editframe = frame.slice(-1); console.log(editframe); console.log(`//iframe[@title='${editframe}']`); await z.switchTo(`//iframe[@title='${editframe}']`); await CommonKeyword.scrollTo(`//body`); await TextField.enterTextUsingLocator(`//body`, `Test Automationdfill`); await z.switchTo(); await Wait.waitUntilVisibilityOfElement(`//button[text()='${await lmt.getLabel(`Save`)}']`, 30); await CommonKeyword.clickElement(`//button[text()='${await lmt.getLabel(`Save`)}']`); try { if (await DewElement.grabNumberOfVisibleElements(`//*[text()[normalize-space()='${await lmt.getLabel(`Confirm`)}']]`) > 0) { await CommonKeyword.clickElement(`//div[contains(@class,'confirmModal')]//dew-btn/button[div/span[text()[normalize-space()='${await lmt.getLabel(`Yes`)}']] and not(@disabled)]`); } } catch (err) { } await DewElement.verifyIfISeeElement(`//*[contains(text(),'${await lmt.getLabel(`Successful`)}')]`); await CommonKeyword.clickElement(`//button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`Ok`)}'] | //button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`OK`)}'] | //button[contains(@class,'btn primary')][@aria-label='OK']`); await Wait.waitUntilVisibilityOfElement(`//button[contains(@class,'close close-sm float-right')]`, 30); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); } catch (error) { console.log(error); } } /** * Remove attachment file by label * * `` * * Flexihelp.removeAttachmentFileByLabel("Name","Test.xlsx") * * * @param {String} label * @param {String} link */ static async removeAttachmentFileByLabel(label: string, link: string) { await this.clickOnHelpIcon(label); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'self-help-tooltip')]`, 30); await CommonKeyword.clickElement(`//div[contains(@class,'edit-text py-3 pr-4')]/span`); await CommonKeyword.clickElement(`//span[@title='${link}']//ancestor::dew-card/span`); await CommonKeyword.clickElement(`//div[contains(@class,'fixed-footer pb-2 ')]/button[2] | //button[contains(@class,'btn btn primary')]//span[text()='${await lmt.getLabel(`Proceed`)}']`); await CommonKeyword.scrollTo(`//button[@class='btn btn-success mr-2']`); await CommonKeyword.clickElement(`//button[@class='btn btn-success mr-2']`); try { if (await DewElement.grabNumberOfVisibleElements(`//*[text()[normalize-space()='${await lmt.getLabel(`Confirm`)}']]`) > 0) { await CommonKeyword.clickElement(`//div[contains(@class,'confirmModal')]//dew-btn/button[div/span[text()[normalize-space()='${await lmt.getLabel(`Yes`)}']] and not(@disabled)]`); } } catch (err) { } await CommonKeyword.clickElement(`//button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`Ok`)}'] | //button[contains(@class,'btn btn-success mr-2')and text()='${await lmt.getLabel(`OK`)}'] | //button[contains(@class,'btn primary')][@aria-label='OK']`); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); } /** * Click on help icon * * `` * * Flexihelp.clickOnHelpIcon("Name") * * @param {String} label name */ static async clickOnHelpIcon(label: string) { if (label == `One View`) { await Wait.waitUntilVisibilityOfElement(`//h1[text()[normalize-space()='${label}']]//..//..//preceding-sibling::dew-self-help-tool//div[@class='sht-tooltip']`, 30); await CommonKeyword.moveCursorTo(`//h1[text()[normalize-space()='${label}']]//..//..//preceding-sibling::dew-self-help-tool//div[@class='sht-tooltip']`); await CommonKeyword.clickElement(`//h1[text()[normalize-space()='${label}']]//..//..//preceding-sibling::dew-self-help-tool//div[@class='sht-tooltip']`); } else { await Wait.waitUntilVisibilityOfElement(`//*[div[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip'] | //*[text()[normalize-space()='${label}']]//div[contains(@class,'sht-tooltip')] | //*[h1[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip']`); await CommonKeyword.moveCursorTo(`//*[div[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip'] | //*[text()[normalize-space()='${label}']]//div[contains(@class,'sht-tooltip')] | //*[h1[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip']`); await CommonKeyword.clickElement(`//*[div[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip'] | //*[text()[normalize-space()='${label}']]//div[contains(@class,'sht-tooltip')] | //*[h1[text()[normalize-space()='${label}']]]//div[@tooltipclass='sht-tooltip']`); } } /** * This method is used to click on SHT footer button. * ```js * await FlexiHelp.clickOnSHTFooterButton("Save") * @param {string}label */ static async clickOnSHTFooterButton(label: string) { try { await Wait.waitUntilVisibilityOfElement(`.//dew-sht-modal-footer//dew-btn/button[div/span[text()='${label}']]`, 30); await Wait.waitForElementClickable(`.//dew-sht-modal-footer//dew-btn/button[div/span[text()='${label}']]`); await CommonKeyword.clickElement(`.//dew-sht-modal-footer//dew-btn/button[div/span[text()='${label}']]`); } catch (err) { throw err; } } /** * this method is used the view flexihelp video * ```js * await FlexiHelp.viewHelpVideo("My Requests","Performing Actions on My Request_Requestor") * ``` * @param {string}label * @param {string}videoName * @param {string}tabName * */ static async viewHelpVideo(label: string, videoName: string, tabName?: string) { try { await this.clickOnHelpIcon(label); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'self-help-tooltip')]`, 30); if (tabName !== undefined) { await CommonKeyword.clickElement(`//span[contains(@class,'self-help-tabs')][text()[normalize-space()='${tabName}']]`); } await DewElement.verifyIfISeeElement(`//p[text()[normalize-space()='${videoName}']]/parent::div//span[contains(@class,'icon-video')] | //p[text()[normalize-space()='${videoName}']]/parent::div/div/img`); await CommonKeyword.clickElement(`//p[text()[normalize-space()='${videoName}']]/parent::div//span[contains(@class,'icon-video')] | //p[text()[normalize-space()='${videoName}']]/parent::div/div/img`); // Verification await DewElement.verifyIfISeeElement(`//vg-player[@vg-responsive='true']`); await Wait.waitForDefaultTimeout(10); await Wait.waitUntilVisibilityOfElement(`//div[contains(@class,'vg-overlay-play')]`); await CommonKeyword.click(`//div[contains(@class,'vg-overlay-play')]`); await Wait.waitForDefaultTimeout(2); const videoCurrentDuration = await DewElement.grabTextFrom(`//vg-player[@vg-responsive='true']//vg-time-display[@vgproperty ='current']`); const videoRemainDuration = await DewElement.grabTextFrom(`//vg-player[@vg-responsive='true']//vg-time-display[@vgproperty ='left']`); const videoTotalDuration = await DewElement.grabTextFrom(`//vg-player[@vg-responsive='true']//vg-time-display[@vgproperty ='total']`); logger.info(`Video Total duration: ` + videoTotalDuration); logger.info(`Video Played duration: ` + videoCurrentDuration); logger.info(`Video Remaining duration: ` + videoRemainDuration); if (videoCurrentDuration == `00:00`) { assert.fail(`Video is corrupted`); } await CommonKeyword.clickElement(`//section//span[contains(@class,'close')]`); } catch (err) { throw Error(`Unable to view video/Video is corrupted`); } } /** * this method is used the view flexihelp video * ```js * await FlexiHelp.viewHelpText("My Requests","Automationtest","Zycus") * ``` * @param {string}label * @param {string}helpText * @param {string}tabName * */ static async viewHelpText(label: string, helpText: string, tabName?: string) { try { await this.clickOnHelpIcon(label); if (tabName !== undefined) { await CommonKeyword.clickElement(`//span[contains(@class,'self-help-tabs')][text()[normalize-space()='${tabName}']]`); } await DewElement.verifyIfISeeText(helpText); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); } catch (err) { throw Error(`Unable to view help text`); } } /** * To download help content * * ```js * await FlexiHelp.downloadHelpContent("My Requests","Title123","Sprint") * ``` * @param {string}label * @param {string}documentTitle * @param {string}fileName * */ static async downloadHelpContent(label: string, documentTitle: string, fileName: string) { try { await this.clickOnHelpIcon(label); const locator = `//p[text()[normalize-space()='${documentTitle}']]/parent::div/div//img`; await CommonKeyword.clickElement(locator); await checkIfFileExist(fileName); await CommonKeyword.clickElement(`//button[contains(@class,'close close-sm float-right')]`); } catch (err) { throw Error(`Unable to view download help content`); } } /** * This method is used to perform dragndrop operation on flexi popup * * ```js * await FlexiHelp.dragAndDropFlexi(`What would you like to do today?`, `//input[@type='MST_Search']`); * ``` * * @param {string}label * @param {string }destinationContainer */ static async dragAndDropFlexi(label: string, destinationContainer: string) { await this.clickOnHelpIcon(label); const srcElement = `//div[contains(@class,'drag-handle')]/img`; const browserName = await z.executeScript(`return navigator.userAgent`); try { if (await browserName.includes(`Chrome`) || browserName.includes(`Edge`)) { await z.executeScript(` var elFrom = document.evaluate("${srcElement}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue var elTo = document.evaluate("${destinationContainer}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue var rectFrom = elFrom.getBoundingClientRect() var rectTo = elTo.getBoundingClientRect() var mouseEvents = document.createEvent("MouseEvents") mouseEvents.initMouseEvent('mousemove', true, false, window, 1, rectFrom.right, rectFrom.top, rectFrom.right, rectFrom.top, false, false, false, false, 0, null) elFrom.dispatchEvent(mouseEvents) mouseEvents.initMouseEvent('mousedown', true, false, window, 1, rectFrom.right, rectFrom.top, rectFrom.right, rectFrom.top, false, false, false, false, 0, null) elFrom.dispatchEvent(mouseEvents) mouseEvents.initMouseEvent('mousemove', true, false, window, 1, rectTo.right, rectTo.top, rectTo.right, rectTo.top, false, false, false, false, 0, null) elFrom.dispatchEvent(mouseEvents) mouseEvents.initMouseEvent('mouseup', true, false, window, 1, rectTo.right, rectTo.top, rectTo.right, rectTo.top, false, false, false, false, 0, null) elFrom.dispatchEvent(mouseEvents) `, srcElement, destinationContainer); } else { await CommonKeyword.scrollIntoView(srcElement); await z.dragAndDrop(srcElement, destinationContainer); } } catch (error) { console.log(`Issue Occured while drag and drop`); throw error; } } } module.exports = new FlexiHelp(); module.exports.FlexiHelp = FlexiHelp; /** * This method is used to check if downloaded file is present in system or not * @param {string}fileName */ async function checkIfFileExist(fileName: string) { const browserName = await z.executeScript(`return navigator.userAgent`); console.log(browserName); if (browserName == `Chrome`) { Tab.openNewTab(); await z.amOnPage(`chrome://downloads/`); z.fillField({ shadow: [`downloads-manager`, `downloads-toolbar`, `cr-toolbar`, `cr-toolbar-search-field`, `#searchInput`] }, fileName); await DewElement.verifyIfISeeText(fileName); Tab.closeCurrentTab(); } if (browserName.includes(`Edg`)) { Tab.openNewTab(); await z.amOnPage(`edge://downloads/`); await TextField.enterTextUsingLocator(`//input[@id='search_input']`, fileName); await DewElement.verifyIfISeeText(fileName); Tab.closeCurrentTab(); } }