最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Testing download links with Nightwatch.js - Stack Overflow

programmeradmin5浏览0评论

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": "/",
            "software-download-latest-linux": "/",
            "software-download-latest-win32": "/",
            "software-download-latest-win64": "/"
        };

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

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.pany./mac/latest/",
            "software-download-latest-linux": "http://downloads.pany./linux/latest/",
            "software-download-latest-win32": "http://downloads.pany./windows/32/latest/",
            "software-download-latest-win64": "http://downloads.pany./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();
    }
};
Share Improve this question asked Jun 23, 2014 at 15:54 KevinlearyKevinleary 9,7204 gold badges58 silver badges48 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5
  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.",
        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
发布评论

评论列表(0)

  1. 暂无评论