Skip to content

update browserstack local with new commands #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Apart from the key, all other BrowserStack Local modifiers are optional. For the
#### Verbose Logging
To enable verbose logging -
```node
bs_local_args = { 'key': '<browserstack-accesskey>', 'v': 'true' }
bs_local_args = { 'key': '<browserstack-accesskey>', 'verbose': 'true' }
```

#### Folder Testing
Expand All @@ -67,7 +67,7 @@ bs_local_args = { 'key': '<browserstack-accesskey>', 'onlyAutomate': 'true' }
#### Force Local
To route all traffic via local(your) machine -
```node
bs_local_args = { 'key': '<browserstack-accesskey>', 'forcelocal': 'true' }
bs_local_args = { 'key': '<browserstack-accesskey>', 'forceLocal': 'true' }
```

#### Proxy
Expand All @@ -90,19 +90,12 @@ bs_local_args = { 'key': '<browserstack-accesskey>', 'localIdentifier': 'randoms

## Additional Arguments

#### Binary Path

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.
Path to specify local Binary path -
```node
bs_local_args = { 'key': '<browserstack-accesskey>', 'binarypath': '/browserstack/BrowserStackLocal' }
```

#### Logfile
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.
To specify the path to file where the logs will be saved -
```node
bs_local_args = { 'key': '<browserstack-accesskey>', 'v': 'true', 'logfile': '/browserstack/logs.txt' }
bs_local_args = { 'key': '<browserstack-accesskey>', 'verbose': 'true', 'logFile': '/browserstack/logs.txt' }
```

## Contribute
Expand Down
71 changes: 41 additions & 30 deletions lib/Local.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,33 @@ function Local(){
this.key = value;
break;

case 'v':
if(value)
this.verboseFlag = '-vvv';
case 'verbose':
if(value.toString() !== 'true')
this.verboseFlag = value;
else {
this.verboseFlag = '1';
}
break;

case 'force':
if(value)
this.forceFlag = '-force';
this.forceFlag = '--force';
break;

case 'only':
if(value)
this.onlyFlag = '-only';
this.onlyHosts = value;
break;

case 'onlyAutomate':
if(value)
this.onlyAutomateFlag = '-onlyAutomate';
this.onlyAutomateFlag = '--only-automate';
break;

case 'forcelocal':
case 'forceLocal':
if(value)
this.forceLocalFlag = '-forcelocal';
this.forceLocalFlag = '--force-local';
break;

case 'localIdentifier':
Expand All @@ -152,6 +156,7 @@ function Local(){
break;

case 'f':
case 'folder':
if(value){
this.folderFlag = '-f';
this.folderPath = value;
Expand Down Expand Up @@ -179,30 +184,27 @@ function Local(){
break;

case 'forceproxy':
case 'forceProxy':
if(value)
this.forceProxyFlag = '-forceproxy';
break;

case 'hosts':
if(value)
this.hosts = value;
this.forceProxyFlag = '--force-proxy';
break;

case 'logfile':
case 'logFile':
if(value)
this.logfile = value;
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove this option? This option allows us to customize the BrowserStackLocal binary path ( the binary must be present at the path and won't be downloaded ).

We were using this for other language bindings as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I removed that was because I didn't see binarypath listed as an option here, I assumed they removed that option. But I have no knowledge of the inner workings of the Browserstack tunnel, just going straight off of their documentation, so maybe that functionality still exists and it is undocumented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Blackbaud-PatrickOFriel binarypath is an option provided by this wrapper not the actual binary. Can you please add it back in the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha, definitely can do


case 'binarypath':
case 'parallelRuns':
if(value)
this.binaryPath = value;
this.parallelRunsFlag = value;
break;

default:
if(value.toString().toLowerCase() == 'true'){
this.userArgs.push('-' + key);
this.userArgs.push('--' + key);
} else {
this.userArgs.push('-' + key);
this.userArgs.push('--' + key);
this.userArgs.push(value);
}
break;
Expand All @@ -226,46 +228,55 @@ function Local(){
};

this.getBinaryArgs = function(){
var args = ['-d', this.opcode, '-logFile', this.logfile];
var args = ['--daemon', this.opcode, '--log-file', this.logfile];
if(this.folderFlag)
args.push(this.folderFlag);
args.push(this.key);
if(this.key) {
args.push('--key');
args.push(this.key);
}
if(this.folderPath)
args.push(this.folderPath);
if(this.forceLocalFlag)
args.push(this.forceLocalFlag);
if(this.localIdentifierFlag){
args.push('-localIdentifier');
args.push('--local-identifier');
args.push(this.localIdentifierFlag);
}
if(this.onlyFlag)
args.push(this.onlyFlag);
if(this.parallelRunsFlag){
args.push('--parallel-runs');
args.push(this.parallelRunsFlag.toString());
}
if(this.onlyHosts) {
args.push('--only');
args.push(this.onlyHosts);
}
if(this.onlyAutomateFlag)
args.push(this.onlyAutomateFlag);
if(this.proxyHost){
args.push('-proxyHost');
args.push('--proxy-host');
args.push(this.proxyHost);
}
if(this.proxyPort){
args.push('-proxyPort');
args.push('--proxy-port');
args.push(this.proxyPort);
}
if(this.proxyUser){
args.push('-proxyUser');
args.push('--proxy-user');
args.push(this.proxyUser);
}
if(this.proxyPass){
args.push('-proxyPass');
args.push('--proxy-pass');
args.push(this.proxyPass);
}
if(this.forceProxyFlag)
args.push(this.forceProxyFlag);
if(this.forceFlag)
args.push(this.forceFlag);
if(this.verboseFlag)
args.push(this.verboseFlag);
if(this.hosts)
args.push(this.hosts);
if(this.verboseFlag){
args.push('--verbose');
args.push(this.verboseFlag.toString());
}
for(var i in this.userArgs){
args.push(this.userArgs[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion node-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var capabilities = {
}

var options = {
'-key': process.env.BROWSERSTACK_ACCESS_KEY,
'key': process.env.BROWSERSTACK_ACCESS_KEY,
//hosts: [{
// name: 'localhost',
// port: 8080,
Expand Down
90 changes: 73 additions & 17 deletions test/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,25 @@ describe('Local', function () {
});

it('should enable verbose', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'v': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-vvv')).to.not.equal(-1);
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'verbose': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('--verbose')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('1')).to.not.equal(-1);
done();
});
});

it('should enable verbose with log level', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'verbose': 2 }, function(){
expect(bsLocal.getBinaryArgs().indexOf('--verbose')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('2')).to.not.equal(-1);
done();
});
});

it('should enable verbose with log level string', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'verbose': '2' }, function(){
expect(bsLocal.getBinaryArgs().indexOf('--verbose')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('2')).to.not.equal(-1);
done();
});
});
Expand All @@ -64,68 +81,106 @@ describe('Local', function () {
});
});

