import { CommonKeyword } from './commonKeyword'; import { Wait } from './dewWait'; /** * Table class */ export class Table { root: any; static root: any; /** * Constructor * @param {*} root */ constructor(root: any) { this.root = root; // locator } /** * sortBy function * @param {*} headerName * @param {*} typeSorting */ static async sortBy(headerName: string, typeSorting: string) { await within(this.root, async () => { await CommonKeyword.clickElement(`h1`); }); const sortTypes = [`desc`, `asc`]; const sortSelector = locate({ css: `.list-head .text-subhead-b.pointer` }).withText(headerName) .toString(); const sortPointer = `img.ml-2.pointer`; /** * To check attribute */ async function checkAttr() { const attribute = await CommonKeyword.executeScript(` const headerName = arguments[0] const listOfHeaders = document.querySelectorAll('.text-subhead-b.pointer') const currentHeader = Array.prototype.filter.call(listOfHeaders, function(header) { if (header.innerText.trim() === headerName) { return header } })[0] if (currentHeader.parentNode.querySelectorAll('img.ml-2.pointer').length) { return currentHeader.parentNode.querySelector('img.ml-2.pointer').getAttribute('src') } `, headerName); return attribute && attribute.includes(typeSorting); } if (!sortTypes.includes(typeSorting)) { throw new Error(`Please provide a valid argument value, the available arguments value are: "desc" or "asc"`); } await Wait.waitUntilVisibilityOfElement(`.hBlock`); // in future use this.root await Wait.waitUntilVisibilityOfElement(sortSelector); /* z.waitForVisible(`.hBlock`, 10); // in future use this.root z.waitForVisible(sortSelector, 5); */ while (!await checkAttr()) { await CommonKeyword.clickElement(sortSelector); await CommonKeyword.scrollIntoView(sortPointer); await Wait.waitUntilVisibilityOfElement(sortPointer); /* z.scrollIntoView(sortPointer); z.waitForVisible(sortPointer, 5); */ } } /** * getColumnData function * @param {*} headerName */ static async getColumnData(headerName: string) { const sortSelector = locate({ css: `.list-head .text-subhead-b.pointer` }).withText(headerName); const cellsBlock = `.scrollable .list-body`; await Wait.waitUntilVisibilityOfElement(`.hBlock`); await Wait.waitUntilVisibilityOfElement(sortSelector); await Wait.waitUntilVisibilityOfElement(cellsBlock); /* z.waitForVisible(`.hBlock`, 10); // in future use this.root z.waitForVisible(sortSelector, 5); z.waitForVisible(cellsBlock, 10); // re render cells content */ const listOfColumsText = await CommonKeyword.executeScript(` const headerName = arguments[0] const listOfHeaders = document.querySelectorAll('span.text-subhead-b') const currentHeader = Array.prototype.find.call(listOfHeaders, function(header) { if (header.innerText.trim() === headerName) { return header } }) const listOfCellsText = currentHeader.parentNode.parentNode.parentNode.querySelectorAll('.list-body') return Array.prototype.map.call(listOfCellsText, function(cell) { return cell.innerText.trim() }) `, headerName); return listOfColumsText; } } module.exports = new Table(`root`);