Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(webdriver-manager): use request module instead of http
Browse files Browse the repository at this point in the history
Google changed selenium-server-standalone.jar's location and is returning 302
http module does not follow redirects

Closes #826
  • Loading branch information
cesarandreu authored and juliemr committed May 21, 2014
1 parent e3731f7 commit 6249efe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
40 changes: 18 additions & 22 deletions bin/webdriver-manager
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var fs = require('fs');
var os = require('os');
var url = require('url');
var request = require('request');
var http = require('http');
var path = require('path');
var AdmZip = require('adm-zip');
Expand Down Expand Up @@ -107,32 +107,28 @@ if (!fs.existsSync(argv.out_dir) || !fs.statSync(argv.out_dir).isDirectory()) {

/**
* Function to download file using HTTP.get.
* Thanks to http://www.hacksparrow.com/using-node-js-to-download-files.html
* for the outline of this code.
* TODO: look into using something instead of request here, to avoid the
* big dependency cost. It's required for now to follow redirects.
*/
var httpGetFile = function(fileUrl, fileName, outputDir, callback) {
console.log('downloading ' + fileUrl + '...');
var options = {
host: url.parse(fileUrl).host,
port: 80,
path: url.parse(fileUrl).pathname
};

http.get(options, function(res) {
var filePath = path.join(outputDir, fileName);
var file = fs.createWriteStream(filePath);
var req = request(fileUrl);
req.on('response', function(res) {
if (res.statusCode !== 200) {
throw new Error('Got code ' + res.statusCode + ' from ' + fileUrl);
}
var filePath = path.join(outputDir, fileName);
var file = fs.createWriteStream(filePath);
res.on('data', function(data) {
file.write(data);
}).on('end', function() {
file.end(function() {
console.log(fileName + ' downloaded to ' + filePath);
if (callback) {
callback(filePath);
}
});
}
});
req.on('data', function(data) {
file.write(data);
});
req.on('end', function() {
file.end(function() {
console.log(fileName + ' downloaded to ' + filePath);
if (callback) {
callback(filePath);
}
});
});
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"author": "Julie Ralph <ju.ralph@gmail.com>",
"dependencies": {
"request": "^2.36.0",
"selenium-webdriver": "2.41.0",
"minijasminenode": "0.4.0",
"saucelabs": "~0.1.0",
Expand Down

0 comments on commit 6249efe

Please sign in to comment.