@qavajs/steps-playwright
Version:
qavajs steps to interact with playwright
51 lines • 2.36 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@qavajs/core");
/**
* Execute client function
* @param {string} functionKey - memory key of function
* @example I execute '$fn' function // fn is function reference
* @example I execute 'window.scrollBy(0, 100)' function
*/
(0, core_1.When)('I execute {value} function/script', async function (fn) {
await this.playwright.page.evaluate(await fn.value());
});
/**
* Execute client function and save result into memory
* @param {string} functionKey - memory key of function
* @param {string} memoryKey - memory key to store result
* @example I execute '$fn' function and save result as 'result' // fn is function reference
* @example I execute 'window.scrollY' function and save result as 'scroll'
*/
(0, core_1.When)('I execute {value} function/script and save result as {value}', async function (fn, memoryKey) {
memoryKey.set(await this.playwright.page.evaluate(await fn.value()));
});
/**
* Execute client function on certain element
* @param {string} functionKey - memory key of function
* @param {string} alias - alias of target element
* @example I execute '$fn' function on 'Component > Element' // fn is function reference
* @example I execute 'arguments[0].scrollIntoView()' function on 'Component > Element'
*/
(0, core_1.When)('I execute {value} function/script on {playwrightLocator}', async function (fnKey, locator) {
let fn = await fnKey.value();
if (typeof fn === 'string') {
fn = new Function('return ' + fn);
}
await locator.evaluate(fn);
});
/**
* Execute client function on certain element
* @param {string} functionKey - memory key of function
* @param {string} alias - alias of target element
* @example I execute '$fn' function on 'Component > Element' and save result as 'innerText' // fn is function reference
* @example I execute 'arguments[0].innerText' function on 'Component > Element' and save result as 'innerText'
*/
(0, core_1.When)('I execute {value} function/script on {playwrightLocator} and save result as {value}', async function (fnKey, locator, memoryKey) {
let fn = await fnKey.value();
if (typeof fn === 'string') {
fn = new Function('return ' + fn);
}
memoryKey.set(await locator.evaluate(fn));
});
//# sourceMappingURL=execute.js.map
;