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:

  • Install browserstack-local npm package:
    npm install browserstack-local --save
    
  • Setup the Local Testing connection in your code:

    const browserstack = require('browserstack-local');
    
    // Creates an instance of Local
    const bs_local = new browserstack.Local();
    
    // You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
    const bs_local_args = { key: 'YOUR_ACCESS_KEY' };
    
    // Starts the Local instance with the required arguments
    bs_local.start(bs_local_args, function () {
      console.log('Started BrowserStackLocal');
    
      // Check if BrowserStack local instance is running
      console.log('BrowserStackLocal running:', bs_local.isRunning());
    
      // Your test code goes here, from creating the driver instance till the end, i.e. driver.quit
    
      // Stop the Local instance after your test run is completed, i.e after driver.quit
      bs_local.stop(function () {
        console.log('Stopped BrowserStackLocal');
      });
    });
    

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