Skip to content

Commit

Permalink
fix: handle error during init
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Jul 2, 2013
1 parent 5650bda commit a0f9f2c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var SauceConnect = function(emitter, logger) {
};


var SauceLabsBrowser = function(id, args, sauceConnect, /* config.sauceLabs */ config, logger) {
var SauceLabsBrowser = function(id, args, sauceConnect, /* config.sauceLabs */ config, logger, emitter) {
config = config || {};

var username = process.env.SAUCE_USERNAME || args.username || config.username;
Expand All @@ -65,6 +65,7 @@ var SauceLabsBrowser = function(id, args, sauceConnect, /* config.sauceLabs */ c
(args.platform ? ' (' + args.platform + ')' : '') + ' on SauceLabs';
var log = logger.create('launcher.sauce');

var self = this;
var driver;
var captured = false;

Expand All @@ -80,6 +81,10 @@ var SauceLabsBrowser = function(id, args, sauceConnect, /* config.sauceLabs */ c
}, 60000);
};

var formatSauceError = function(err) {
return err.message + '\n ' + err.data.split('\n').shift();
};

var start = function(url) {
var options = {
browserName: args.browserName,
Expand All @@ -99,7 +104,12 @@ var SauceLabsBrowser = function(id, args, sauceConnect, /* config.sauceLabs */ c
url = url + '?id=' + id;

driver = wd.remote('ondemand.saucelabs.com', 80, username, accessKey);
driver.init(options, function() {
driver.init(options, function(err) {
if (err) {
log.error('Can not start %s\n %s', browserName, formatSauceError(err));
return emitter.emit('browser_process_failure', self);
}

log.debug('WebDriver channel instantiated, opening ' + url);
driver.get(url, heartbeat);
});
Expand Down Expand Up @@ -135,6 +145,10 @@ var SauceLabsBrowser = function(id, args, sauceConnect, /* config.sauceLabs */ c
this.isCaptured = function() {
return captured;
};

this.toString = function() {
return this.name;
};
};


Expand Down

0 comments on commit a0f9f2c

Please sign in to comment.