Test on Internal Networks
BrowserStack enables you to run your JUnit automated tests on your internal development environments, on localhost, and from behind a corporate firewall. This feature is called “Local Testing”.
Local Testing establishes a secure connection between your machine and the BrowserStack cloud. Once you set up Local Testing, all URLs work out of the box, including HTTPS URLs and those behind a proxy or firewall.
Configuring your JUnit tests for Local Testing takes just three steps:
Step 1: Download and install the BrowserStackLocal binary:
<!-- Install using maven -->
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>browserstack-local-java</artifactId>
<version>1.0.6</version>
</dependency>
Step 2: Next, you need to update your JUnit config file, local.conf.json
, and set the browserstack.local
capability to true
:
{
"server": "hub-cloud.browserstack.com",
"user": "BROWSERSTACK_USERNAME",
"key": "BROWSERSTACK_ACCESS_KEY",
"capabilities": {
"build": "junit-browserstack",
"name": "local_test",
"browserstack.debug": true,
"browserstack.local": true
},
"environments": [
{
"browser": "chrome"
}
]
}
Here is a sample test case written for running local with JUnit.
public class LocalTest extends BrowserStackJUnitTest {
@Test
public void test() throws Exception {
SessionId sessionId = ((RemoteWebDriver) driver).getSessionId();
try {
driver.get("http://bs-local.com:45691/check");
assertTrue(driver.getPageSource().contains("Up and running"));
mark(sessionId, "passed", "Local content validated!");
} catch (Throwable t) {
mark(sessionId, "failed", "Local content not validated!");
System.out.println("Exception: " + t);
}
}
}
Step 3: You can now run your JUnit test using BrowserStack Local with the following command:
# Run using maven
mvn test -P local
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!