使用Nightwatch检查HTTP状态代码 [英] check http status code using nightwatch

查看:70
本文介绍了使用Nightwatch检查HTTP状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用nightwatch.js检查HTTP状态代码?我尝试过

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

但是当然不行.

解决方案

实际上,尚无办法使用Selenium(

const request = require('request');

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

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.

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

这篇关于使用Nightwatch检查HTTP状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