Testing download links with Nightwatch.js

前端 未结 1 391
梦如初夏
梦如初夏 2020-12-16 23:51

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

相关标签:
1条回答
  • 2020-12-17 00:46
    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
    0 讨论(0)
提交回复
热议问题