|
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/browserstack/browserstack-local-csharp)
|
4 | 4 |
|
| 5 | +A simple C-sharp wrapper for BrowserStack Local Binary. |
| 6 | + |
5 | 7 | ## Setup
|
6 | 8 |
|
7 | 9 | Open the solution file `BrowserStack/BrowserStack.sln` in `Visual Studio`. The projects are `Visual Studio 2015` compatible.
|
8 | 10 | You will need to resolve the references from the `Solution Explorer`. `Visual Studio` with automatically download the references from NuGet.
|
9 | 11 |
|
10 |
| -## API |
| 12 | +## Example |
| 13 | + |
| 14 | +``` |
| 15 | +using BrowserStack; |
| 16 | +
|
| 17 | +# creates an instance of Local |
| 18 | +Local local = new Local(); |
| 19 | +
|
| 20 | +# replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY". |
| 21 | +List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() { |
| 22 | + new KeyValuePair<string, string>("key", "<browserstack-accesskey>"), |
| 23 | +} |
| 24 | +
|
| 25 | +# starts the Local instance with the required arguments |
| 26 | +local.start(bsLocalArgs); |
| 27 | +
|
| 28 | +# check if BrowserStack local instance is running |
| 29 | +Console.WriteLine(local.isRunning()); |
| 30 | +
|
| 31 | +# stop the Local instance |
| 32 | +local.stop(); |
| 33 | +``` |
| 34 | + |
| 35 | +## Arguments |
| 36 | + |
| 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 - |
| 38 | + |
| 39 | +#### Verbose Logging |
| 40 | +To enable verbose logging - |
| 41 | +``` |
| 42 | +bsLocalArgs.Add(new KeyValuePair<string, string>("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 | +bsLocalArgs.Add(new KeyValuePair<string, string>("f", "/my/awesome/folder")); |
| 49 | +``` |
| 50 | + |
| 51 | +#### Force Start |
| 52 | +To kill other running Browserstack Local instances - |
| 53 | +``` |
| 54 | +bsLocalArgs.Add(new KeyValuePair<string, string>("force", "true")); |
| 55 | +``` |
| 56 | + |
| 57 | +#### Only Automate |
| 58 | +To disable local testing for Live and Screenshots, and enable only Automate - |
| 59 | +``` |
| 60 | +bsLocalArgs.Add(new KeyValuePair<string, string>("onlyAutomate", "true")); |
| 61 | +``` |
| 62 | + |
| 63 | +#### Force Local |
| 64 | +To route all traffic via local(your) machine - |
| 65 | +``` |
| 66 | +bsLocalArgs.Add(new KeyValuePair<string, string>("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 | +bsLocalArgs.Add(new KeyValuePair<string, string>("proxyHost", "127.0.0.1")); |
| 79 | +bsLocalArgs.Add(new KeyValuePair<string, string>("proxyPort", "8000")); |
| 80 | +bsLocalArgs.Add(new KeyValuePair<string, string>("proxyUser", "user")); |
| 81 | +bsLocalArgs.Add(new KeyValuePair<string, string>("proxyPass", "password")); |
| 82 | +``` |
| 83 | + |
| 84 | +#### Local Identifier |
| 85 | +If doing simultaneous multiple local testing connections, set this uniquely for different processes - |
| 86 | +``` |
| 87 | +bsLocalArgs.Add(new KeyValuePair<string, string>("localIdentifier", "randomstring")); |
| 88 | +``` |
| 89 | + |
| 90 | +## Additional Arguments |
| 91 | + |
| 92 | +#### Binary Path |
| 93 | + |
| 94 | +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. |
| 95 | +Path to specify local Binary path - |
| 96 | +``` |
| 97 | +bsLocalArgs.Add(new KeyValuePair<string, string>("binarypath", "/browserstack/BrowserStackLocal")); |
| 98 | +``` |
| 99 | + |
| 100 | +#### Logfile |
| 101 | +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. |
| 102 | +To specify the path to file where the logs will be saved - |
| 103 | +``` |
| 104 | +bsLocalArgs.Add(new KeyValuePair<string, string>("v", "true")); |
| 105 | +bsLocalArgs.Add(new KeyValuePair<string, string>("logfile", "/browserstack/logs.txt")); |
| 106 | +``` |
| 107 | + |
| 108 | +## Contribute |
| 109 | + |
| 110 | +### Build Instructions |
| 111 | + |
| 112 | +To run the test suite run the nunit tests from Visual Studio. |
| 113 | + |
| 114 | +### Reporting bugs |
11 | 115 |
|
12 |
| -### Constructor |
| 116 | +You can submit bug reports either in the Github issue tracker. |
13 | 117 |
|
14 |
| -* `new Local()`: creates an instance of Local |
| 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. |
15 | 119 |
|
16 |
| -### Methods |
| 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. |
17 | 121 |
|
18 |
| -* `start(options)`: starts Local instance with options. The options available are detailed below. |
19 |
| -* `stop()`: stops the Local instance |
20 |
| -* `isRunning()`: checks if Local instance is running and returns a corresponding boolean value |
| 122 | +### Pull Requests |
21 | 123 |
|
22 |
| -### Options |
| 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. |
23 | 125 |
|
24 |
| -* `key`: BrowserStack Access Key |
25 |
| -* `v`: Provides verbose logging |
26 |
| -* `f`: If you want to test local folder rather internal server, provide path to folder as value of this option |
27 |
| -* `force`: Kill other running Browserstack Local |
28 |
| -* `only`: Restricts Local Testing access to specified local servers and/or folders |
29 |
| -* `forcelocal`: Route all traffic via local machine |
30 |
| -* `onlyAutomate`: Disable Live Testing and Screenshots, just test Automate |
31 |
| -* `proxyHost`: Hostname/IP of proxy, remaining proxy options are ignored if this option is absent |
32 |
| -* `proxyPort`: Port for the proxy, defaults to 3128 when -proxyHost is used |
33 |
| -* `proxyUser`: Username for connecting to proxy (Basic Auth Only) |
34 |
| -* `proxyPass`: Password for USERNAME, will be ignored if USERNAME is empty or not specified |
35 |
| -* `localIdentifier`: If doing simultaneous multiple local testing connections, set this uniquely for different processes |
36 |
| -* `hosts`: List of hosts and ports where Local must be enabled for eg. localhost,3000,1,localhost,3001,0 |
37 |
| -* `logfile`: Path to file where Local logs be saved to |
38 |
| -* `binarypath`: Optional path to Local binary |
| 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. |
39 | 129 |
|
40 | 130 | ## Example
|
41 | 131 |
|
|
0 commit comments