Java bindings for BrowserStack Local.
Add this dependency to your project's POM:
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-local-java</artifactId>
<version>1.1.4</version>
</dependency>
import com.browserstack.local.Local;
// creates an instance of Local
Local bsLocal = new Local();
// replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
HashMap<String, String> bsLocalArgs = new HashMap<String, String>();
bsLocalArgs.put("key", "<browserstack-accesskey>");
// starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs);
// check if BrowserStack local instance is running
System.out.println(bsLocal.isRunning());
// stop the Local instance
bsLocal.stop();
Apart from the key, all other BrowserStack Local modifiers are optional. For the full list of modifiers, refer BrowserStack Local modifiers. For examples, refer below -
To enable verbose logging -
bsLocalArgs.put("v", "true");
To test local folder rather internal server, provide path to folder as value of this option -
bsLocalArgs.put("f", "/my/awesome/folder");
To kill other running Browserstack Local instances -
bsLocalArgs.put("force", "true");
To disable local testing for Live and Screenshots, and enable only Automate -
bsLocalArgs.put("onlyAutomate", "true");
To route all traffic via local(your) machine -
bsLocalArgs.put("forcelocal", "true");
To route all traffic via the proxy specified.
bsLocalArgs.put("forceproxy", "true");
To use a proxy for local testing -
- proxyHost: Hostname/IP of proxy, remaining proxy options are ignored if this option is absent
- proxyPort: Port for the proxy, defaults to 3128 when -proxyHost is used
- proxyUser: Username for connecting to proxy (Basic Auth Only)
- proxyPass: Password for USERNAME, will be ignored if USERNAME is empty or not specified
bsLocalArgs.put("proxyHost", "127.0.0.1");
bsLocalArgs.put("proxyPort", "8000");
bsLocalArgs.put("proxyUser", "user");
bsLocalArgs.put("proxyPass", "password");
To use local proxy in local testing -
- localProxyHost: Hostname/IP of proxy, remaining proxy options are ignored if this option is absent
- localProxyPort: Port for the proxy, defaults to 8081 when -localProxyHost is used
- localProxyUser: Username for connecting to proxy (Basic Auth Only)
- localProxyPass: Password for USERNAME, will be ignored if USERNAME is empty or not specified
bsLocalArgs.put("localProxyHost", "127.0.0.1");
bsLocalArgs.put("localProxyPort", "8000");
bsLocalArgs.put("-localProxyUser", "user");
bsLocalArgs.put("-localProxyPass", "password");
To use PAC (Proxy Auto-Configuration) in local testing -
- pac-file: PAC (Proxy Auto-Configuration) file’s absolute path
bsLocalArgs.put("-pac-file", "<pac_file_abs_path>");
If doing simultaneous multiple local testing connections, set this uniquely for different processes -
bsLocalArgs.put("localIdentifier", "randomstring");
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 -
bsLocalArgs.put("binarypath", "/browserstack/BrowserStackLocal");
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 -
bsLocalArgs.put("v", "true");
bsLocalArgs.put("logFile", "/browserstack/logs.txt");
To compile the package, mvn compile
.
To run the test suite run, mvn test
.
You can submit bug reports either in the Github issue tracker.
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.
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.
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.
- Adhere to the coding conventions you see in the surrounding code.
- Include tests, and make sure all tests pass.
- 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.