admin管理员组文章数量:1402848
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.
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.
Share Improve this question asked Mar 26, 2015 at 18:17 kokitokokito 1,2742 gold badges14 silver badges21 bronze badges 4- you could have the button do something nightwatch has a built-in event for, like an element being visible, even a clear element... – dandavis Commented Mar 26, 2015 at 19:23
- this would allow me to test if the button would have change something in the view but what if it doesn't change anything you see, but just get some info not displayed? furthermore, this doesn't allow me to test if there's no request send when the button is supposed to be disabled. – kokito Commented Mar 26, 2015 at 19:43
- 1 you can tie the network action to the detectable event, not just to the click() itself. – dandavis Commented Mar 26, 2015 at 20:27
- 1 how would you do that? – kokito Commented Mar 27, 2015 at 14:08
4 Answers
Reset to default 4Yes, you can use https://www.npmjs./package/nightwatch-xhr in order to watch for Ajax requests from Nightwatch.js.
(I'm one of the maintainers)
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.
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./forum/#!msg/nightwatchjs/NFBi0fnQNT8/Dp9t1-CDBQAJ
Here is the solution to capture the XHR traffic:
https://github./Bugazelle/nightwatch-capture-network-traffic
How it is working
Take advantage of the
ajaxListener.js
The js is forked from https://gist.github./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
本文标签: javascriptwatch network with nightwatchStack Overflow
版权声明:本文标题:javascript - watch network with nightwatch - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744373188a2603131.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论