Test Your Apps Locally With BrowserStack
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:
-
Via adding dependency (language bindings): The BrowserStackLocal binary is installed by adding it as a dependency in the
pom.xml
file. 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. Using language bindings is the recommended way to integrate localhost testing on BrowserStack. - 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
Install the BrowserStackLocal
language bindings by adding it as a dependency in the pom.xml
file.
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 |
---|---|
local.start(options) |
Expects options object. Returns a callback when the tunnel has started successfully. Your test script should start executing after this callback has been invoked. |
local.stop() |
Call this method after your test suite is complete. |
local.isRunning() |
Check if the BrowserStack local instance is running. |
Add desired capabilities to enable local
Update your TestNG test (local.conf.json
) 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
.
"bstack:options": {
// Set the local capability as true
"local" : true
}
"capabilities": {
// Set the 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.
In your terminal/command-line, navigate to either android
or the ios
diectory and run the adjacent command.
Download BrowserStack Local
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
Copy the capabilities from the following window into your test file.
"bstack:options": {
// Set the local capability as true
"local" : true
}
{
// Set the 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.
Run your first local test
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 testng-browserstack repository and install required dependencies using the following commands:
Set BrowserStack credentials
Set userName
and accessKey
in the local.conf.json
config file. Skip this step if you have already set credentials as environment variables.
Set local capability to true
Verify that the local
capability in the local.conf.json
file is set to true
.
Execute build on BrowserStack
From the root directory of this project, run the following command:
View the test result on your App Automate Dashboard.
Next Steps
After you have successfully run your first test using BrowserStack Local, you can explore the following sections:
- Testing your local site that might be behind a proxy
- Local flags to customize your local testing setup
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!