check http status code using nightwatch

后端 未结 3 1803
闹比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:04

    Actually there is no way yet to get the response status of the page using Selenium (https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/141)

    But what you can easily do is require "request" library, make your request to the webpage you want to open in your Selenium tests and validate that response status code equals 200:

    const request = require('request');
    
    request('http://stackoverflow.com', (error, response, body) => {
        browser.assert.equal(response.statusCode, 200);
    });
    

提交回复
热议问题