gpt4 book ai didi

javascript - 使用 Nightwatch.js 测试下载链接

转载 作者:数据小太阳 更新时间:2023-10-29 05:22:54 26 4
gpt4 key购买 nike

我正在尝试使用 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();
}
};

最佳答案

  1. 使用节点 http 模块并发出“HEAD”请求
  2. 例如:断言文件大小

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

引用资料

关于javascript - 使用 Nightwatch.js 测试下载链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24370238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com