watch network with nightwatch
Asked Answered
F

4

7

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.

Froebel answered 26/3, 2015 at 18:17 Comment(4)
you could have the button do something nightwatch has a built-in event for, like an element becoming visible, even a clear element...Parrnell
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.Froebel
you can tie the network action to the detectable event, not just to the click() itself.Parrnell
how would you do that?Froebel
D
4

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)

Duma answered 21/11, 2018 at 10:21 Comment(0)
I
0

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.

Influenza answered 9/8, 2016 at 8:43 Comment(0)
K
0

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

Kalk answered 18/1, 2018 at 15:22 Comment(1)
While this link may assist in your answer to the question, you can improve this answer by taking vital parts of the link and putting it into your answer, this makes sure your answer is still an answer if the link gets changed or removed :)Hamster
A
0

Here is the solution to capture the XHR traffic:

https://github.com/Bugazelle/nightwatch-capture-network-traffic

How it is working

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

    The .getLog could capture the console warn logs for us

Applejack answered 30/5, 2020 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.