Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Question regarding waitForXHR #28

Open
palmer-cl opened this issue May 23, 2019 · 1 comment
Open

Question regarding waitForXHR #28

palmer-cl opened this issue May 23, 2019 · 1 comment

Comments

@palmer-cl
Copy link

Hey everyone,

Im using this package in a pattern like you have in the docs:

module.exports = {
    'Catch all XHRs, trigger click': function (browser) {
        browser
            .url('some/path')
            .someStuff()
            .moreStuff()
            .waitForXHR('', 1000, function browserTrigger() {
                browser.click('.tracking-link-1');
            }, function assertValues(xhrs) {
                browser.assert.equal(xhrs[0].status, "success");
                browser.assert.equal(xhrs[0].method, "POST");
                browser.assert.equal(xhrs[0].requestData, "200");
                browser.assert.equal(xhrs[0].httpResponseCode, "200");
                browser.assert.equal(xhrs[0].responseData, "");
            });
    }
}

Im wondering why waitForXHR blocks tests from continuing after the XHR assertion. Is there a different pattern I should be using to keep tests running after asserting the correct XHR status code? Currently, If I call .waitForXHR() the rest of my test will not run. I would like to do something like this:

module.exports = {
    'Catch all XHRs, trigger click': function (browser) {
        browser
            .url('some/path')
            .someStuff()
            .moreStuff()
            .waitForXHR('', 1000, function browserTrigger() {
                browser.click('.tracking-link-1');
            }, function assertValues(xhrs) {
                browser.assert.equal(xhrs[0].status, "success");
                browser.assert.equal(xhrs[0].method, "POST");
                browser.assert.equal(xhrs[0].requestData, "200");
                browser.assert.equal(xhrs[0].httpResponseCode, "200");
                browser.assert.equal(xhrs[0].responseData, "");
            });
           .moreStuff()
           .moreStuff()
    }
}

Thanks!

@Pieras2
Copy link

Pieras2 commented Oct 28, 2019

Hi, maybe I might be wrong but I found "assert" to be blocking tests.
It is to be used in case we know that something is so completely wrong that further tests are no more relevant at this point. Nightwatch has method "verify" which does you wish it did.

Please see description from NW api

The built-in extendable assert/verify library is available on the Nightwatch instance as two namespaces containing the same methods which perform assertions on elements:
.assert - when an assertion fails, the test ends, skipping all other assertions.
.verify - when an assertion fails, the test logs the failure and continues with other assertions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants