Integrate BrowserStack App Automate with Travis CI

Use our Travis CI add-on to integrate BrowserStack with ease and test your native or hybrid apps on BrowserStack real device cloud.


Travis CI is a hosted, distributed continuous integration service used to build and test software projects.


This add-on automatically sets up BrowserStack Local Testing which allows you to test your private servers, alongside public URLs, using the BrowserStack cloud. To do this it uses the BrowserStackLocal binary for your build platform.

BrowserStack Local Testing establishes a secure connection between your Travis build container / VM and BrowserStack servers. Local Testing also has support for firewalls, proxies and Active Directory. Once the secure connection is set up, all URLs work out of the box, including your web server, local folders, as well as URLs with HTTPS.

Setting up BrowserStack

Please sign up for a BrowserStack account if you haven’t already; it’s free for open-source projects. Once you have signed up get your Username and Access Key from the account settings page. Your Username and Access Key are required to configure the .travis.yml file of your project.

Choose whether you want to store your Access Key as plain text or in a secure/encrypted form. For open-source projects we recommend storing the Access Key in a secure form so that pull requests cannot use the keys stored in your .travis.yml. For more information see the pull requests page.

Encrypted Access Key

To encrypt your Access Key for use in .travis.yml you can use:

travis encrypt <your_browserstack_access_key>

Note: You need to have the Travis CLI installed to be able to do this (see Encryption Keys for more details). Once your Access Key is encrypted, you can add the secure string to your .travis.yml file as shown below.

    username: "Your BrowserStack Username"
      secure: "The secure string output of travis encrypt"

Plain Text Access Key

To store your Access Key in plain text format, add the following configuration to your .travis.yml file:

    username: "Your BrowserStack Username"
    access_key: "Your BrowserStack Access Key"

Note: We strongly recommend storing your BrowserStack Access Keys in the encrypted format, since other users that have access to your repository can read and use your plain text Access Keys to test on BrowserStack.

App Upload

Upload your App to the BrowserStack servers after building it. To upload the app, configure the path to your app in the .travis.yml file:

  - "build script"

  - "test script"

    username: "Your BrowserStack Username"
    access_key: "Your BrowserStack Access Key"
    app_path: "path to the app file"

Once the app is uploaded to the BrowserStack servers the resulting app id will be set in the environment variable BROWSERSTACK_APP_ID. You can use it to set the Appium capability in your test.

String userName = System.getenv("BROWSERSTACK_USERNAME");
String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
String app = System.getenv("BROWSERSTACK_APP_ID");

public static void main(String args[]) throws MalformedURLException, InterruptedException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("app", app);
    caps.setCapability("device", "Samsung Galaxy S8");
    caps.setCapability("build", "MyBuild");

driver = new AndroidDriver<AndroidElement>(new URL("https://"+userName+":"+accessKey+""), caps);
userName = process.env.BROWSERSTACK_USERNAME
accessKey = process.env.BROWSERSTACK_ACCESS_KEY
app = process.env.BROWSERSTACK_APP_ID

var capabilities = {
    "browserstack.user" : userName,
    "browserstack.key" : accessKey,
    "device" : "Samsung Galaxy S8",
    "app" : app,
    "build" : "SampleBuild"

driver = wd.promiseRemote("");

  //Write your code here
  .fin(function() { return driver.quit(); })
userName = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
accessKey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
app = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_ID");

DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("browserstack.user", userName);
caps.SetCapability("browserstack.key", accessKey);
caps.SetCapability("app", app);
caps.SetCapability("device", "Samsung Galaxy S8");
caps.SetCapability("build", "SampleBuild");

AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new Uri(""), caps);
$user_name = getenv("BROWSERSTACK_USERNAME");
$access_key = getenv("BROWSERSTACK_ACCESS_KEY");
$app = getenv("BROWSERSTACK_APP_ID");

$capabilities = new DesiredCapabilities();
$capabilities->setCapability("app", $app);
$capabilities->setCapability("device", "Samsung Galaxy S8");
$capabilities->setCapability("build", "SampleBuild");

$driver = RemoteWebDriver::create("https://"+user_name+":"+access_key+"", $capabilities);
user_name = os.getenv("BROWSERSTACK_USERNAME")
access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
app = os.getenv("BROWSERSTACK_APP_ID")

desired_cap = {
 'device': 'Samsung Galaxy S8',
 'app': os.getenv("BROWSERSTACK_APP_ID"),
 'build': 'SampleBuild'

driver = webdriver.Remote("https://" + user_name + ":" + access_key + "", desired_cap)

desired_caps = {
	'device': 'Samsung Galaxy S8',
    'build': 'SampleBuild'

appium_driver ={
	'caps' => desired_caps,
	'appium_lib' => {
    :server_url => "https://#{user_name}:#{access_key}"
	}}, true)

Local Identifier

A Local Identifier is a unique identifier for each Local connection when multiple Local connections are connected. The add-on will ALWAYS create a Local Identifier for each local connection that is created. If you are using the Appium testing framework, the Local Identifier must be added to the Appium capabilities.

The Local Identifier is exposed as an environment variable BROWSERSTACK_LOCAL_IDENTIFIER. You can use it to set the Appium capability. See the following example which uses Ruby’s appium_lib:

desired_caps = {
	'browserstack.local': 'true',
    'browserstack.localIdentifier': ENV['BROWSERSTACK_LOCAL_IDENTIFIER']
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserstack.local", "true");
caps.setCapability("browserstack.localIdentifier", System.getenv("BROWSERSTACK_LOCAL_IDENTIFIER");
desired_cap = {
 'browserstack.local': 'true',
 'browserstack.localIdentifier': os.getenv("BROWSERSTACK_LOCAL_IDENTIFIER")
var capabilities = {
 "browserstack.local" : "true",
 "browserstack.localIdentifier" : process.env.BROWSERSTACK_LOCAL_IDENTIFIER
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("browserstack.local", "true");
caps.SetCapability("browserstack.localIdentifier", Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER"));
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.local", "true");
$capabilities->setCapability("browserstack.localIdentifier", getenv("BROWSERSTACK_LOCAL_IDENTIFIER"));

Local identifiers are essential for matrix builds. Since matrix builds in Travis can be run on the same VM, we need to add the Local Identifier when starting the connection to ensure that the correct local tunnel gets the right requests.

Additional Options

Proxy Local Testing also allows you to set the proxy host, port, username, and password through which all URLs will be resolved:

    username: "Your BrowserStack Username"
      secure: "The secure string output of `travis encrypt`"
    proxyHost: "Proxy server host"
    proxyPort: "Proxy server port"
    proxyUser: "User to use when accessing proxy server"
    proxyPass: "Password to use when accessing proxy server"

More Options

Some other options that are supported by the add on -

  • forcelocal: If this is set to true then all URLs will be resolved via the Travis container that your build is running in.
  • only: restricts Local Testing access to the specified local servers and/or folders.

Sample usage:

    username: "Your BrowserStack Username"
      secure: "The secure string output of `travis encrypt`"
    forcelocal: true

The format for the only flag is, “Host pattern”, “Host Port”, “Flag for SSL True(1)/False(0)” and repeat.


Pro Tip: You may also refer to the documentation on Travis

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