Skip to main content

Test on Internal Networks

Run Cucumber Java tests on your privately hosted websites using BrowserStack Automate.

Important: Sample test scripts are available in the cucumber-java-browserstack repository.

The sample test script in this section is compatible with JSON wire protocol-based client bindings. Check out our W3C-based scripts in the selenium-4 branch of the repository.

Introduction

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

This guide will help you:

  1. Run your first local test
  2. Understand details of the local test script

Prerequisites

If you have already run your first test, you can skip the prerequisites.

  • BrowserStack Username and Access key, which you can find in your account settings. If you have not created an account yet, you can sign up for a Free Trial or purchase a plan.
  • Maven is installed on your machine, Maven environment variables are set, and Maven bin is added to system path, $PATH. Check out the official website to download the latest version of Maven.
  • Git installed on your machine.
  • Java installed on your machine.

Run your first local test

Configure your Cucumber Java tests for Local Testing using the following steps:

  1. Clone the cucumber-java-browserstack sample repo on GitHub using the following command:

    git clone https://github.com/browserstack/cucumber-java-browserstack.git
    cd cucumber-java-browserstack
    
  2. Verify that the browserstack-local-java dependency is added in the pom.xml file:

    pom.xml
     <!-- Install using maven -->
     <dependency>
       <groupId>com.browserstack</groupId>
       <artifactId>browserstack-local-java</artifactId>
       <version>1.0.6</version>
     </dependency>
    
  3. Install the required dependencies by running the following command in your command-line:

      mvn install
    
  4. Update your Cucumber Java config file, cucumber-java-browserstack/src/test/resources/conf/local.conf.json, in your sample repository to set your BrowserStack Username and Access Key.

    Verify that the browserstack.local capability is set to true:

     {
       "server": "hub.browserstack.com",
       "user": "YOUR_USERNAME",
       "key": "YOUR_ACCESS_KEY",
    
       "capabilities": {
         "build": "cucumber-java-browserstack",
         "name": "local_test",
         "browserstack.debug": true,
         "browserstack.local": true
       },
    
       "environments": [{
         "browser": "chrome"
       }]
     }
    
  5. Run your Cucumber Java test using BrowserStack Local with the following command:

       mvn test -P local
    
  6. View your tests on BrowserStack on the BrowserStack Automate Dashboard.
Protip: You can use our capability builder and select from a wide range of custom capabilities that BrowserStack supports.

Understand your local test script

When you run the mvn compile exec:java -P local command, the RunWebDriverCucumberTests.java file within the cucumber-java-browserstack/src/test/java/com/browserstack directory is executed, which uses the Cucumber TestNG Runner to run the Local.feature file.

When the test is triggered, it:

  • Opens the http://bs-local.com:45691/check website.
  • Checks whether the web page displays the Up and running text.
  • Marks the test as passed or failed based on whether the text is displayed on the web page.
Local.feature
  Feature: Verify Local test

  Scenario: Navigate to Local check page
    Given I am on the website 'http://bs-local.com:45691/check'
    Then the page should contain 'Up and running'

Understand the Cucumber Java configuration file

In the sample repository, the configuration file named local.conf.json exists in the cucumber-java-browserstack/src/test/resources/conf/ directory of the project. It is preloaded with default configuration for connecting tests to BrowserStack, and sample capabilities, such as browser name and its version, for running tests.

The capability browserstack.local is set to true in this file to run local tests.

parallel.conf.json
     {
      "server": "hub.browserstack.com",
      "user": "YOUR_USERNAME",
      "key": "YOUR_ACCESS_KEY",

      "capabilities": {
        "build": "cucumber-java-browserstack",
        "browserstack.debug": true,
        "browserstack.local": true
      },

      "environments": [{
        "browser": "chrome"
      }]
    }

Next steps

After you have successfully run your first test using BrowserStack Local, you can explore the following sections:

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