Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & Test Observability
No Result Found

Manage incoming connections from BrowserStack to your private servers

Manage incoming connections from BrowserStack while testing your locally hosted websites

Your website need not be publicly available for you to be able to test it using BrowserStack Automate. Using BrowserStack Local Testing, you can create a secure tunnel connection between your network and the BrowserStack cloud, using which, the remote browsers can resolve your localhost URLs and enable you to test any website that is hosted locally and not resolvable over the public Internet.

If you have not already set up a Local Testing connection, use this step-by-step guide to complete the setup.

This document covers how you can manage the incoming connections from the BrowserStack cloud to your private servers which hosts the application that you want to test.

If you are using BrowserStack SDK, you can set the capabilities covered in this document within the browserstack.yml file:

Test localhost websites

Once you’ve enabled Local Testing connection, our remote browsers and mobile devices will be able to access localhost URLs.

Use your test scripts to access and interact with your localhost website (for example, localhost:3000). Set browserstackLocal capability to true in your browserstack.yml configuration file.

browserstack.yml
Copy icon Copy

Due to security restrictions in Safari (on iOS 10 and above), localhost URLs will automatically change to http://bs-local.com. This lets us load your website assets properly and does not affect your test scripts. Remember to configure your local server to serve requests from bs-local.com.

Force all requests to resolve through your internal network

You can force all traffic through your internal network even if the resources are publicly resolvable using Local Testing’s --force-local capability. This option resolves all requests (on our remote browsers and devices) through your local machine.

To enable this option, add the following capability to your browserstack.yml file:

browserstack.yml
Copy icon Copy

After establishing the Local Testing connection, use your test scripts to access and interact with your internally-hosted website (for example, staging.example.com). Remember to set local capability to true in your test scripts.

Bypass invalid certificate warning while testing on local HTTPS websites

You can test local websites with SSL certificates on our remote browsers and devices through Local Testing. When you access local websites that have SSL certificates on the browsers, you might see an “invalid certificate” error:

Invalid Certificate Error Window

browserstack.yml
Copy icon Copy

Now, use your test scripts to access and interact with your local HTTPS websites (for example, https://localhost:3000 or https://staging.example.com). Remember to set local capability to true in your test scripts before you run them.

BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.

Test localhost websites

Once you’ve enabled Local Testing connection, our remote browsers and mobile devices will be able to access localhost URLs.

Use your test scripts to access and interact with your localhost website (for example, localhost:3000). Add the following snippet to your test scripts to set the local capability to true:

MutableCapabilities capabilities = new MutableCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("local", "true");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
  'bstack:options' : {
    "local" : "true"
  }
}
ChromeOptions capabilities = new ChromeOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("local", "true");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
$caps = array(
'bstack:options' => array(
    "local" => "true"
    )
)
bstack_options = {
    "local": "true"
}
options = ChromeOptions()
options.set_capability('bstack:options', bstack_options)
options = Selenium::WebDriver::Options.chrome
capabilities = {
  'bstack:options' => {
   "local" = "true"
  }
}

Due to security restrictions in Safari (on iOS 10 and above), localhost URLs will automatically change to http://bs-local.com. This lets us load your website assets properly and does not affect your test scripts. Remember to configure your local server to serve requests from bs-local.com.

Force all requests to resolve through your internal network

You can force all traffic through your internal network even if the resources are publicly resolvable using Local Testing’s --force-local capability. This option resolves all requests (on our remote browsers and devices) through your local machine.

To enable this option, use one of the two ways to establish the Local Testing connection:

Add the following snippet to your test scripts to set the forceLocal to true:

HashMap<String, String> bsLocalArgs = new HashMap<String, String>();
bsLocalArgs.put("forcelocal", "true");
var bs_local_args = { 'forceLocal': 'true' };
List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() {
  new KeyValuePair<string, string>("forcelocal", "true")
};
$bs_local_args = array("key" => "<browserstack-accesskey>", "forcelocal" => true);
bs_local_args = { "forcelocal": "true" }
bs_local_args = {"forcelocal" => "true"}

Use the --force-local flag while establishing a Local Testing connection.

./BrowserStackLocal --key YOUR_ACCESS_KEY --force-local
BrowserStackLocal.exe --key YOUR_ACCESS_KEY --force-local

After establishing the Local Testing connection, use your test scripts to access and interact with your internally-hosted website (for example, staging.example.com). Remember to set local capability to true in your test scripts.

Bypass invalid certificate warning while testing on local HTTPS websites

You can test local websites with SSL certificates on our remote browsers and devices through Local Testing. When you access local websites that have SSL certificates on the browsers, you might see an “invalid certificate” error:

Invalid Certificate Error Window

To avoid invalid certificate errors while testing on our remote browsers, set the acceptInsecureCerts capability to true in your test scripts.

MutableCapabilities capabilities = new MutableCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("acceptInsecureCerts", "true");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
 	'bstack:options' : {
 		"acceptInsecureCerts" : "true",
 	}
}
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("acceptInsecureCerts", "true");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
$caps = array(
 	'bstack:options' => array(
 		"acceptInsecureCerts" => "true",
 	)
)
desired_cap = {
 	'bstack:options' : {
 		"acceptInsecureCerts": "true",
 	}
}
capabilities = {
 	'bstack:options' => {
 		"acceptInsecureCerts" => "true",
 	}
}

To avoid invalid certificate errors while testing on our remote browsers, set the acceptSslCerts capability to true in your test scripts.

caps.setCapability("acceptSslCerts", "true");
var capabilities = {
  'acceptSslCerts' : 'true'
}
caps.SetCapability("acceptSslCerts", "true");
$caps['acceptSslCerts'] = "true";
caps['acceptSslCerts'] = True
caps['acceptSslCerts'] = 'true'

Now, use your test scripts to access and interact with your local HTTPS websites (for example, https://localhost:3000 or https://staging.example.com). Remember to set local capability to true in your test scripts before you run them.

To resolve the “invalid certificate” error, set networkLogs as true to enable the session network logs.

Connection duration and disconnection

The Local Testing connection is persistent. Your machine and BrowserStack Cloud remain connected unless you explicitly end the connection.

In the following scenarios, ensure that you open and close the connection by following the steps:

Language bindings: Write the code to start the Local binary before accessing websites on your internal servers. Close the connection after test execution is complete.

CI server: Write a script that will establish the Local Testing connection before running a test. Close the connection after test execution is complete.

Binary: Run the Local binary using command-line interface with appropriate flags before triggering your tests. Close the connection after test execution is complete.

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
Download Copy Check Circle