Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy

Integrate BrowserStack App Automate with CircleCI

Integrate your Appium test suite with CircleCI and BrowserStack device cloud for native and hybrid apps.


CircleCI uses .circleci/config.yml for configuration, and it can be used to integrate your tests with BrowserStack. There are some variables you need to set: grid config, username, access key, etc. For more detailed information on setting environment variables in CircleCI, please refer to their documentation.

Integrate with App Automate

Here we are providing sample configuration for CircleCI’s config file, by which you can build your app, upload it to app automate and run tests on it. Add the following to “steps” in CircleCI’s config.

Generate apk

- run: ./gradlew assembleDebug

Upload app to BrowserStack

# Upload app to BrowserStack and set app url in an environment variable.
# Here replace app-debug.apk with name of your apk.
- run:
    name : App upload and Set app id in environment variable.
    command : |
      APP_UPLOAD_RESPONSE=$(curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -X POST -F "file=@app/build/outputs/apk/debug/app-debug.apk")
      APP_ID=$(echo $APP_UPLOAD_RESPONSE | jq -r ".app_url")
      if [ $APP_ID != null ]; then
        echo "Apk uploaded to BrowserStack with app id : ",$APP_ID;
        echo "export BROWSERSTACK_APP_ID=$APP_ID" >> $BASH_ENV;
        source $BASH_ENV;
        echo "Setting value of BROWSERSTACK_APP_ID in environment variables to  ",$APP_ID;
        UPLOAD_ERROR_MESSAGE=$(echo $APP_UPLOAD_RESPONSE | jq -r ".error")
        echo "App upload failed, reason : ",$UPLOAD_ERROR_MESSAGE
        exit 1;

Run tests

- run: ./gradlew test

Similarly, one can build an ios app, upload it and then run tests on it.

Here if app upload is successful then app id of that app will be stored in an environment variable “BROWSERSTACK_APP_ID” and it can be accessed in your tests in the following way:

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("device", "Samsung Galaxy S8");
    caps.setCapability("app", app);
    caps.setCapability("build", "MyBuild");

driver = new AndroidDriver(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,
    "app" : app,
    "device" : "Samsung Galaxy S8",
    "build" : "MyBuild"

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("device", "Samsung Galaxy S8");
caps.SetCapability("app", app);
caps.SetCapability("build", "MySampleBuild");

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

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

$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': app,
 'build': 'MyBuild'

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

desired_caps = {
    'device':  'Samsung Galaxy S8',
    'app':  app,
    'build': 'MyBuild'

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

Running Local Tests

If you are testing in your development or staging environment, you can configure CircleCI to automatically download the latest version of the BrowserStack Local binary and instantiate the binary before your test starts. In addition to the code below, you will also have to enable local in your test script by setting the capability:

Capability Description Value
browserstack.local Test against internal/local servers true/false
Default Value: false

Add the following run step in your config file:

- run:
    name : Download BrowserStack Local binary and start it.
    command : |
      # Download the browserstack binary file
      wget ""
      # Unzip it
      # Run the file with user's access key
      ./BrowserStackLocal YOUR_ACCESS_KEY

For the complete working example of how to configure Circle CI, check out the .circleci/config.yml file in our repository.

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?


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