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. This page will guide you through enabling Local Testing for App Automate sessions, and then using it to test apps that retrieve data from servers on your local machine, CI/CD machines or nodes, and other private network configurations. In this guide you will learn how to :
- Setup your environment
- Upload your app
- Configure and run your Local test
- View test execution results
1. Setup your environment
- You will need a BrowserStack
username
andaccess_key
. If you haven’t created an account yet, sign up for a free trial or purchase a paid plan. After signup, you can obtain your access credentials from account settings - Ensure you have Ruby installed on your system. You can download updated Ruby versions from ruby-lang.org
- Ensure you have
Bundler
installed on your system. To installBundler
, follow steps outlined in the bundler installation guide - You will need access to your Android app (
.apk
or.aab
file) or iOS app (.ipa
file)
.apk
or .ipa
file and are looking to simply try App Automate Local Testing, you can download and test using our sample Android Local app or sample iOS Local app.
2. Upload your app
Upload your Android app (.apk
or .aab
file) or iOS app (.ipa
file) to BrowserStack servers using our REST API. Here is an example cURL
request to upload app on App Automate :
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/apk/file"
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" ^
-X POST "https://api-cloud.browserstack.com/app-automate/upload" ^
-F "file=@/path/to/apk/file"
Ensure that @
symbol is prepended to the file path in the above request. A sample response for the above request is shown below:
{
"app_url" : "bs://j3c874f21852ba57957a3fdc33f47514288c4ba4"
}
Please note the app_url
value returned in the API response (bs://j3c874.....
in the above example). We will use this value to set the application under test while configuring the test later on.
- App upload will take a few seconds to about a minute depending on the size of your app. Do not interrupt the
cURL
command until you get the response back. - If you upload an iOS app, we will re-sign the app with our own provisioning profile to be able to install your app on our devices during test execution.
3. Configure and run your Local test
Setup your project
Clone the Cucumber sample integration code from our GitHub repository.
git clone https://github.com/browserstack/cucumber-ruby-appium-app-browserstack.git
Next, execute the following commands in project’s base directory to install the required dependencies:
# Test an android app
cd android/examples
bundle install
# Test an iOS app
cd ios/examples
bundle install
This will install requisite dependencies including Appium’s Ruby client :
source 'http://rubygems.org'
gem 'appium_lib'
gem 'cucumber'
gem 'rspec'
gem 'rake'
gem 'browserstack-local'
gem 'parallel_tests'
gem 'selenium-cucumber'
gem 'selenium-webdriver'
Configure Appium’s desired capabilities
Desired capabilities are a series of key-value pairs that allow you to configure your Appium tests on BrowserStack. The following capabilities are required for Local Testing :
-
app
capability : Its used to specify your uploaded app that will be installed on the device during test execution. Use theapp_url
obtained in Upload your App section to set its value. -
device
capability : Its used to specify the BrowserStack device you want to run the test on. -
browserstack.local
capability : Its used to enable BrowserStack Local feature for your test execution.
In the Cucumber sample integration code, Appium’s desired capabilities are defined in the local.config.yml
file located in the examples/run-local-test/config
directory :
server: "hub-cloud.browserstack.com"
common_caps:
"browserstack.user": "YOUR_USERNAME"
"browserstack.key": "YOUR_ACCESS_KEY"
"project": "First Cucumber Android Project"
"build": "Cucumber Android"
"browserstack.debug": true
browser_caps:
-
"device": "Google Pixel 3"
"os_version": "9.0"
"app": "bs://<app-id>"
"browserstack.local": true
"name": "local_test"
server: "hub-cloud.browserstack.com"
common_caps:
"browserstack.user": "YOUR_USERNAME"
"browserstack.key": "YOUR_ACCESS_KEY"
"project": "First Cucumber iOS Project"
"build": "Cucumber iOS"
"browserstack.debug": true
browser_caps:
-
"device": "iPhone 11 Pro"
"os_version": "13"
"app": "bs://<app-id>"
"browserstack.local": true
"name": "local_test"
- You can explore other Appium capabilities using our Capabilities Builder
Establish a Local Testing connection
In addition to using the browserstack.local
capability, you also need to establish a Local Testing connection from your local or CI/CD machine to BrowserStack servers. Within your test scripts, you can add a code snippet that will automatically start and stop Local Testing connection using BrowserStack’s Ruby binding for BrowserStack Local.
In the Cucumber sample integration code, the Local Testing connection is initialised in the env.rb
file located in the examples/run-local-test/features/support
directory as shown below :
require 'browserstack/local'
#...
if caps['browserstack.local'] && caps['browserstack.local'].to_s == 'true'
$bs_local = BrowserStack::Local.new
bs_local_args = { "key" => "#{caps['browserstack.key']}" }
$bs_local.start(bs_local_args)
end
#...
Create remote Webdriver
Once you have configured desired capabilities and established Local Testing connection, you can initialize an Appium webdriver to test remotely on BrowserStack. In order to do so, you need to use a remote BrowserStack URL along with your BrowserStack access credentials.
In the Cucumber sample integration code, the remote Webdriver is initialised in the env.rb
file located in the examples/run-local-test/features/support
directory as shown below :
#...
desired_caps = {
caps: caps,
appium_lib: {
server_url: "https://hub-cloud.browserstack.com/wd/hub"
}
}
begin
$appium_driver = Appium::Driver.new(desired_caps, true)
$driver = $appium_driver.start_driver
rescue Exception => e
puts e.message
Process.exit(0)
end
#...
Setup your test-case
This step will help you setup your first test case with Cucumber framework. In the Cucumber sample integration code, we have provided a sample test-case in examples/run-local-test/features
directory for BrowserStack’s sample apps. If you are testing your own app, please modify the test case accordingly.
If you are using your own app, modify the following code as per your test case:
Feature: BrowserStack Local Testing
Background:
Given I start test on the Local Sample App
Scenario: Can check tunnel working
Then I should see "Up and running"
If you are using your own app, modify the following code as per your test case:
Feature: BrowserStack Local Testing
Background:
Given I start test on the Local Sample App
Scenario: Can check tunnel working
Then I should see "Up and running"
Run the test
You are ready to run your first Cucumber test on BrowserStack. In the Cucumber sample integration code, switch to examples/
directory, and run the test using command :
# Run using Rake
bundle exec rake local
4. View test execution results
You can access the test execution results, and debugging information such as video recording, network and device logs on App Automate dashboard or using our REST APIs.
What’s next
Congratulations! You just ran your first local test on App Automate. Next, you can learn to :
- Run tests in parallel - Speed up test execution by running tests simultaneously across multiple BrowserStack devices
Need some help?
If you have any queries, please get in touch with us.
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!