playwright-fluent
Version:
Fluent API around playwright
42 lines (41 loc) • 1.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkHandle = exports.defaultCheckOptions = void 0;
const hover_on_handle_1 = require("../hover-on-handle");
const utils_1 = require("../../../utils");
const is_handle_enabled_1 = require("../is-handle-enabled");
const is_handle_checked_1 = require("../is-handle-checked");
exports.defaultCheckOptions = {
stabilityInMilliseconds: 300,
timeoutInMilliseconds: 30000,
verbose: false,
};
async function checkHandle(selector, name, page, options) {
if (!page) {
throw new Error(`Cannot check '${name}' because no browser has been launched`);
}
if (!selector) {
throw new Error(`Cannot check '${name}' because selector was not found in DOM`);
}
const hoverOptions = {
...hover_on_handle_1.defaultHoverOptions,
verbose: options.verbose,
stabilityInMilliseconds: options.stabilityInMilliseconds,
timeoutInMilliseconds: options.timeoutInMilliseconds,
};
await (0, hover_on_handle_1.hoverOnHandle)(selector, name, page, hoverOptions);
(0, utils_1.report)('Checking if selector is already checked ...', options.verbose);
const isChecked = await (0, is_handle_checked_1.isHandleChecked)(selector, { verbose: options.verbose });
if (isChecked) {
(0, utils_1.report)('Selector is already checked: nothing to do.', options.verbose);
return;
}
(0, utils_1.report)('waiting for the selector to be enabled ...', options.verbose);
await (0, utils_1.waitUntil)(() => (0, is_handle_enabled_1.isHandleEnabled)(selector, { verbose: false }), `Cannot check '${name}' because this selector is disabled`, {
...options,
throwOnTimeout: true,
wrapPredicateExecutionInsideTryCatch: true,
});
await selector.check();
}
exports.checkHandle = checkHandle;
;