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

Commit

Permalink
fix: fix browserstack api tunnelling option
Browse files Browse the repository at this point in the history
feat: added captureTimeout option support
feat: added retryLimit option support
feat: added optionals browserstack api options  (build, project, bane, timeout)
  • Loading branch information
inspector-ambitious committed Oct 4, 2013
1 parent c027e2b commit 9453045
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ module.exports = function(config) {
- `username` your BS username (email), you can also use `BROWSER_STACK_USERNAME` env variable.
- `accessKey` your BS access key (password), you can also use `BROWSER_STACK_ACCESS_KEY` env variable.
- `startTunnel` do you wanna establish the BrowserStack tunnel ? (defaults to `true`)

- `retryLimit` how many times do you want to retry to capture the browser ? (defaults to `3`)
- `captureTimeout` the browser capture timeout (defaults to `120`)
- `timeout` the BS worker timeout (defaults to `300`
- `build` the BS worker build name (optional)
- `name` the BS worker name (optional)
- `project` the BS worker project name (optional)

### Per browser options
- `device` name of the device
Expand Down
65 changes: 60 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,44 @@ var createBrowserStackClient = function(/* config.browserStack */ config) {
var formatError = function(error) {
if (error.message === 'Validation Failed') {
return ' Validation Failed: you probably misconfigured the browser ' +
'or given browser is not available.';
'or given browser is not available.';
}

return error.toString();
};


var BrowserStackBrowser = function(id, emitter, args, logger,
/* browserStackTunnel */ tunnel, /* browserStackClient */ client) {
/* config */ config,
/* browserStackTunnel */ tunnel, /* browserStackClient */ client) {

var self = this;
var workerId = null;
var captured = false;
var log = logger.create('launcher.browserstack');
var browserName = (args.browser || args.device) + (args.browser_version ? ' ' + args.browser_version : '') +
' (' + args.os + ' ' + args.os_version + ')' + ' on BrowserStack';
' (' + args.os + ' ' + args.os_version + ')' + ' on BrowserStack';

this.id = id;
this.name = browserName;

var bsConfig = config.browserStack;

var captureTimeout = 0;

if (config.captureTimeout) {
captureTimeout = config.captureTimeout;
}

var retryLimit = 3;
if (bsConfig) {
if (bsConfig.retryLimit) {
retryLimit = bsConfig.retryLimit;
}
}

this.start = function(url) {

// TODO(vojta): handle non os/browser/version
var settings = {
os: args.os,
Expand All @@ -90,6 +107,26 @@ var BrowserStackBrowser = function(id, emitter, args, logger,
url: url + '?id=' + id
};

if (bsConfig) {
settings['browserstack.tunnel'] = true;
if (bsConfig.startTunnel === false) {
settings['browserstack.tunnel'] = false;
}
if (bsConfig.timeout) {
settings.timeout = bsConfig.timeout;
}
if (bsConfig.name) {
settings.name = bsConfig.name;
}
if (bsConfig.build) {
settings.build = bsConfig.build;
}
if (bsConfig.project) {
settings.project = bsConfig.project;
}
}

this.url = url;
tunnel.then(function() {
client.createWorker(settings, function(error, worker) {
if (error) {
Expand All @@ -99,9 +136,14 @@ var BrowserStackBrowser = function(id, emitter, args, logger,

log.debug('Browser %s started with id %s', browserName, worker.id);
workerId = worker.id;

if (captureTimeout) {
setTimeout(self._onTimeout, captureTimeout);
}

});
}, function() {
emitter.emit('browser_process_failure', self);
emitter.emit('browser_process_failure', self);
});
};

Expand All @@ -126,6 +168,19 @@ var BrowserStackBrowser = function(id, emitter, args, logger,
this.toString = function() {
return this.name;
};

this._onTimeout = function() {
if (captured) {
return;
}
captured = false;
log.warn('%s have not captured in %d ms, killing.', browserName, captureTimeout);
self.kill(function() {
if(retryLimit--) {
self.start(self.url);
}
});
};
};


Expand All @@ -134,4 +189,4 @@ module.exports = {
'browserStackTunnel': ['factory', createBrowserStackTunnel],
'browserStackClient': ['factory', createBrowserStackClient],
'launcher:BrowserStack': ['type', BrowserStackBrowser]
};
};

0 comments on commit 9453045

Please sign in to comment.