Skip to main content
Start running your tests on the latest iOS minor versions on BrowserStack App Automate. Check out our documentation!

Local Testing with App Automate

Local Testing is a BrowserStack feature that helps you test mobile apps that access resources hosted in development or testing environments during automated test execution.

In this guide, you will learn:

Prerequisites

You need to have 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.

Configure BrowserStack Local

You can setup localhost testing using the following two ways:

  • Recommended: Via PIP (language bindings): The BrowserStack Local binary is installed using the pip command. It internally establishes a secure tunnel with BrowserStack when you run your test case. The package provides hooks that let you control the lifecycle of the tunnel.
  • Via CLI Interface (binary): You can also download the BrowserStack Local binary and setup the tunnel via your terminal. This method is useful when you don’t want to make any code changes in your test suite and want to manage the tunnel lifecycle independently.

Install the package

Add browserstack-local to your project using the pip command.

Set the access key and use available methods in your test script

Set your access key that is used to create the secure tunnel. Use the following methods provided by the local library to manage your local connection:

Method Description
bs_local.start(**bs_local_args) Expects **bs_local_args object. Returns a callback when the tunnel has started successfully. Your test script should start executing after this callback has been invoked.
bs_local.stop() Call this method after your test suite is complete.
browserstack_sample_local.py

Add desired capabilities to enable local

Update your Python test (browserstack_sample_local.py) file to set the local capability to true. You may face errors running your test script if any other capability is enabled before setting up local.

desired_cap = {
    "bstack:options": {
        #Set the local capability as true
        "local" : "true"
    }
}
desired_caps = {
    #Set BrowserStack Local capability as True
    "browserstack.local": "true"
}

If your staging environment is behind a proxy or firewall, additional arguments, such as proxy username, proxy password, etc, need to be set. Check out Local Binary parameters to learn about additional arguments.

Execute build on BrowserStack

You are now ready to execute your build on BrowserStack. On your local machine, open the terminal/command prompt. Navigate to either the android or ios directory and run the test script.

Download BrowserStack Local

Show download options

Unzip the binary

Unzip the downloaded file and move it to a folder/directory from which you have permission to start it using your command line or terminal.

Run the binary using your command line or terminal

Run the following command to initiate the BrowserStack Local connection:

If your staging environment is behind a proxy or firewall, additional arguments, such as proxy username, proxy password, etc, need to be set. Check out Local Binary parameters to learn about additional arguments.

# Step 3 - Run this command in your terminal to start the BrowserStack Local binary. Your working directory should be where you have the downloaded binary.
./BrowserStackLocal --key YOUR_ACCESS_KEY
# Step 3 - Run this command in your command prompt. Your working directory should be where you have unzipped BrowserStackLocal.exe
BrowserStackLocal.exe --key YOUR_ACCESS_KEY

Set up config to enable local

Update your Python test file to set the local capability to true. You may face errors running your test script if any other capability is enabled before setting up local.

desired_cap = {
    "bstack:options": {
        #Set the local capability as true
        "local" : "true"
    }
}
desired_caps = {
    #Set BrowserStack Local capability as True
    "browserstack.local": "true"
}

Execute build on BrowserStack

You are now ready to execute your build on BrowserStack. On your local machine, open the terminal/command prompt. Navigate to either the android or ios directory and run the test script.

Check BrowserStack Local connectivity

Run a sample test to check if BrowserStack Local is working as expected and can connect to BrowserStack servers.

Clone sample Git repository

Clone the sample python-browserstack repository and install required dependencies using the following commands:

Copy icon Copy snippet

Set BrowserStack credentials

Set userName and accessKey in the browserstack_sample_local.py config file. Skip this step if you have already set credentials as environment variables.

browserstack_sample_local.py
Copy icon Copy snippet

Set local capability to true

Verify that the local capability in the browserstack_sample_local.py file is set to true.

browserstack_sample_local.py
Copy icon Copy snippet

Execute build on BrowserStack

From the root directory of this project, run the following command:

Copy icon Copy snippet

View the test result on your App Automate Dashboard.

If the test fails, refer to the sections below for additional configuration that may be needed.

Additional configuration

BrowserStack Local works out of the box in most cases. However, depending on the URL from where your app fetches data, and your network setup, some additional configuration may be required. The following are the most frequently occurring scenarios:

The URL where app’s data resides is accessible from the internet but serves different content within your internal network.

This is common with staging environments set up as sub-domains and configured to work only in your private/VPN network. In this case, add the following entry in your browserstack_sample_local.py file.

browserstack_sample_local.py
Copy icon Copy snippet

The forceLocal capability will resolve all network traffic through the BrowserStack Local tunnel.

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