Skip to content

Commit b9ed8ad

Browse files
committed
Merge branch 'master' into pr/6
2 parents a8fd027 + f797cd5 commit b9ed8ad

File tree

6 files changed

+66
-30
lines changed

6 files changed

+66
-30
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ If nothing is provided as `preset` **default** is used.
2727
### Parameters
2828

2929
- *username*: BrowserStack username
30-
(Alternatively: use `BROWSERSTACK_UESRNAME` environment variable)
30+
(Alternatively: use `BROWSERSTACK_USERNAME` environment variable)
3131

3232
- *key*: BrowserStack key
3333
(Alternatively: use `BROWSERSTACK_KEY` environment variable)
@@ -92,6 +92,21 @@ A sample configuration file:
9292
}
9393

9494

95+
### Enviroment variables
96+
97+
* `BROWSERSTACK_USER`:
98+
BrowserStack user name.
99+
100+
* `BROWSERSTACK_KEY`:
101+
BrowserStack key.
102+
103+
* `TUNNEL_ID`:
104+
Identifier for the current instance of the tunnel process. In `TRAVIS` setup `TRAVIS_JOB_ID` will be the default identifier.
105+
106+
* `BROWSERSTACK_JSON`:
107+
Path to the browserstack.json file. If null, `browserstack.json` in the root directory will be used.
108+
109+
95110
### Secure Information
96111

97112
To prevent checking in the BrowserStack `username` and `key` in your

