量角器:是否有可能测试有我的应用程序没有404? [英] Protractor: Is it possible to test that there are no 404 in my app?
问题描述
我是新来的量角器,我想写一个测试,看看有没有美女主播与网址给404错误。
I'm new to protractor, I want to write a test to see that there are no anchors with urls giving 404 errors.
我已经看到了这个如何测试用量角器HTML链接?一>,但对于只有一个确定的环节,我想这样做在页面所有链接。
I've seen this How to test html links with protractor?, but is for one determined link only, I want to do it for all links in the page.
测试应该通过对HTTP状态200,这里<一说href=\"http://stackoverflow.com/questions/25137881/how-to-use-protractor-to-get-the-response-status-$c$c-and-response-text\">How用量角器获得响应状态code和响应文本?
The test should pass for the http status 200, as stated here How to use protractor to get the response status code and response text?
我有两个问题:
- 这是否测试使得量角器意义?
- 是否有可能测试这个?如果是这样,怎么样?
推荐答案
我认为它肯定是可行的,并会使情理之中的事情,如果范围是有限的,因为这不是一个典型的UI测试硒的webdriver的用途。你可以做这样的事情,找到所有环节,得到下面的网址和消防使用像申请模块的GET请求。这里是一个伪code。
I think its definitely doable and would make sense to do it if the scope is limited since this is not a typical UI test that selenium-webdriver is used for. You could do something like, find all links, get underneath url and fire a GET request using a module like request. Here is a pseudo code.
var request = require('request');
var assert = require('assert');
element.all(by.tagName('a')).then(function(link) {
var url = link.getAttribute('href');
if(url) {
request(url, function (error, response, body) {
assert.equal(response.statusCode, 200, 'Status code is not OK');
});
}
});
这篇关于量角器:是否有可能测试有我的应用程序没有404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!