webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
42 lines (33 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _Timer = _interopRequireDefault(require("../../utils/Timer"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _default(condition, {
timeout = this.options.waitforTimeout,
interval = this.options.waitforInterval,
timeoutMsg
} = {}) {
if (typeof condition !== 'function') {
throw new Error('Condition is not a function');
}
if (typeof timeout !== 'number') {
timeout = this.options.waitforTimeout;
}
if (typeof interval !== 'number') {
interval = this.options.waitforInterval;
}
const fn = condition.bind(this);
let timer = new _Timer.default(interval, timeout, fn, true);
return timer.catch(e => {
if (e.message === 'timeout') {
if (typeof timeoutMsg === 'string') {
throw new Error(timeoutMsg);
}
throw new Error(`waitUntil condition timed out after ${timeout}ms`);
}
throw new Error(`waitUntil condition failed with the following reason: ${e && e.message || e}`);
});
}