bin/runner.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var cleanUp = function cleanUp () {
5757
process.on('exit', cleanUp);
5858
process.on('SIGINT', cleanUp);
5959

60-
console.log("Launching server..");
60+
console.log("Launching server on port:", serverPort);
6161

6262
var server = new Server(client, workers);
6363
server.listen(parseInt(serverPort, 10));
@@ -87,6 +87,10 @@ function launchBrowser(browser) {
8787
browser.build = config.build;
8888
}
8989

90+
if(config.tunnelIdentifier) {
91+
browser["tunnel_identifier"] = config.tunnelIdentifier;
92+
}
93+
9094
client.createWorker(browser, function (err, worker) {
9195
if (err || typeof worker !== 'object') {
9296
utils.alertBrowserStack("Failed to launch worker",
@@ -135,7 +139,8 @@ function launchBrowser(browser) {
135139
}
136140

137141
if (config.browsers && config.browsers.length > 0) {
138-
tunnel = new Tunnel(config.key, serverPort, function () {
142+
tunnel = new Tunnel(config.key, serverPort, config.tunnelIdentifier, function () {
143+
console.log("Launching BrowserStack workers");
139144
config.browsers.forEach(function(browser) {
140145
if (browser.browser_version === "latest") {
141146
console.log("[%s] Finding version.", utils.browserString(browser));

lib/config.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ var path = require('path'),
22
fs = require('fs');
33
var pwd = process.cwd();
44

5+
config_path = process.env.BROWSERSTACK_JSON || 'browserstack.json';
6+
config_path = path.resolve(path.relative(process.cwd(), config_path));
7+
console.log("Using config:", config_path);
8+
59
try {
6-
var config = require(process.cwd() + '/browserstack');
10+
var config = require(config_path);
711
} catch (e) {
812
if (e.code == 'MODULE_NOT_FOUND') {
9-
console.error('Configuration file `browserstack.json` is missing.');
13+
console.log('Configuration file `browserstack.json` is missing.');
1014
} else {
11-
throw(e);
15+
console.log('Invalid configuration in `browserstack.json` file');
16+
console.log(e.message);
17+
console.log(e.stack);
1218
}
13-
1419
process.exit(1);
1520
}
1621

@@ -61,6 +66,8 @@ if (!fs.existsSync(config.test_path)){
6166
process.exit(1);
6267
}
6368

69+
config.tunnelIdentifier = process.env.TUNNEL_ID || process.env.TRAVIS_JOB_ID || process.env.TRAVIS_BUILD_ID;
70+
6471
for (key in config) {
6572
if (config.hasOwnProperty(key)) {
6673
exports[key] = config[key];

lib/server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ exports.Server = function Server(bsClient, workers) {
130130
status += query.failed;
131131

132132
if (worker) {
133+
bsClient.takeScreenshot(worker.id,function(error,screenshot){
134+
if(!error && screenshot.url){
135+
console.log('[%s] Screenshot: %s', worker.string, screenshot.url);
136+
}
137+
133138
bsClient.terminateWorker(worker.id, function () {
134139
if (!workers[uuid]) {
135140
return;
@@ -150,6 +155,7 @@ exports.Server = function Server(bsClient, workers) {
150155
process.exit(status);
151156
}
152157
});
158+
});
153159
}
154160

155161
response.end();

lib/tunnel.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
var exec = require('child_process').exec,
22
fs = require('fs'),
33
http = require('http'),
4-
tunnelJar = '/tmp/BrowserStackTunnel.jar',
5-
utils = require('./utils');
4+
tunnelJar = __dirname + '/BrowserStackTunnel.jar',
5+
utils = require('./utils'),
6+
config = require('./config');
67

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

1011
function tunnelLauncher () {
1112
var tunnelCommand = 'java -jar ' + tunnelJar + ' ';
13+
if (config.debug)
14+
tunnelCommand += ' -v ';
1215
tunnelCommand += key + ' ';
1316
tunnelCommand += 'localhost' + ',';
1417
tunnelCommand += port.toString() + ',';
1518
tunnelCommand += '0';
16-
tunnelCommand += ' -force -onlyAutomate';
19+
tunnelCommand += (typeof tunnelIdentifier === 'undefined')? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + tunnelIdentifier;
1720

1821
if (typeof callback !== 'function') {
1922
callback = function () {};
2023
}
2124

22-
console.log("Launching tunnel..");
25+
console.log("Launching tunnel");
2326
var subProcess = exec(tunnelCommand, function (error, stdout, stderr) {
27+
console.error(stderr);
2428
if (stdout.indexOf('Error') >= 0) {
25-
console.log("..Failed");
29+
console.log("Tunnel launching failed");
2630
console.log(stdout);
2731
process.exit(1);
2832
}
@@ -48,7 +52,7 @@ var Tunnel = function Tunnel (key, port, callback, err) {
4852

4953
if (data.indexOf(runMatcher) >= 0) {
5054
running = true;
51-
console.log("..Done");
55+
console.log("Tunnel launched");
5256
callback();
5357
}
5458
});
@@ -58,22 +62,21 @@ var Tunnel = function Tunnel (key, port, callback, err) {
5862

5963
fs.exists(tunnelJar, function (exists) {
6064
if (exists) {
61-
tunnelLauncher();
62-
} else {
63-
console.log('Downloading tunnel to `%s`', tunnelJar);
65+
fs.unlinkSync(tunnelJar);
66+
}
67+
console.log('Downloading tunnel jar to `%s`', tunnelJar);
6468

65-
var file = fs.createWriteStream(tunnelJar);
66-
var request = http.get(
67-
"http://www.browserstack.com/BrowserStackTunnel.jar",
68-
function(response) {
69-
response.pipe(file);
69+
var file = fs.createWriteStream(tunnelJar);
70+
var request = http.get(
71+
"http://www.browserstack.com/BrowserStackTunnel.jar",
72+
function(response) {
73+
response.pipe(file);
7074

71-
response.on('end', function () {
72-
tunnelLauncher();
73-
});
74-
}
75-
);
76-
}
75+
response.on('end', function () {
76+
tunnelLauncher();
77+
});
78+
}
79+
);
7780
});
7881

7982
return that;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "browserstack-runner",
33
"description": "A command line interface to run browser tests over BrowserStack",
4-
"version": "0.0.11",
4+
"version": "0.0.15",
55
"homepage": "https://github.com/browserstack/browserstack-runner",
66
"repository": {
77
"type": "git",
88
"url": "git://github.com/browserstack/browserstack-runner.git"
99
},
1010
"dependencies": {
11-
"browserstack": "git://github.com/browserstack/node-browserstack.git"
11+
"browserstack": "1.0.1"
1212
},
1313
"bin": {
1414
"browserstack-runner": "bin/cli.js"

0 commit comments

Comments
 (0)