leadfoot/helpers/pollUntil

(require("leadfoot/helpers/pollUntil"))(poller: function|string, argsopt: Array.<any>, timeoutopt: number, pollIntervalopt: number): function

A leadfoot/Command helper that polls for a value within the client environment until the value exists or a timeout is reached.

Parameters

Name Type Attributes Description
poller function|string

The poller function to execute on an interval. The function should return null or undefined if there is not a result. If the poller function throws, polling will halt.

args Array.<any> optional

An array of arguments to pass to the poller function when it is invoked. Only values that can be serialised to JSON, plus leadfoot/Element objects, can be specified as arguments.

timeout number optional

The maximum amount of time to wait for a successful result, in milliseconds. If not specified, the current executeAsync maximum timeout for the session will be used.

pollInterval number optional

The amount of time to wait between calls to the poller function, in milliseconds. If not specified, defaults to 67ms.

Returns

  • A leadfoot/Command#then callback function that, when called, returns a promise that resolves to the value returned by the poller function on success and rejects on failure.

Examples

var Command = require('leadfoot/Command');
var pollUntil = require('leadfoot/helpers/pollUntil');

new Command(session)
    .get('http://example.com')
    .then(pollUntil('return document.getElementById("a");', 1000))
    .then(function (elementA) {
        // element was found
    }, function (error) {
        // element was not found
    });
var Command = require('leadfoot/Command');
var pollUntil = require('leadfoot/helpers/pollUntil');

new Command(session)
    .get('http://example.com')
    .then(pollUntil(function (value) {
        var element = document.getElementById('a');
        return element && element.value === value ? true : null;
    }, [ 'foo' ], 1000))
    .then(function () {
        // value was set to 'foo'
    }, function (error) {
        // value was never set
    });