Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing download links with Nightwatch.js

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();
    }
};
like image 248
Kevin Leary Avatar asked Jun 23 '14 15:06

Kevin Leary


1 Answers

  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

  • Check if file exists on FTPS site using cURL
  • Protractor e2e test case for downloading pdf file
  • Stop downloading the data in nodejs request
like image 107
e382df99a7950919789725ceeec126 Avatar answered Oct 09 '22 09:10

e382df99a7950919789725ceeec126