UNPKG

webdriverio

Version:

Next-gen browser and mobile automation test framework for Node.js

52 lines (40 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _Timer = _interopRequireDefault(require("../Timer")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class Interception { constructor(url, filterOptions = {}, browser) { this.url = url; this.filterOptions = filterOptions; this.browser = browser; this.respondOverwrites = []; this.matches = []; } waitForResponse({ timeout = this.browser.options.waitforTimeout, interval = this.browser.options.waitforInterval, timeoutMsg } = {}) { if (typeof timeout !== 'number') { timeout = this.browser.options.waitforTimeout; } if (typeof interval !== 'number') { interval = this.browser.options.waitforInterval; } const fn = () => this.calls.length > 0; const timer = new _Timer.default(interval, timeout, fn, true); return this.browser.call(() => timer.catch(e => { if (e.message === 'timeout') { if (typeof timeoutMsg === 'string') { throw new Error(timeoutMsg); } throw new Error(`waitForResponse timed out after ${timeout}ms`); } throw new Error(`waitForResponse failed with the following reason: ${e && e.message || e}`); })); } } exports.default = Interception;