最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - watch network with nightwatch - Stack Overflow

programmeradmin11浏览0评论

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
Add a ment  | 

4 Answers 4

Reset to default 4

Yes, 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

  1. 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()
    }
  1. Then take advantage of Nightwatch API .getLog

    The .getLog could capture the console warn logs for us

发布评论

评论列表(0)

  1. 暂无评论