Evaluating the functionality of download links using Nightwatch.js

My goal is to create an automated test using Nightwatch.js to validate the functionality of software download links. Instead of downloading the files, I simply want to confirm that the links are returning a 200 HTTP response, indicating that they are directing users to the correct location.

Does anyone have suggestions for testing downloadable file links with Nightwatch.js?

Below is the current setup I 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();
    }
};

Answer №1

  1. Utilize the `http` module to create a "HEAD" request
  2. For instance: verify the file size

test.js

var http = require("http");

module.exports = {
  "Is file available" : 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

  • Verify file existence on FTPS site using cURL
  • E2E test case for downloading PDF file with Protractor
  • Cease downloading data in Node.js request

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Invoking a function sharing the same name as a local variable

The code snippet below is causing me some trouble... var firstPlay = 1; if (firstPlay == 1) { firstPlay(); } If I remove the if statement and simply have: firstPlay(); It works fine, but for some reason it doesn't work with the if statement. ...

Switch the functionality of a Google Chrome extension back and forth numerous times

My Google Chrome extension works by attaching event listeners to all elements on a page and inserting CSS (lol.js and style.css) when clicked. However, I am facing an issue where I cannot remove the JS and CSS upon clicking the icon again. Right now, I am ...

I'm puzzled as to why I am unable to invoke a class method within this callback function. The error message indicates a TypeError: 'this' is undefined

Currently, I am troubleshooting a challenge in my Angular application that involve TypeScript. The issue lies within a method in a TypeScript class: findArtistBidsAppliedByCurrentWall(bid):Observable<Bid[]> { console.log("findArtistBidsApplied ...

I am experiencing a lack of results when attempting to run db.find() in Mongodb

Recently I delved into the realm of MongoDB, deciding to create a basic application that simply showcases data stored in my database. Check out the code snippet below: var mongoose = require("mongoose"); mongoose.connect("mongodb://localhost ...

Updating an object property within an array in Angular Typescript does not reflect changes in the view

I am currently delving into Typescript and Angular, and I have encountered an issue where my view does not update when I try to modify a value in an array that is assigned to an object I defined. I have a feeling that it might be related to the context b ...

Looking for assistance in transferring information from one webpage to another dynamic webpage

I'm in the process of building a website to feature products using NextJs. My goal is to transfer data from one page to another dynamic page. The data I am working with consists of a json array of objects stored in a data folder within the project. Wh ...

Non-functioning function within object

this is a unique object var Manager = (function () { var self = this; self.fetch = function (request, response) { response.send({ message: 'Data fetched successfully' }); } return self; })() module.ex ...

Loading a series of images in advance using jQuery

I have a series of frames in an animation, with file names like: frame-1.jpg, frame-2.jpg, and I have a total of 400 images. My goal is to preload all 400 images before the animation begins. Usually, when preloading images, I use the following method: v ...

The project is throwing an error: Unable to locate module './lib/md5-hex' in Ember JS

I attempted the following steps: uninstalling md5-hex using npm with the command: npm uninstall md5-hex --save reinstalling md5-hex using npm with the command: npm install md5-hex --save After performing these actions, I ran ember s but unfortunately, i ...

AngularJS: Implementing a toggle click function for a list of items within an iframe

Here's the workflow I'm dealing with: I have a collection of items, each having an ng-click event that triggers the display of an iframe below the clicked item. The process works like this: When clicking an item, a hidden div tag beneath it ap ...

Developing a modal with various hyperlinks

I'm currently working on a website that features multiple news articles, each linking to a separate page. Is it possible to use modal windows to have the articles pop up on the same page instead of opening in a new window? If so, I would greatly appre ...

Is there a way to utilize Selenium in Python to click on numeric buttons with the onclick event?

Here is the HTML code I am working with: <ul aria-hidden="false" aria-labelledby="resultsPerPage-button" id="resultsPerPage-menu" role="listbox" tabindex="0" class="ui-menu ui-corner-bottom ui-widget ui-widget-content" aria-activedescendant="ui-id-2" a ...

Using Django to load a template and incorporate a loading spinner to enhance user experience during data retrieval

In my Django project, I need to load body.html first and then dashboard.html. The dashboard.html file is heavy as it works with python dataframes within the script tag. So, my goal is to display body.html first, and once it's rendered, show a loading ...

Error: The "use client" component does not recognize either window or localStorage

I'm currently working on creating a wrapper function that can be used in every dashboard component. "use client"; const UserWrapper = ({ children }) => { const user = JSON.parse(window.localStorage.getItem("ysg_u")); retur ...

Can I specify which modal or component will appear when I click on a component?

Working on a small Angular 5 project, I have a simple component that represents a food product shown below: [![enter image description here][1]][1] This component is nested within my main component. When this component is clicked, a quantity component/m ...

Chrome has recently updated to version 92, causing unexpected exceptions even when the driver is said to be compatible

After updating the Chrome driver to version 92.0.4515.107 and installing the .rpm file for Chrome version 92, I encountered an exception when running the code: selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching ...

Bypass the Array.reduce method in JavaScript

I'm currently working on finding an elegant solution to a toy example pattern. The goal is to stop the reduce algorithm immediately and return 0 when an element with a value of 0 is encountered, without processing the rest of the elements. let factor ...

Scheduled tasks arranged by the user

My goal is to empower my users to schedule specific actions at their preferred times. With a node server hosted on Azure, I am exploring the potential of using node-schedule for this functionality. One idea I'm considering is running a master schedule ...

What is the correct method for configuring access permissions?

I'm in the process of developing a user management system, but I keep finding myself having to check the user type for each router. router.get('/admin/settings', (req, res) => { if(admin) { //Proceed. } } router.get(&apo ...

Ways to retrieve the highest date value in an array

I'm running into an issue where I am trying to find the maximum day in an array of dates, but for some reason it keeps returning either Invalid Date or null. I'm not sure what's going wrong. Do you think I should convert the values to a diff ...