我试图用Nightwatch.js构建一个自动测试,以验证软件下载链接是否正常工作。我不想下载这些文件,因为它们很大,我只想验证相应的链接是否返回了200个HTTP响应,以确保链接指向正确的位置。
对用Nightwatch.js测试可下载文件链接的方法有什么想法吗?
以下是我目前的情况:
/**
* Test Software Downloads
*
* Verify that software downloads are working
*/
module.exports = {
"Download redirect links": function (browser) {
// download links
var downloadLinks = {
"software-download-latest-mac": "http://downloads.company.com/mac/latest/",
"software-download-latest-linux": "http://downloads.company.com/linux/latest/",
"software-download-latest-win32": "http://downloads.company.com/windows/32/latest/",
"software-download-latest-win64": "http://downloads.company.com/windows/64/latest/"
};
// loop through download links
for (var key in downloadLinks) {
if (downloadLinks.hasOwnProperty(key)) {
// test each link's status
browser
.url(downloadLinks[key]);
}
}
// end testing
browser.end();
}
};发布于 2015-02-10 06:24:43
http模块并发出"HEAD“请求test.js
var http = require("http");
module.exports = {
"Is file avaliable" : 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.headers["content-length"], 14022, 'Same file size');
client.end();
}).on("error", function (err) {
console.log(err);
client.end();
}).end();
}
};参考资料
https://stackoverflow.com/questions/24370238
复制相似问题