Skip to content

Instantly share code, notes, and snippets.

@EeroHeroHeino
Created July 28, 2015 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EeroHeroHeino/1a2e09f173fe1766f99c to your computer and use it in GitHub Desktop.
Save EeroHeroHeino/1a2e09f173fe1766f99c to your computer and use it in GitHub Desktop.
// Add js step before this step which defines
// - GLOBALS.download_file_link CSS locator to an element with src for the file
// - GLOBALS.expected_download_status optionally expected some other response status than 200
if (!GLOBALS.download_file_link) {
callback("JS-step GLOBALS.download_file_link not set");
}
if (!GLOBALS.expected_download_status) {
var expected_status = 200;
} else {
var expected_status = GLOBALS.expected_download_status;
}
var locator = GLOBALS.download_file_link;
var url = document.querySelector(locator).href;
var request = new XMLHttpRequest();
request.open('GET', url, false);
request.send(null);
if (request.status === expected_status) {
return callback(true);
} else {
callback('Downloading '+url+' failed with '+request.status+' (expected '+expected_status+')');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment