Skip to main content

Test on Internal Networks

BrowserStack enables you to run your JBehave 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.

Note: Code samples in this guide can be found in the jbehave-browserstack sample repo on GitHub

Configuring your JBehave tests for Local Testing takes just few simple steps:

  1. Clone the serenity-browserstack repo on GitHub with BrowserStack’s sample tests, if not already done:

     git clone https://github.com/browserstack/serenity-browserstack.git
     cd serenity-browserstack
    
  2. You will see that the following dependencies exist in your pom.xml file, which will be responsible for creating the connection between your privately hosted website and the BrowserStack cloud:
    pom.xml
     <!-- Install using maven -->
     <dependency>
         <groupId>com.browserstack</groupId>
         <artifactId>browserstack-local-java</artifactId>
         <version>0.1.0</version>
     </dependency>
    
  3. Install the dependencies using maven (if not already done):

    mvn install
    
  4. Update your JBehave config file, jbehave-browserstack/conf/local.conf.json (in sample repo), and set the browserstack.local capability to true:
     {
       "server": "hub-cloud.browserstack.com",
       "user": "YOUR_USERNAME",
       "key": "YOUR_ACCESS_KEY",
    
       "capabilities": {
         "name": "Bstack-[JBehave] Local Test",
         "browserstack.local": true
       },
    
       "environments": [{
         "browser": "chrome"
       }]
     }
    
  5. Run a sample test case to check whether the Local test connection has been set up properly. You can use the following sample test case, which can be found in the repo under jbehave-browserstack/src/test/resources/stories/local.story:

     // Local Story
     Scenario: Can check tunnel working
    
     When I open health check
     Then I should see "Up and running"
    

    Also, you will need to define the Page, Steps and Embedder(exists in the sample repository):

    jbehave-browserstack/src/test/java/com/browserstack/local/pages/LocalPage.java
     // Local Page
     public class LocalPage {
         private String DEFAULT_LOCAL_URL = "http://bs-local.com:45691/check";
         private WebDriver driver;
         private WebElement element;
    
         public LocalPage(WebDriver driver) {
             this.driver = driver;
         }
    
         public String getPageSource(){
             return driver.getPageSource();
         }
    
         public void openHealthCheck() {
            driver.get(DEFAULT_LOCAL_URL);
         }
     }
    
    jbehave-browserstack/src/test/java/com/browserstack/local/pages/LocalSteps.java
     // Local Steps
     public class LocalSteps {
         private LocalPage page;
    
         public LocalSteps(WebDriver driver) {
             page = new LocalPage(driver);
         }
    
         @When("I open health check")
         public void openHealthCheck() {
             page.openHealthCheck();
         }
    
         @Then("I should see \"$keyword\"")
         public void pageShouldContain(String keyword) {
             Assert.assertTrue(page.getPageSource().contains(keyword));
         }
     }
    
    jbehave-browserstack/src/test/java/com/browserstack/local/LocalEmbedder.java
     // Embedder
     public class LocalEmbedder extends Embedder {
         private WebDriver driver;
    
         public LocalEmbedder(WebDriver driver) {
             this.driver = driver;
         }
    
         @Override
         public EmbedderControls embedderControls() {
             return new EmbedderControls().doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
         }
    
         @Override
         public Configuration configuration() {
             Class<? extends LocalEmbedder> embedderClass = this.getClass();
             return new MostUsefulConfiguration()
                 .useStoryLoader(new LoadFromClasspath(embedderClass.getClassLoader()))
                 .useStoryReporterBuilder(new StoryReporterBuilder()
                     .withCodeLocation(CodeLocations.codeLocationFromClass(embedderClass))
                     .withDefaultFormats()
                     .withCrossReference(new CrossReference()))
                 .useParameterConverters(new ParameterConverters()
                     .addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd"))))
                 .useParameterControls(new ParameterControls().useNameDelimiterLeft("<").useNameDelimiterRight(">"))
                 .useStepPatternParser(new RegexPrefixCapturingPatternParser(
                       "$"))
                 .useStepMonitor(new SilentStepMonitor());
         }
    
         @Override
         public InjectableStepsFactory stepsFactory() {
             return new InstanceStepsFactory(configuration(), new LocalSteps(driver));
         }
    
     }
    
  6. You can now run your JBehave 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






Thank you for your valuable feedback

Is this page helping you?

Yes
No

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!

Talk to an Expert
Talk to an Expert