These are chat archives for rosshinkley/nightmare

7th
Oct 2016
eoxia-jimmy
@eoxia-jimmy
Oct 07 2016 08:56

Hi everybody.

How can i use .wait to wait a custom function in custom script ?

I wanna wait xhr response in the wait like this:
// Custom script
window.XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
        this.addEventListener("readystatechange", function() {
            if (this.readyState === 4) {
                var responseJSON = JSON.parse(this.responseText);
                if ( responseJSON && responseJSON.data && responseJSON.data.template ) {
                    delete responseJSON.data.template;
                }

                if ( responseJSON && responseJSON.data && responseJSON.data.template_left ) {
                    delete responseJSON.data.template_left;
                }

                if ( responseJSON && responseJSON.data && responseJSON.data.template_right ) {
                    delete responseJSON.data.template_right;
                }
                window.__responses[window.currentAction] = responseJSON;
            }
        }, false);
    open.apply(this, arguments);
};

// nightmare
.click('.wp-digi-develop-list .active .wp-digi-new-group-action a')
        .wait(window.__response['myCustomAction'])
        .evaluate(function() {
            return window.__responses[window.currentAction];
        })
Ross Hinkley
@rosshinkley
Oct 07 2016 14:09
@jimmy-eoxia .wait() can take a function, similar to how .evaluate() works
(under the covers, they're very similar)
docs for what it's worth
is that close to what you're after?