使用Nightwatch.js测试下载链接 [英] Testing download links with Nightwatch.js

查看:125
本文介绍了使用Nightwatch.js测试下载链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Nightwatch.js构建自动化测试,以验证软件下载链接是否正常工作。我不想下载文件,因为它们非常大,我只想验证相应的链接是否返回200 HTTP响应,以确保链接指向正确的位置。

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.

有关使用Nightwatch.js测试可下载文件链接的方法吗?

Any idea for ways to test links to downloadable files with 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();
    }
};


推荐答案


  1. 使用节点 http 模块并发出HEAD请求

  2. 例如:断言filesize

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

参考

  • Check if file exists on FTPS site using cURL
  • Protractor e2e test case for downloading pdf file
  • Stop downloading the data in nodejs request

这篇关于使用Nightwatch.js测试下载链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