Manage connections from local servers for Espresso tests
Manage incoming connections from private or localhost servers for testing apps using Espresso on BrowserStack App Automate.
This guide covers managing incoming connections from localhost servers and private servers for Espresso tests.
Test apps that retrieve data from localhost servers
After you enable Local Testing, your remote devices can access apps that retrieve data from your localhost servers. Use your test scripts to access and interact with your apps. Remember to use the local parameter when executing the test:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"devices": ["Google Pixel 7-13.0"], "local": "true", "app": "bs://f5L3azt9pLzE995f49376eb1fa3c284dc321f8d", "testSuite": "bs://6eb1fa3c284ddbe9971b2d1aee0d52943b9c081"}' \
-H "Content-Type: application/json"
Test apps that retrieve data from private or internal servers
You can securely test mobile apps that retrieve data from private or internal servers using --force-local on your remote mobile devices. This option routes all requests from your remote devices through your local machine.
To enable this option, use one of two ways to establish the Local Testing connection:
Via command-line interface:
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
Via language bindings:
Set the forcelocal parameter to true in your Local Testing arguments before starting your test script.
bsLocalArgs.Add(new KeyValuePair<string, string>("key", "<browserstack-accesskey>"));
bsLocalArgs.Add(new KeyValuePair<string, string>("forcelocal", "true"));
bsLocalArgs.put("key", "<browserstack-accesskey>");
bsLocalArgs.put("forcelocal", "true");
bs_local_args = { 'key': '<browserstack-accesskey>', 'forcelocal': 'true' }
my %bs_local_args = ("key" => "<browserstack-accesskey>", "forcelocal" => "true");
$bs_local_args = array("key" => "<browserstack-accesskey>", "forcelocal" => true);
bs_local_args = { "key": "<browserstack-accesskey>" , "forcelocal": "true"}
bs_local_args = { "key" => "<browserstack-accesskey>" , "forcelocal" => "true"}
After establishing the Local Testing connection, use your test scripts to access and interact with your internally-hosted website, for example, staging.example.com.
Test apps that retrieve data from servers behind a firewall and/or VPNs
With Local Testing, you can test apps that retrieve data/assets from internal servers that are behind firewalls and/or VPNs.
Start by making sure that you can access the app on your machine. Then, set up a Local Testing connection by following the steps listed in Test apps that retrieve data from private or internal servers.
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:
| Steps | Details |
|---|---|
| Language bindings | Write the code to start the local binary before accessing mobile apps that retrieve content from your local or staging servers. Close the connection after the test execution is complete. |
| CI server | Write a script that will establish the Local Testing connection before running a test. Close the connection after the test execution is complete. |
| Binary | Run the Local binary using a command-line interface with appropriate flags before triggering your tests. Close the connection after the 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
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!