Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check http status code using nightwatch

how do I check the HTTP status code using nightwatch.js? I tried

  browser.url(function (response) {
     browser.assert.equal(response.statusCode, 200);
  });

but of course that does not work.

like image 651
Brown A Avatar asked Mar 21 '16 21:03

Brown A


People also ask

How do I check my HTTP status code?

Just use Chrome browser. Hit F12 to get developer tools and look at the network tab. Shows you all status codes, whether page was from cache etc.

What is the command to run the script Nightwatch?

You can add Nightwatch to your project simply by running npm install nightwatch --save-dev . This places the Nightwatch executable in your ./node_modules/.

What is Nightwatch JS used for?

js, Nightwatch. js is an open-source automated testing framework that aims at providing complete E2E (end to end) solutions to automate testing with Selenium Javascript for web-based applications, browser applications, and websites. Nightwatch.

What is Nightwatch in Selenium?

What is Nightwatch JS? Nightwatch JS is an automated testing framework for web applications and websites, written in Node. js and using the W3C WebDriver API. This is a complete End-to-End testing framework that aims to simplify the process of setting up continuous integration and creating automatic tests.


1 Answers

Supplementing to Hilarion Galushka's answer: you can use the perform() command from nightwatch to intergrate request and assert into your nightwatch tests. http://nightwatchjs.org/api/perform.html

For example:

module.exports = {
    'test response code': function (browser) {
        browser.perform(done => {
            request('http://stackoverflow.com', function (error, response, body) {
                browser.assert.equal(response.statusCode, 200);
                done()
            });
        })
    }
}
like image 60
mibemerami Avatar answered Sep 28 '22 04:09

mibemerami