Monitoring requests and responses with nightwatch.js
Asked Answered
O

1

7

I am using Nightwatch and was hoping to monitor the http requests that are being generated by my nightwatch steps. Is there a way to listen to the requests that are sent and the responses received. I dont need to modify them.

Thanks Matt

Oppen answered 30/5, 2016 at 23:0 Comment(5)
did you get anywhere with this?Buccal
Might be a duplicate #29286460Higdon
@swiss196 no I didn't get anywhere with this. The feedback I got was it is not possibleOppen
Hey, @matt it's been a year and 7 months, has there been any work done on this? e2e automation testing for error pages is what I'm after, so it would be cool to alter a request after a click/submit action to get back the correct error page. :)Shipper
no change as far as I know sorryOppen
H
0

Yes there is a way.

In order to monitor the HTTP requests: It's basically will monitor when user click on event that send a request to the server such as: submit button in login page - that send userName & password.

First install npm i nightwatch-xhr

after that you can make a function like that:

module.exports = {
  tags: ["test"],
  "test": function (browser) {
      browser
      .windowMaximize()
      .url("some url")
      .insertValue("namevalue")
      .insertValue("passwordValue")

      //then write something like that
      .waitForXHR(
      "",
      1000,
      function browserTrigger() {
        browser.click("submit button")
      },
      function assertValues(xhr) {
        console.log(xhr)
      }
    );
   }
  }

It will catch the request data that send to the server.

Heptameter answered 29/8, 2020 at 20:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.