Using adb commands

adb (Android debug bridge) is a command-line tool that lets you communicate with Android devices. The adb command facilitates a variety of device actions, such as installing apps, granting permissions, copying files, profiling for performance etc. Learn how to achieve equivalent functionality on BrowserStack without having to use adb.

Managing applications

Install packages

ADB command: adb install [options] package_name

How to achieve this functionality on BrowserStack:

First, you must upload your apps on BrowserStack and obtain the app_url. Refer to Upload your app section to see how this can be done.

Second, mention the app_url of the uploaded app you want to install in the app capability inside the Desired capabilities object while running a new Appium test session on BrowserStack. The app you want to test will be your main app, and the apps your main app depends on need to be specified in the otherApps capability. For more info, refere to Appium capability builder

Uninstall packages

ADB command: adb uninstall package

How to achieve this functionality on BrowserStack:

You don’t have to explicitly uninstall an app after you’re done with your tests. We automatically uninstall your apps, delete the data that was added/modified during your tests and clean up the device before running another test session on that device.

If you want to uninstall the package, and reinstall it during the same session, we recommend you to reset the app instead.

Reset the app or clear package data

ADB command: adb shell pm clear package

How to achieve this functionality on BrowserStack:

You can use Appium’s reset package functionality to clear all the data associated with the app.

File Transfers

Copy a file or directory and its sub-directories to the device

ADB command: adb push local remote

How to achieve this functionality on BrowserStack:

By default, BrowserStack provides a set of images & videos you can use to test whether file uploads work fine in your app. But, if you choose to use your own images & videos, you can upload your custom media and use them in your tests.

First, upload your custom media to BrowserStack and obtain the media’s media_url(media://…….). Refer to the upload media section to see how this can be done.

Second, mention the media_url of the media you want to access in the browserstack.uploadMedia capability inside the Desired capabilities object while running a new Appium test session with BrowserStack. These media_url’s should be mentioned as an array in the browserstack.uploadMedia capability.

You can also use Appium’s push file functionality, but you can only copy files into the /data/local/tmp folder, and can retrieve the file from that location using Appium’s pull file functionality.

Retrieve a file or directory and its sub-directories from the device

ADB command: adb pull remote local

How to achieve this functionality on BrowserStack:

If you want to take a screenshot, store it locally on the device, and retrieve it using pull command, you can use Appium’s screenshot functionality to get the screenshot in base64 or PNG format that you can write to a file locally on your machine.

You can also use BrowserStack’s Screenshots functionality to generate screenshots. Just pass the browserstack.debug capability in your Appium script’s desired capability object, and BrowserStack will automatically generate screenshots at various steps in your test so that you can consume them or debug using them later.

You can also use Appium’s pull file functionality, but you can only retrieve files from the /data/local/tmp folder. You can also copy files to the same location using Appium’s push file functionality.

Granting Permissions to Apps

Grant a permission to an app

ADB command: adb shell pm grant package_name permission

How to achieve this functionality on BrowserStack:

You can auto-grant permissions passing the autoGrantPermissions capability while starting the test.

You can also handle with the permission alerts, and click the allow button during the test.

Revoke a permission from an app

ADB command: adb shell pm revoke package_name permission

How to achieve this functionality on BrowserStack:

You cannot do this on BrowserStack at the moment.

If you need to perform your tests with limited permissions, we recommend you to run a new test session and allow / disallow the required permissions during the test by handling the permission alerts.

Debugging Options

ADB command: adb logcat [options]

How to achieve this functionality on BrowserStack:

You can access these logs in the Device Logs section of the test session page in your App Automate dashboard.

You can also retrieve these logs via the AppiumREST API.

Working with Android Activity & Animations

Start an Activity specified by intent

ADB command: adb shell am start [options] intent

How to achieve this functionality on BrowserStack:

You can use Appium’s start activity functionality to start an Android activity by providing package name and activity name.

Force stop everything associated with package

ADB command: adb shell am force-stop package

How to achieve this functionality on BrowserStack:

You can use Appium’s close app functionality to force stop and close your application.

Remember that you can only force stop your main application (specified by the app capability ), but not the applications your main application depends on (the ones specified in otherApps capability).

Disable system animations to speed up your tests and improve stability

ADB command: adb shell am instrument --no-window-animation [options]

How to achieve this functionality on BrowserStack:

You can now use Appium’s capability disableWindowAnimation to disable system’s window animations.

Remember that you need to also set the browserstack.appium_version capability to 1.9.1 or later because this capability is not available in the older versions of Appium.

Screen Capture & Recording

Capture a screenshot and save it to file

ADB command: adb shell screencap filename

How to achieve this functionality on BrowserStack:

You use BrowserStack’s Screenshots functionality to generate screenshots. Just pass the browserstack.debug capability in your tests’ desired capabilities, and BrowserStack will automatically generate screenshots at various steps in your test so that you can consume them or debug using them later.

You can use Appium’s screenshot functionality to get the screenshot in base64 or PNG format that you can write to a file locally on your machine.

Record display of devices

ADB command: adb shell screenrecord [options] filename

How to achieve this functionality on BrowserStack:

You can use browserstack.video capability in your tests’ desired capabilities if you want to enable video recording during your test.

App Profiling

Understand battery consumption, memory, CPU utilization & network performance

ADB command: adb dumpsys [options]

How to achieve this functionality on BrowserStack:

You can get this information from your App Automate dashboard on the test session page.

Note: App profiling is only available for Android.