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.
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.
You can add Nightwatch to your project simply by running npm install nightwatch --save-dev . This places the Nightwatch executable in your ./node_modules/.
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 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.
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()
});
})
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With