check http status code using nightwatch

后端 未结 3 1800
闹比i
闹比i 2021-02-07 15:26

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

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


        
3条回答
  •  醉梦人生
    2021-02-07 15:54

    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()
                });
            })
        }
    }
    

提交回复
热议问题