it('should set folder testing with folder option', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'folder': '/var/html' }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-f')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('/var/html')).to.not.equal(-1);
done();
});
});

it('should enable force', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'force': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-force')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--force')).to.not.equal(-1);
done();
});
});

it('should enable only', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'only': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-only')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--only')).to.not.equal(-1);
done();
});
});

it('should enable onlyAutomate', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'onlyAutomate': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-onlyAutomate')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--only-automate')).to.not.equal(-1);
done();
});
});

it('should enable forcelocal', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'forcelocal': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-forcelocal')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--force-local')).to.not.equal(-1);
done();
});
});

it('should enable forcelocal with camel case', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'forceLocal': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('--force-local')).to.not.equal(-1);
done();
});
});

it('should enable custom boolean args', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'boolArg1': true, 'boolArg2': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-boolArg1')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('-boolArg2')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--boolArg1')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--boolArg2')).to.not.equal(-1);
done();
});
});

it('should enable custom keyval args', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'customKey1': 'custom value1', 'customKey2': 'custom value2' }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-customKey1')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--customKey1')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('custom value1')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('-customKey2')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--customKey2')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('custom value2')).to.not.equal(-1);
done();
});
});

it('should enable forceproxy', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'forceproxy': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-forceproxy')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--force-proxy')).to.not.equal(-1);
done();
});
});

it('should enable forceproxy with camel case', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'forceProxy': true }, function(){
expect(bsLocal.getBinaryArgs().indexOf('--force-proxy')).to.not.equal(-1);
done();
});
});


it('should set localIdentifier', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'localIdentifier': 'abcdef' }, function(){
expect(bsLocal.getBinaryArgs().indexOf('-localIdentifier')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--local-identifier')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('abcdef')).to.not.equal(-1);
done();
});
});

it('should set parallelRuns', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'parallelRuns': '10' }, function(){
expect(bsLocal.getBinaryArgs().indexOf('--parallel-runs')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('10')).to.not.equal(-1);
done();
});
});

it('should set parallelRuns with integer value', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'parallelRuns': 10 }, function(){
expect(bsLocal.getBinaryArgs().indexOf('--parallel-runs')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('10')).to.not.equal(-1);
done();
});
});

it('should set proxy', function (done) {
bsLocal.start({
'key': process.env.BROWSERSTACK_ACCESS_KEY,
Expand All @@ -135,20 +190,21 @@ describe('Local', function () {
'proxyUser': 'user',
'proxyPass': 'pass'
}, function(){
expect(bsLocal.getBinaryArgs().indexOf('-proxyHost')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--proxy-host')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('localhost')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('-proxyPort')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--proxy-port')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf(8080)).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('-proxyUser')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--proxy-user')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('user')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('-proxyPass')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('--proxy-pass')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('pass')).to.not.equal(-1);
done();
});
});

it('should set hosts', function (done) {
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'hosts': 'localhost,8000,0' }, function(){
bsLocal.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY, onlyCommand: true, 'only': 'localhost,8000,0'}, function(){
expect(bsLocal.getBinaryArgs().indexOf('--only')).to.not.equal(-1);
expect(bsLocal.getBinaryArgs().indexOf('localhost,8000,0')).to.not.equal(-1);
done();
});
Expand Down