Test on Internal Networks

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

Enabling Local Testing with Automate is a simple two-step process:

  1. Establishing a Local Testing connection.
  2. Configuring test scripts so they run through the Local Testing connection.

Enabling Local Testing with Automate

You can establish Local Testing connection in one of two ways:

  • Language bindings
  • Command-line interface

Within your test scripts, you can add a snippet that will automatically start and end the Local Testing connection. To do this, you’ll need bindings.

Follow the steps below:

  • Installation using Composer:

      # If you don't already use Composer, you can download the composer.phar binary:
      curl -sS https://getcomposer.org/installer | php
    
      # Include the binding:
      php composer.phar require browserstack/local:dev-master
    
      # Install all the dependencies:
      php composer.phar install
    
      # Test the installation by running a simple test file, check out example.php in the main repository.
    
  • Setup the Local Testing connection in your code:

      require_once("vendor/autoload.php");
      use BrowserStack\Local;
    
      # Creates an instance of Local
      $bs_local = new Local();
    
      # You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
      $bs_local_args = array("key" => "YOUR_ACCESS_KEY");
    
      # Starts the Local instance with the required arguments
      $bs_local->start(bs_local_args);
    
      # Check if BrowserStack local instance is running
      echo $bs_local->isRunning();
    
      # Stop the Local instance
      $bs_local->stop();
    

Refer to this GitHub repository for more details.

You can also start a Local Testing connection through your command-line interface by following the steps below:

./BrowserStackLocal --key YOUR_ACCESS_KEY
BrowserStackLocal.exe --key YOUR_ACCESS_KEY
Note: The Local Testing connection is persistent. Your machine and BrowserStack Cloud remain connected unless you explicitly end the connection. Hence, close the connection after test execution is complete.

The Local Testing setup will differ slightly based on your requirements (for example, proxy settings, restricting connections to certain domains, etc.). Refer to our complete list of flags to set up Local Testing for different environments/network configurations. To know more, please refer the Local Testing document.

Configuring tests to run with Local Testing connection

After establishing the Local Testing connection, set browserstack.local capability to true by adding the following snippet to your test scripts:

caps.setCapability("browserstack.local", "true");
Note: The binary connection needs to be established before creating a test session, and disconnected only after test execution is complete.

To find more about how you can test your websites hosted at your local sites, please read more about Local Testing.

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