Skip to content

Commit 3edfcca

Browse files
committed
Merge branch 'master' into qunitlogging
2 parents 62b3ef3 + d006c8e commit 3edfcca

File tree

6 files changed

+65
-42
lines changed

6 files changed

+65
-42
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ If nothing is provided as `preset` **default** is used.
3838
- *test_framework*: Specify test framework which will execute the tests.
3939
We support qunit, jasmine and mocha.
4040

41+
- *timeout*: Specify worker timeout with BrowserStack.
42+
4143
- *browsers*: A list of browsers on which tests are to be run.
4244

4345
A sample configuration file:

bin/runner.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var BrowserStack = require('browserstack'),
55
utils = require('../lib/utils');
66
Server = require('../lib/server').Server;
77
config = require('../lib/config');
8-
Tunnel = require('../lib/tunnel').Tunnel;
8+
Tunnel = require('../lib/local').Tunnel;
99

1010
var serverPort = 8888;
1111
var tunnel;
@@ -88,6 +88,14 @@ function launchBrowser(browser, url) {
8888
browser["tunnel_identifier"] = config.tunnelIdentifier;
8989
}
9090

91+
var timeout = parseInt(config.timeout);
92+
if(! isNaN(timeout)) {
93+
browser.timeout = timeout;
94+
} else {
95+
timeout = 300;
96+
}
97+
var activityTimeout = timeout - 10;
98+
9199
client.createWorker(browser, function (err, worker) {
92100
if (err || typeof worker !== 'object') {
93101
console.log("Error from BrowserStack: ", err);
@@ -117,19 +125,28 @@ function launchBrowser(browser, url) {
117125
worker.activityTimeout = setTimeout(function () {
118126
if (!worker.acknowledged) {
119127
var subject = "Worker inactive for too long: " + worker.string;
120-
var content = "Worker details:\n" + JSON.stringify(worker, null, 4);
121-
122-
utils.alertBrowserStack(subject, content);
128+
var content = "Worker details:\n" + JSON.stringify(worker.config, null, 4);
129+
client.takeScreenshot(worker.id, function(error, screenshot) {
130+
if (!error && screenshot.url) {
131+
console.log('[%s] Screenshot: %s', worker.string, screenshot.url);
132+
}
133+
utils.alertBrowserStack(subject, content);
134+
});
123135
}
124-
}, 60 * 1000);
136+
}, activityTimeout * 1000);
125137

126138
setTimeout(function () {
127139
if (workers[key]) {
128140
var subject = "Tests timed out on: " + worker.string;
129-
var content = "Worker details:\n" + JSON.stringify(worker, null, 4);
130-
utils.alertBrowserStack(subject, content);
141+
var content = "Worker details:\n" + JSON.stringify(worker.config, null, 4);
142+
client.takeScreenshot(worker.id, function(error, screenshot) {
143+
if (!error && screenshot.url) {
144+
console.log('[%s] Screenshot: %s', worker.string, screenshot.url);
145+
}
146+
utils.alertBrowserStack(subject, content);
147+
});
131148
}
132-
}, (config.timeout || 300) * 1000);
149+
}, (activityTimeout * 1000));
133150
}
134151
});
135152
}, 2000);
@@ -145,7 +162,7 @@ var launchBrowsers = function(config, browser) {
145162
});
146163
} else {
147164
var url = 'http://localhost:' + serverPort.toString() + '/' + config.test_path;
148-
launchBrowser(browser,url);
165+
launchBrowser(browser,url);
149166
}
150167
}, 100);
151168
}

lib/tunnel.js renamed to lib/local.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
var exec = require('child_process').exec,
22
fs = require('fs'),
33
http = require('http'),
4-
tunnelJar = __dirname + '/BrowserStackTunnel.jar',
4+
windows = (process.platform.match(/win/) != null),
5+
localBinary = __dirname + (windows ? '/BrowserStackTunnel.jar' : '/BrowserStackLocal'),
56
utils = require('./utils'),
67
config = require('./config');
78

