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
1 Answer
Reset to default 5- Use the node
http
module and make a "HEAD" request - 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