diff --git a/README.md b/README.md index 38f16e1..8b3e84a 100644 --- a/README.md +++ b/README.md @@ -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': '', 'v': 'true' } +bs_local_args = { 'key': '', 'verbose': 'true' } ``` #### Folder Testing @@ -67,7 +67,7 @@ bs_local_args = { 'key': '', 'onlyAutomate': 'true' } #### Force Local To route all traffic via local(your) machine - ```node -bs_local_args = { 'key': '', 'forcelocal': 'true' } +bs_local_args = { 'key': '', 'forceLocal': 'true' } ``` #### Proxy @@ -91,18 +91,18 @@ bs_local_args = { 'key': '', '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': '', 'binarypath': '/browserstack/BrowserStackLocal' } -``` + + 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': '', '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': '', 'v': 'true', 'logfile': '/browserstack/logs.txt' } +bs_local_args = { 'key': '', 'verbose': 'true', 'logFile': '/browserstack/logs.txt' } ``` ## Contribute diff --git a/lib/Local.js b/lib/Local.js index ce12b0f..4549cdf 100644 --- a/lib/Local.js +++ b/lib/Local.js @@ -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': @@ -152,6 +156,7 @@ function Local(){ break; case 'f': + case 'folder': if(value){ this.folderFlag = '-f'; this.folderPath = value; @@ -179,18 +184,20 @@ function Local(){ break; case 'forceproxy': + case 'forceProxy': if(value) - this.forceProxyFlag = '-forceproxy'; + this.forceProxyFlag = '--force-proxy'; break; - case 'hosts': + case 'logfile': + case 'logFile': if(value) - this.hosts = value; + this.logfile = value; break; - case 'logfile': + case 'parallelRuns': if(value) - this.logfile = value; + this.parallelRunsFlag = value; break; case 'binarypath': @@ -200,9 +207,9 @@ function Local(){ 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; @@ -226,46 +233,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]); } diff --git a/node-example.js b/node-example.js index 511959c..af07f00 100644 --- a/node-example.js +++ b/node-example.js @@ -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, diff --git a/test/local.js b/test/local.js index 02a5e6a..b4e20d9 100644 --- a/test/local.js +++ b/test/local.js @@ -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(); }); }); @@ -64,47 +81,62 @@ 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(); }); @@ -112,7 +144,14 @@ describe('Local', function () { 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(); }); }); @@ -120,12 +159,28 @@ describe('Local', function () { 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, @@ -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(); });