UNPKG

@theintern/leadfoot

Version:

Leadfoot. A JavaScript client library that brings cross-platform consistency to the Selenium WebDriver API.

71 lines 2.78 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("@theintern/common"); var statusCodes_1 = __importDefault(require("./statusCodes")); /** * Waits for all elements findable in the currently active window/frame * using the given strategy and value to be destroyed. * * @param session The session to consider. * * @param locator The particular instance that will perform the locating. * * @param using The element retrieval strategy to use. See * [[Command.Command.find]] for options. * * @param value The strategy-specific value to search for. See * [[Command.Command.find]] for details. * * @returns a Task that resolves when no matching elements can be found, or * rejects if matching elements still exist after the find timeout. */ function waitForDeleted(session, locator, using, value) { var originalTimeout; return session .getTimeout('implicit') .then(function (value) { originalTimeout = value; session.setTimeout('implicit', 0); }) .then(function () { return new common_1.Task(function (resolve, reject) { var startTime = Date.now(); (function poll() { if (Date.now() - startTime > originalTimeout) { var always = function () { var error = new Error(); error.status = 21; var _a = statusCodes_1.default[error.status], name = _a[0], message = _a[1]; error.name = name; error.message = message; reject(error); }; session .setTimeout('implicit', originalTimeout) .then(always, always); return; } locator.find(using, value).then(poll, function (error) { var always = function () { /* istanbul ignore else: other errors should never occur during normal operation */ if (error.name === 'NoSuchElement') { resolve(); } else { reject(error); } }; session .setTimeout('implicit', originalTimeout) .then(always, always); }); })(); }); }) .then(function () { }); } exports.default = waitForDeleted; //# sourceMappingURL=waitForDeleted.js.map