Here is the demo for Nightwatch to capture the network traffic.
Give me a 🌟, if it helps. Thank you! 🤩
# Install the chromedriver
# Note: the chromedirver version in package.json is 77.0.0. You may need to change it based on your environment
npm install
# Run the test
nightwatch captureXHRTraffic.js
-
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
This solution only could capture the XHR requests.
If traffic type is fetch, it won't working.
For example, all the requests in https://httpbin.org/ are fetch type, this solution is not working.