Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm attempting to build an automated test with Nightwatch.js in order to verify that software download links are working correctly. I don't want to download the files, as they are quite large, I just want to verify that the corresponding link is returning a 200 HTTP response to make sure the links are pointing to the proper place.

Any idea for ways to test links to downloadable files with Nightwatch.js?

Here's what I currently have:

/**
 * 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();
    }
};
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
325 views
Welcome To Ask or Share your Answers For Others

1 Answer

  1. Use the node http module and make a "HEAD" request
  2. For example: assert the filesize

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

References


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...