check http status code using nightwatch

后端 未结 3 1805
闹比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 16:06

    Try this

        var http = require("http");
        module.exports = {
          "Check Response Code" : function (client) {
              var request = http.request({
                host: "www.google.com",
                port: 80,
                path: "/images/srpr/logo11w.png",
                method: "HEAD"
              }, function (response) {
                client
                .assert.equal(response.statusCode, 200, 'Check status');
                client.end();
              }).on("error", function (err) {
                console.log(err);
                client.end();
              }).end();
             }
           };
    

提交回复
热议问题