Skip to content

Commit 0afdd14

Browse files
committed
Merge pull request #8 from browserstack/custom_args
Custom args
2 parents 0eaf577 + e9459e2 commit 0afdd14

File tree

3 files changed

+170
-64
lines changed

3 files changed

+170
-64
lines changed

README.md

Lines changed: 108 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,127 @@
22

33
[![Build Status](https://travis-ci.org/browserstack/browserstack-local-nodejs.svg?branch=master)](https://travis-ci.org/browserstack/browserstack-local-nodejs)
44

5-
## Setup
5+
A simple Nodejs wrapper for BrowserStack Local Binary.
6+
7+
## Installation
68

79
```
8-
npm install browserstack
10+
npm install browserstack-local
911
```
1012

11-
## API
13+
## Example
1214

13-
### Constructor
15+
```
16+
var browserstack = require('browserstack-local');
1417
15-
* `new browserstack.Local()`: creates an instance of Local
18+
# creates an instance of Local
19+
var bs_local = new browserstack.Local();
1620
17-
### Methods
21+
# replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
22+
var bs_local_args = { 'key': '<browserstack-accesskey>' };
1823
19-
* `start(options, callback)`: starts Local instance with options. The options available are detailed below.
20-
* `stop(callback)`: stops the Local instance
21-
* `isRunning()`: checks if Local instance is running and returns a corresponding boolean value
24+
# starts the Local instance with the required arguments
25+
bs_local.start(bs_local_args, function() {
26+
console.log("Started BrowserStackLocal");
27+
});
2228
23-
The first and only argument to any callback function will be an error object.
29+
# check if BrowserStack local instance is running
30+
console.log(bs_local.isRunning());
2431
25-
### Options
32+
# stop the Local instance
33+
bs_local.stop(function() {
34+
console.log("Stopped BrowserStackLocal");
35+
});
2636
27-
* `key`: BrowserStack Access Key
28-
* `v`: Provides verbose logging
29-
* `f`: If you want to test local folder rather internal server, provide path to folder as value of this option
30-
* `force`: Kill other running Browserstack Local
31-
* `only`: Restricts Local Testing access to specified local servers and/or folders
32-
* `forcelocal`: Route all traffic via local machine
33-
* `onlyAutomate`: Disable Live Testing and Screenshots, just test Automate
34-
* `proxyHost`: Hostname/IP of proxy, remaining proxy options are ignored if this option is absent
35-
* `proxyPort`: Port for the proxy, defaults to 3128 when -proxyHost is used
36-
* `proxyUser`: Username for connecting to proxy (Basic Auth Only)
37-
* `proxyPass`: Password for USERNAME, will be ignored if USERNAME is empty or not specified
38-
* `localIdentifier`: If doing simultaneous multiple local testing connections, set this uniquely for different processes
39-
* `hosts`: List of hosts and ports where Local must be enabled for eg. localhost,3000,1,localhost,3001,0
40-
* `logfile`: Path to file where Local logs be saved to
41-
* `binarypath`: Optional path to Local binary
37+
```
4238

39+
## Arguments
4340

44-
## Tests
41+
Apart from the key, all other BrowserStack Local modifiers are optional. For the full list of modifiers, refer [BrowserStack Local modifiers](https://www.browserstack.com/local-testing#modifiers). For examples, refer below -
4542

46-
To run the test suite run - `npm test`.
43+
#### Verbose Logging
44+
To enable verbose logging -
45+
```
46+
bs_local_args = { 'key': '<browserstack-accesskey>', 'v': 'true' }
47+
```
4748

48-
## Example
49+
#### Folder Testing
50+
To test local folder rather internal server, provide path to folder as value of this option -
51+
```
52+
bs_local_args = { 'key': '<browserstack-accesskey>', 'f': '/my/awesome/folder' }
53+
```
54+
55+
#### Force Start
56+
To kill other running Browserstack Local instances -
57+
```
58+
bs_local_args = { 'key': '<browserstack-accesskey>', 'force': 'true' }
59+
```
60+
61+
#### Only Automate
62+
To disable local testing for Live and Screenshots, and enable only Automate -
63+
```
64+
bs_local_args = { 'key': '<browserstack-accesskey>', 'onlyAutomate': 'true' }
65+
```
66+
67+
#### Force Local
68+
To route all traffic via local(your) machine -
69+
```
70+
bs_local_args = { 'key': '<browserstack-accesskey>', 'forcelocal': 'true' }
71+
```
72+
73+
#### Proxy
74+
To use a proxy for local testing -
75+
76+
* proxyHost: Hostname/IP of proxy, remaining proxy options are ignored if this option is absent
77+
* proxyPort: Port for the proxy, defaults to 3128 when -proxyHost is used
78+
* proxyUser: Username for connecting to proxy (Basic Auth Only)
79+
* proxyPass: Password for USERNAME, will be ignored if USERNAME is empty or not specified
80+
81+
```
82+
bs_local_args = { 'key': '<browserstack-accesskey>', 'proxyHost': '127.0.0.1', 'proxyPort': '8000', 'proxyUser': 'user', 'proxyPass': 'password' }
83+
```
84+
85+
#### Local Identifier
86+
If doing simultaneous multiple local testing connections, set this uniquely for different processes -
87+
```
88+
bs_local_args = { 'key': '<browserstack-accesskey>', 'localIdentifier': 'randomstring' }
89+
```
90+
91+
## Additional Arguments
92+
93+
#### Binary Path
94+
95+
By default, BrowserStack local wrappers try downloading and executing the latest version of BrowserStack binary in ~/.browserstack or the present working directory or the tmp folder by order. But you can override these by passing the -binarypath argument.
96+
Path to specify local Binary path -
97+
```
98+
bs_local_args = { 'key': '<browserstack-accesskey>', 'binarypath': '/browserstack/BrowserStackLocal' }
99+
```
100+
101+
#### Logfile
102+
To save the logs to the file while running with the '-v' argument, you can specify the path of the file. By default the logs are saved in the local.log file in the present woring directory.
103+
To specify the path to file where the logs will be saved -
104+
```
105+
bs_local_args = { 'key': '<browserstack-accesskey>', 'v': 'true', 'logfile': '/browserstack/logs.txt' }
106+
```
107+
108+
## Contribute
109+
110+
### Instructions
111+
112+
To run the test suite run, `npm test`.
113+
114+
### Reporting bugs
115+
116+
You can submit bug reports either in the Github issue tracker.
117+
118+
Before submitting an issue please check if there is already an existing issue. If there is, please add any additional information give it a "+1" in the comments.
119+
120+
When submitting an issue please describe the issue clearly, including how to reproduce the bug, which situations it appears in, what you expect to happen, what actually happens, and what platform (operating system and version) you are using.
121+
122+
### Pull Requests
123+
124+
We love pull requests! We are very happy to work with you to get your changes merged in, however, please keep the following in mind.
49125

50-
To run the example run - `node node-example.js`.
126+
* Adhere to the coding conventions you see in the surrounding code.
127+
* Include tests, and make sure all tests pass.
128+
* Before submitting a pull-request, clean up the git history by going over your commits and squashing together minor changes and fixes into the corresponding commits. You can do this using the interactive rebase command.

lib/Local.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function Local(){
1111
this.key = process.env.BROWSERSTACK_ACCESS_KEY;
1212
this.logfile = path.join(process.cwd(), 'local.log');
1313
this.exitCallback;
14+
this.userArgs = [];
1415

1516
this.errorRegex = /\*\*\* Error: [^\r\n]*/i;
1617
this.doneRegex = /Press Ctrl-C to exit/i;
@@ -81,88 +82,94 @@ function Local(){
8182
var value = options[key];
8283

8384
switch(key){
84-
case '-key':
85+
case 'key':
8586
this.key = value;
8687
break;
8788

88-
case '-v':
89+
case 'v':
8990
if(value)
9091
this.verboseFlag = '-vvv';
9192
break;
9293

93-
case '-force':
94+
case 'force':
9495
if(value)
9596
this.forceFlag = '-force';
9697
break;
9798

98-
case '-only':
99+
case 'only':
99100
if(value)
100101
this.onlyFlag = '-only';
101102
break;
102103

103-
case '-onlyAutomate':
104+
case 'onlyAutomate':
104105
if(value)
105106
this.onlyAutomateFlag = '-onlyAutomate';
106107
break;
107108

108-
case '-forcelocal':
109+
case 'forcelocal':
109110
if(value)
110111
this.forceLocalFlag = '-forcelocal';
111112
break;
112113

113-
case '-localIdentifier':
114+
case 'localIdentifier':
114115
if(value)
115116
this.localIdentifierFlag = '-localIdentifier ' + value;
116117
break;
117118

118-
case '-f':
119+
case 'f':
119120
if(value){
120121
this.folderFlag = '-f';
121122
this.folderPath = value;
122123
}
123124
break;
124125

125-
case '-proxyHost':
126+
case 'proxyHost':
126127
if(value)
127128
this.proxyHost = '-proxyHost ' + value;
128129
break;
129130

130-
case '-proxyPort':
131+
case 'proxyPort':
131132
if(value)
132133
this.proxyPort = '-proxyPort ' + value;
133134
break;
134135

135-
case '-proxyUser':
136+
case 'proxyUser':
136137
if(value)
137138
this.proxyUser = '-proxyUser ' + value;
138139
break;
139140

140-
case '-proxyPass':
141+
case 'proxyPass':
141142
if(value)
142143
this.proxyPass = '-proxyPass ' + value;
143144
break;
144145

145-
case '-forceproxy':
146+
case 'forceproxy':
146147
if(value)
147148
this.forceProxyFlag = '-forceproxy';
148149
break;
149150

150-
case '-hosts':
151+
case 'hosts':
151152
if(value)
152153
this.hosts = value;
153154
break;
154155

155-
case '-logfile':
156+
case 'logfile':
156157
if(value)
157158
this.logfile = value;
158159
break;
159160

160-
case '-binarypath':
161+
case 'binarypath':
161162
if(value)
162163
this.binaryPath = value;
163164
break;
164165

165166
default:
167+
if(value.toString().toLowerCase() == 'true'){
168+
this.userArgs.push('-' + key);
169+
} else {
170+
this.userArgs.push('-' + key);
171+
this.userArgs.push(value);
172+
}
166173
break;
167174
}
168175
}
@@ -208,6 +215,9 @@ function Local(){
208215
args.push(this.verboseFlag);
209216
if(this.hosts)
210217
args.push(this.hosts);
218+
for(var i in this.userArgs){
219+
args.push(this.userArgs[i]);
220+
}
211221
return args;
212222
};
213223
}

0 commit comments

Comments
 (0)