Skip to content

Commit 863d9c8

Browse files
committed
for user args
1 parent 0f01ab8 commit 863d9c8

File tree

2 files changed

+112
-27
lines changed

2 files changed

+112
-27
lines changed

README.md

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,125 @@
22

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

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

79
```
810
gem install browserstack-local
911
```
1012

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

35+
## Arguments
4136

42-
## Build
37+
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 -
4338

44-
To build gem, `rake build`.
39+
#### Verbose Logging
40+
To enable verbose logging -
41+
```
42+
bs_local_args = { "key" => "<browserstack-accesskey>" , "v" => "true"}
43+
```
44+
45+
#### Folder Testing
46+
To test local folder rather internal server, provide path to folder as value of this option -
47+
```
48+
bs_local_args = { "key" => "<browserstack-accesskey>" , "f" => "/my/awesome/folder"}
49+
```
50+
51+
#### Force Start
52+
To kill other running Browserstack Local instances -
53+
```
54+
bs_local_args = { "key" => "<browserstack-accesskey>" , "force" => "true"}
55+
```
56+
57+
#### Only Automate
58+
To disable local testing for Live and Screenshots, and enable only Automate -
59+
```
60+
bs_local_args = { "key" => "<browserstack-accesskey>" , "onlyAutomate" => "true"}
61+
```
62+
63+
#### Force Local
64+
To route all traffic via local(your) machine -
65+
```
66+
bs_local_args = { "key" => "<browserstack-accesskey>" , "forcelocal" => "true"}
67+
```
68+
69+
#### Proxy
70+
To use a proxy for local testing -
71+
72+
* proxyHost: Hostname/IP of proxy, remaining proxy options are ignored if this option is absent
73+
* proxyPort: Port for the proxy, defaults to 3128 when -proxyHost is used
74+
* proxyUser: Username for connecting to proxy (Basic Auth Only)
75+
* proxyPass: Password for USERNAME, will be ignored if USERNAME is empty or not specified
76+
77+
```
78+
bs_local_args = { "key" => "<browserstack-accesskey>", "proxyHost" => "127.0.0.1", "proxyPort" => "8000", "proxyUser" => "user", "proxyPass" => "password"}
79+
```
80+
81+
#### Local Identifier
82+
If doing simultaneous multiple local testing connections, set this uniquely for different processes -
83+
```
84+
bs_local_args = { "key" => "<browserstack-accesskey>" , "localIdentifier" => "randomstring"}
85+
```
86+
87+
## Additional Arguments
88+
89+
#### Binary Path
90+
91+
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.
92+
Path to specify local Binary path -
93+
```
94+
bs_local_args = { "key" => "<browserstack-accesskey>" , "binarypath" => "/browserstack/BrowserStackLocal"}
95+
```
96+
97+
#### Logfile
98+
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.
99+
To specify the path to file where the logs will be saved -
100+
```
101+
bs_local_args = { "key" => "<browserstack-accesskey>" , "v" => "true", "logfile" => "/browserstack/logs.txt"}
102+
```
103+
104+
## Contribute
45105

106+
### Build Instructions
46107

47-
## Tests
108+
To build gem, `rake build`.
48109

49110
To run the test suite run, `rake test`.
111+
112+
### Reporting bugs
113+
114+
You can submit bug reports either in the Github issue tracker.
115+
116+
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.
117+
118+
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.
119+
120+
### Pull Requests
121+
122+
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.
123+
124+
* Adhere to the coding conventions you see in the surrounding code.
125+
* Include tests, and make sure all tests pass.
126+
* 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/browserstack/local.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Local
88

99
def initialize(key = ENV["BROWSERSTACK_ACCESS_KEY"])
1010
@key = key
11+
@user_arguments = []
1112
@logfile = File.join(Dir.pwd, "local.log")
1213
@is_windows = RbConfig::CONFIG['host_os'].match(/mswin|msys|mingw|cygwin|bccwin|wince|emc|win32/)
1314
@exec = @is_windows ? "call" : "exec";
@@ -47,6 +48,12 @@ def add_args(key, value=nil)
4748
@binary_path = value
4849
elsif key == "forceproxy" && value.to_s != "false"
4950
@force_proxy_flag = "-forceproxy"
51+
else
52+
if value.to_s.downcase != true || value.to_s.downcase! != false
53+
@user_arguments << "-#{key}"
54+
else
55+
@user_arguments << "-#{key} #{value}"
56+
end
5057
end
5158
end
5259

@@ -120,6 +127,7 @@ def command
120127

121128
def command_args
122129
args = ["#{@binary_path}", "-logFile", "#{@logfile}", "#{@key}", "#{@folder_flag}", "#{@folder_path}", "#{@force_local_flag}", "#{@local_identifier_flag}", "#{@only_flag}", "#{@only_automate_flag}", "#{@proxy_host}", "#{@proxy_port}", "#{@proxy_user}", "#{@proxy_pass}", "#{@force_proxy_flag}","#{@force_flag}", "#{@verbose_flag}", "#{@hosts}"]
130+
args = args + @user_arguments
123131
args = args.select {|a| a.to_s != "" }
124132
args.push(:err => [:child, :out])
125133
args

0 commit comments

Comments
 (0)