Reputation: 1254
I'm using nightwatch to test the frontend of an application. I'm testing that some buttons are clickable or not.
Is it possible with nightwatch, to know if there was a network request made by the click, or more generally, to watch the network.
Upvotes: 7
Views: 3242
Reputation: 405
Here is the solution to capture the XHR traffic:
https://github.com/Bugazelle/nightwatch-capture-network-traffic
Take advantage of the ajaxListener.js
The js is forked from https://gist.github.com/icodejs/3183154
This hack will make all the XHR requests as a warn log to console
{
"type": "response",
"syncMode": this.syncMode,
"method": this.method,
"url": this.url,
"requestData": this.requestData,
"readyState": this.readyState,
"responseText": this.responseText,
"responseCode": this.status,
"responseHeader": this.getAllResponseHeaders()
}
Then take advantage of Nightwatch API .getLog
The .getLog could capture the console warn logs for us
Upvotes: 0
Reputation: 3168
Yes, you can use https://www.npmjs.com/package/nightwatch-xhr in order to watch for Ajax requests from Nightwatch.js.
(I'm one of the maintainers)
Upvotes: 4
Reputation: 31
You cannot with plain nightwatch. It can be done with browsermob which enables to record your browser request and saves in HAR format. You have to integrate browsermob-proxy. I have responded to another similar post. Check this.
https://groups.google.com/forum/#!msg/nightwatchjs/NFBi0fnQNT8/Dp9t1-CDBQAJ
Upvotes: 0
Reputation: 406
Is it possible with nightwatch, to know if there was a network request made by the click, or more generally, to watch the network.
No it is not.
Upvotes: 0