Skip to main content

Run your Detox Tests for Android on Browserstack (Beta)

Detox is a Gray box end-to-end testing and automation framework for React Native apps.

BrowserStack App Automate supports Detox testing on a wide range of real Android devices.

This guide will help you run your first Detox test on BrowserStack(Only for Android).

In this guide, you’ll learn how to:

  1. Setup BrowserStack account
  2. Install the Patched Version of Detox
  3. Upload your Android App
  4. Upload your App Client
  5. Modify Detox Config
  6. Run Android Detox tests
  7. View Test Results

Please Note:

  • Detox itself only supports Real Devices testing with Android.
  • Only the Jest runner is supported for Detox on Browserstack.
  • This is in Public Beta and we will move out of Beta pretty soon.

Setup BrowserStack account

You will need a BrowserStack username and access key. To obtain your access credentials, sign up for a free trial or purchase a plan.

Install the Patched Version of Detox

You would need to install the patched version of Detox in order to run it on Browserstack.

This is necessary as we had to modify Detox to make it work with our real device public cloud. We have made these changes in the patched version of Detox that we have hosted here.

Here is a sample script that takes you through the steps of installing and linking the patched version of Detox.


#! /bin/sh

BASE_PATH=$(pwd)

# install packages to support detox tests
echo "[DETOX_SETUP_LOG] installing packages"
npm install

# clone and install patched detox
git clone -b implement_cloud_driver https://github.com/pb2323/cloud_detox_support.git
DETOX_BIN=$(pwd)/cloud_detox_support/detox
cd $DETOX_BIN
echo "[DETOX_SETUP_LOG] setting up browserstack-detox installing packages for it"
npm install

# # link native detox to patched detox
cd $BASE_PATH/node_modules
echo "[DETOX_SETUP_LOG] Link native detox"
mv detox/ ./detoxback
ln -s $DETOX_BIN ./detox
cd $BASE_PATH

Upload your Android App

You can Upload your Android app (.apk or .aab file) to BrowserStack servers using the REST API request.

The following sample cURL command shows how to upload an app:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/detox/v2/android/app" \
-F "file=@/path/to/app/file/Application-release.apk"

A sample response for the request is as follows:


{
    "app_name":"Application-release.apk",
    "app_url":"bs://56ec4bf5fb368a671f59fb4df85379db2f7b3a1c",
    "app_version":"1.0",
    "app_id":"56ec4bf5fb368a671f59fb4df85379db2f7b3a1c",
    "uploaded_at":"2023-04-12 07:27:54 UTC",
    "expiry":"2023-05-11 07:27:54 UTC"
}

The value of the app_url parameter in the response is used to specify the application under test when you run Detox tests.

Note: 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.

Upload your App Client

The App Client is the automatically generated test suite apk, this is similar to the test suite apk generated for Espresso tests. This would be present in the same directory where you have built your app. You can Upload your App Client(.apk or .aab file) to BrowserStack servers using the REST API request.

The following sample cURL command shows how to upload an app client:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/detox/v2/android/app-client" \
-F "file=@/path/to/app/file/DetoxAppClient.apk"

A sample response for the request is as follows:

{
    "app_client_name":"DetoxAppClient.apk",
    "app_client_url":"bs://fd71879ddbbb08e0edb4fd4f52d2c79ec342eaad",
    "app_client_id":"fd71879ddbbb08e0edb4fd4f52d2c79ec342eaad",
    "uploaded_at":"2023-04-17 00:41:42 UTC",
    "expiry":"2023-05-17 00:41:42 UTC"
}

The value of the app_client_url parameter in the response is used to specify the appClient when you run Detox tests.

Modify Detox Config

After you upload your app and appClient to BrowserStack servers, you need to modify your detox config to point towards Browserstack with some additional params.

A sample config for running tests on Browserstack is as follows:


{
  "test-runner": "jest",
  "runner-config": "e2e/jest.config.js",
  "specs": "e2e",
  "apps": {
    "android.cloud.release":{
      "type": "android.cloud",
      "app":"app_url from the previous steps",
      "appClient":"app_client_url from the previous steps"
    }
  },
  "devices": {
    "cloud":{
      "type":"android.cloud",
      "device":{
        "name":"OnePlus 8",
        "osVersion": "10.0"
      }
    }
  },
  "configurations": {
    "android.cloud.release": {
      "device":"cloud",
      "app": "android.cloud.release",
      "cloudAuthentication":{
        "username":"userName from your Browserstack Account",
        "accessKey":"accessKey from your Browserstack Account",
        "extra": true
      },
      "session":{
        "server":"ws://detox.browserstack.com/init",
        "name": "example-session-name",
        "build": "example-build-name"
      }
    }
  }
}

Please refer to this for a full list of Android Devices that we support.

Run Android Detox tests

You can run your detox tests by specifying the Browserstack relevant configuration.

detox test -c android.cloud.release

View test results

After you start Detox tests, visit your App Automate dashboard to view your test results, debugging logs, and overall test details.

Alternatively, you can use the REST API to obtain logs. You would need the session ID for this , which would be available in the Detox logs given out by your CLI it would also be visible in your Dashboard.

The following sample cURL command shows how obtain logs via the API for a Detox session.:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/detox/v2/android/sessions/<session-id>" \

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