8-
var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
9+
var Tunnel = function Tunnel (key, port, uniqueIdentifier, callback, err) {
910
var that = {};
1011

1112
function tunnelLauncher () {
12-
var tunnelCommand = 'java -jar ' + tunnelJar + ' ';
13+
var tunnelCommand = (windows ? 'java -jar ' : '') + localBinary + ' ';
1314
if (config.debug)
1415
tunnelCommand += ' -v ';
1516
tunnelCommand += key + ' ';
1617
tunnelCommand += 'localhost' + ',';
1718
tunnelCommand += port.toString() + ',';
1819
tunnelCommand += '0';
19-
tunnelCommand += (typeof tunnelIdentifier === 'undefined')? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + tunnelIdentifier;
20+
tunnelCommand += (typeof uniqueIdentifier === 'undefined')? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + uniqueIdentifier;
2021

2122
if (typeof callback !== 'function') {
2223
callback = function () {};
2324
}
2425

25-
console.log("Launching tunnel");
26+
console.log("[%s] Launching tunnel", new Date());
2627
var subProcess = exec(tunnelCommand, function (error, stdout, stderr) {
2728
console.log(stderr);
29+
console.log(error);
2830
if (stdout.indexOf('Error') >= 0) {
29-
console.log("Tunnel launching failed");
31+
console.log("[%s] Tunnel launching failed", new Date());
3032
console.log(stdout);
3133
process.exit(1);
3234
}
@@ -38,8 +40,7 @@ var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
3840

3941
setTimeout(function () {
4042
if (!running) {
41-
utils.alertBrowserStack("Tunnel launch timeout",
42-
'Stdout:\n' + data);
43+
utils.alertBrowserStack("Tunnel launch timeout", 'Stdout:\n' + data);
4344
}
4445
}, 30 * 1000);
4546

@@ -52,28 +53,31 @@ var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
5253

5354
if (data.indexOf(runMatcher) >= 0) {
5455
running = true;
55-
console.log("Tunnel launched");
56+
console.log("[%s] Tunnel launched", new Date());
5657
callback();
5758
}
5859
});
5960

6061
that.process = subProcess;
6162
}
6263

63-
fs.exists(tunnelJar, function (exists) {
64+
fs.exists(localBinary, function (exists) {
6465
if (exists) {
65-
fs.unlinkSync(tunnelJar);
66+
fs.unlinkSync(localBinary);
67+
// tunnelLauncher();
68+
// return;
6669
}
67-
console.log('Downloading tunnel jar to `%s`', tunnelJar);
70+
console.log('Downloading BrowserStack Local to `%s`', localBinary);
6871

69-
var file = fs.createWriteStream(tunnelJar);
72+
var file = fs.createWriteStream(localBinary);
7073
var request = http.get(
71-
"http://www.browserstack.com/BrowserStackTunnel.jar",
74+
(windows ? "http://www.browserstack.com/BrowserStackTunnel.jar" : ("http://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-" + process.platform + "-" + process.arch)),
7275
function(response) {
7376
response.pipe(file);
7477

7578
response.on('end', function () {
76-
tunnelLauncher();
79+
fs.chmodSync(localBinary, 0700);
80+
setTimeout(function() {tunnelLauncher();}, 100);
7781
});
7882
}
7983
);

lib/server.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,30 @@ exports.Server = function Server(bsClient, workers) {
138138
if (worker) {
139139
bsClient.takeScreenshot(worker.id,function(error,screenshot){
140140
if(!error && screenshot.url){
141-
console.log('[%s] Screenshot: %s', worker.string, screenshot.url);
141+
console.log('[%s] Screenshot: %s', worker.string, screenshot.url);
142142
}
143143

144-
bsClient.terminateWorker(worker.id, function () {
145-
if (!workers[uuid]) {
146-
return;
147-
}
144+
bsClient.terminateWorker(worker.id, function () {
145+
if (!workers[uuid]) {
146+
return;
147+
}
148148

149-
console.log('[%s] Terminated', worker.string);
149+
console.log('[%s] Terminated', worker.string);
150150

151-
clearTimeout(workers[uuid].activityTimeout);
152-
delete workers[uuid];
151+
clearTimeout(workers[uuid].activityTimeout);
152+
delete workers[uuid];
153153

154-
if (utils.objectSize(workers) === 0) {
155-
console.log("All tests done, failures: %d.", status);
154+
if (utils.objectSize(workers) === 0) {
155+
console.log("All tests done, failures: %d.", status);
156156

157-
if (status > 0) {
158-
status = 1;
159-
}
157+
if (status > 0) {
158+
status = 1;
159+
}
160160

161-
process.exit(status);
162-
}
161+
process.exit(status);
162+
}
163+
});
163164
});
164-
});
165165
}
166166

167167
response.end();

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var alertBrowserStack = function alertBrowserStack (subject, content, params, fn
3535
var urlObject = url.parse(endpoint);
3636

3737
var context = config.alert_context || "Runner alert";
38-
console.log("[%s] %s", context, subject);
38+
console.log("[%s] [%s] %s", new Date(), context, subject);
3939

4040
if (typeof fn !== 'function') {
4141
if (typeof params === 'function') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "browserstack-runner",
33
"description": "A command line interface to run browser tests over BrowserStack",
4-
"version": "0.1.1",
4+
"version": "0.1.4",
55
"homepage": "https://github.com/browserstack/browserstack-runner",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)