@qavajs/steps-playwright
Version:
qavajs steps to interact with playwright
50 lines • 2.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@qavajs/core");
/**
* Execute client function on electron process 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 '$js(async ({ app }) => app.getAppPath())' function and save result as 'scroll'
*/
(0, core_1.When)('I execute {value} function/script on electron app', async function (fn) {
await this.playwright.driver.evaluate(await fn.value());
});
/**
* Execute client function on electron process 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 '$js(async ({ app }) => app.getAppPath())' function on electron app and save result as 'result'
*/
(0, core_1.When)('I execute {value} function/script on electron app and save result as {value}', async function (fn, memoryKey) {
memoryKey.set(await this.playwright.driver.evaluate(await fn.value()));
});
/**
* Click electron menu
* @param {string} menuPath - menu path
* @example I click 'File > Edit' electron menu
*/
(0, core_1.When)('I click {value} electron menu', async function (menu) {
await this.playwright.driver.evaluate(async ({ Menu }, { menuPath }) => {
const path = menuPath.split(/\s*>\s*/);
const menu = Menu.getApplicationMenu();
if (!menu)
throw new Error('Menu is not set');
const firstMenu = path.shift();
const findItemPredicate = (item) => (menu) => menu.label === item || menu.role === item;
let currentMenu = menu.items.find(findItemPredicate(firstMenu));
if (!currentMenu)
throw new Error(`Menu '${firstMenu}' is not found`);
for (const pathItem of path) {
if (!currentMenu?.submenu)
throw new Error(`Menu '${pathItem}' does not have submenu`);
currentMenu = currentMenu.submenu.items.find(findItemPredicate(pathItem));
if (!currentMenu)
throw new Error(`Menu '${pathItem}' is not found`);
}
currentMenu.click();
}, { menuPath: await menu.value() });
});
//# sourceMappingURL=electron.js.map
;