如何使用nightwatch检查网页中所有链接的HTTPS响应状态?
"HttpResponse": function (client) {
var http = require("http");
client.maximizeWindow()
.url('https://www.google.co.in');
client.elements('css selector', ' a', function (result) {
console.log(result.value.length);
for (var a=0;a<result.value.length;a++) {
client.elementIdAttribute(result.value[a].ELEMENT, 'href', function (link) {
console.log('Link Text' + link.value);
var request = http.request({
host: "www.google.co.in",
port: 80,
path: link.value.split('google.co.in')[1],
method: "HEAD"
}, function (response) {
client
.assert.equal(response.statusCode, 200, 'Check status');
client.end();
}).on("error", function (err) {
console.log(err);
client.end();
}).end();
})
}
});
这对我不起作用。
我得到以下错误:
Failed [equal]: (Check status) - expected "200" but got: "302"
at ClientRequest.<anonymous>
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:565:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)
at Socket.socketOnData (_http_client.js:454:20)
at addChunk (_stream_readable.js:252:12)
at readableAddChunk (_stream_readable.js:239:11)
at Socket.Readable.push (_stream_readable.js:197:10)
at TCP.onread (net.js:589:20)
预期为200但是它会抛出302