playwright-fluent
Version:
Fluent API around playwright
23 lines (22 loc) • 964 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.invokeMethodOnHandle = void 0;
async function invokeMethodOnHandle(methodName, selector, selectorName) {
if (!selector) {
throw new Error(`Cannot invoke method '${methodName}' on '${selectorName}' because selector was not found in DOM`);
}
const hasBeenInvoked = await selector.evaluate((el, methodName) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (el && el[methodName] && typeof el[methodName] === 'function') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
el[methodName]();
return true;
}
return false;
}, methodName);
if (hasBeenInvoked) {
return;
}
throw new Error(`Cannot invoke method '${methodName}' on '${selectorName}' because this method does not exist.`);
}
exports.invokeMethodOnHandle = invokeMethodOnHandle;
;