diff --git a/lib/_pageElement.js b/lib/_pageElement.js index 1263531..105ae82 100644 --- a/lib/_pageElement.js +++ b/lib/_pageElement.js @@ -122,12 +122,29 @@ async function getFileContent(path) { return fs.existsSync(path) ? await readFile(path, 'utf8') : null; } -exports.getPageElement = async (taiko, element) => { - const _element = await getHelper(taiko, element); - if (_element !== element) { - return await _element; +async function tableCellElement(taiko, element) { + if (element.startsWith("table")) { + const tableCellObject = JSON.parse(element.replace("table", "").trim()); + const tableElementValue = tableCellObject["tableElement"]; + const columnNameValue = tableCellObject["columnName"]; + const rowValue = tableCellObject["row"]; + const tableElement = await getElement(taiko, tableElementValue); + const tableElementLocatorValue = tableElement.description.replace("CustomSelector with query", "").trim(); + const columnHeaders = await taiko.$(tableElementLocatorValue + "//thead//th").elements(); + let columnIndex = 0; + for (let index in columnHeaders) { + const columnHeader = (await columnHeaders[index].text()).toString(); + if (columnHeader === columnNameValue) { + columnIndex = ++index; + break; + } + } + return await taiko.$("(" + tableElementLocatorValue + "//tbody//tr[" + rowValue + "])//td[" + columnIndex + "]"); } - + return element; +} + +async function getElement(taiko, element) { let elementText; if (element.includes("with text")) { const elementParts = element.split("with text"); @@ -153,13 +170,28 @@ exports.getPageElement = async (taiko, element) => { if (hasElement) { let elementLocatorValue = fileObject[element]; elementLocatorValue = elementText ? - elementLocatorValue.replace("{text}", elementText) : elementLocatorValue; + elementLocatorValue.replaceAll("{text}", elementText) : elementLocatorValue; + return await taiko.$(elementLocatorValue); } return await element; } +exports.getPageElement = async (taiko, element) => { + let _element = await getHelper(taiko, element); + if (_element !== element) { + return await _element; + } + + _element = await tableCellElement(taiko, element); + if (_element !== element) { + return await _element; + } + + return await getElement(taiko, element); +} + exports.checkElementState = async (taiko, element, elementState) => { const pageElement = await this.getPageElement(taiko, element); switch (elementState) { diff --git a/lib/page_steps.js b/lib/page_steps.js index 13c6627..20974de 100644 --- a/lib/page_steps.js +++ b/lib/page_steps.js @@ -4,6 +4,7 @@ const taiko = require("taiko"); const assert = require("assert"); const selectors = require("./_selectors"); const helpers = require("./_helpers"); +const path = require("path"); const { getPageElement, checkElementState, scrollToElementView } = require("./_pageElement"); step(["Goto ", "Open ", "Goto in new tab", "Open in new tab"], async url => { @@ -368,7 +369,7 @@ step(["Click ", "Click on ", "Clic }); step("Clear text box", async element => { - await taiko.clear(await getPageElement(taiko, element)) + await taiko.clear(await getPageElement(taiko, element)); }); step(["Enter to text box", "Enter to "], async (value, element) => { @@ -401,8 +402,7 @@ step("Verify text is ", async (element, elementText) => { elementText = helpers.getValue(elementText); gauge.message("Verifying " + element + " text contains " + elementText); - await taiko.waitFor(element + ' did not contain text ' + elementText, - async () => (await (await getPageElement(taiko, element)).text()).toString() + await taiko.waitFor(async () => (await (await getPageElement(taiko, element)).text()).toString() .replaceAll("\\s+", " ") .replaceAll("\n", " ") .includes(elementText)); @@ -419,6 +419,16 @@ step(["Save as ", "Save text as file to ", async (filePath, element) => { + const fileAbsolutePath = process.env.file_upload_directory && !path.isAbsolute(filePath) ? + path.join(process.env.file_upload_directory, filePath) : path.join(filePath); + await taiko.attach(fileAbsolutePath, await getPageElement(taiko, element)); +}); + +/* file actions steps 👆 */ + step(["Wait seconds", "Wait for seconds"], async seconds => { await taiko.waitFor(seconds * 1000); }); diff --git a/lib/page_steps_continue_on_failure.js b/lib/page_steps_continue_on_failure.js index 95d1584..26f9c50 100644 --- a/lib/page_steps_continue_on_failure.js +++ b/lib/page_steps_continue_on_failure.js @@ -17,13 +17,12 @@ step(["Verify ", "Verify text is ", -{continueOnFailure: true}, async (element, elementText) => { +step("Verify text is ", + {continueOnFailure: true}, async (element, elementText) => { elementText = helpers.getValue(elementText); gauge.message("Verifying " + element + " text contains " + elementText); - await taiko.waitFor(element + ' did not contain text ' + elementText, - async () => (await (await getPageElement(taiko, element)).text()).toString() + await taiko.waitFor(async () => (await (await getPageElement(taiko, element)).text()).toString() .replaceAll("\\s+", " ") .replaceAll("\n", " ") .includes(elementText)) diff --git a/package.json b/package.json index cf13ff6..010100e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@softrams/gauge-taiko-steps", - "version": "0.1.3", + "version": "0.1.4", "description": "Implementation of common test steps with Taiko driver for writing tests with Gauge framework", "main": "index.js", "scripts": {