一尘不染

使用Nightwatch.js测试下载链接

selenium

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

阅读 402

收藏
2020-06-26

共1个答案

一尘不染

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