Running arbitrary ADB commands via Appium

February 13, 2026 · 8 min read · Tool Comparison

HeadSpin Platform
Automated & amp; manual examination made easy through data science insights.
Differentiating capableness:
  • Extensive end-to-end automation of QA process
  • Comparative analysis of app performance against peers
  • Continuous monitoring of app performance using semisynthetic data for higher availability of apps
  • Easy-to-use developer friendly program
cloudtest go
Affordable Real Device Testing for Emerging Teams
cloudtest go
Affordable Real Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized mobile trial executing in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based examination

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Running arbitrary ADB commands via AppiumRunning arbitrary ADB commands via Appium

Running arbitrary ADB commands via Appium

Published on
January 31, 2018
Updated on
Published on
June 19, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

Previously, we discussed. That was all well and full, but thither was a bit of clunkiness in how we set up the weather for the test. We actually automated the UI in order to remove all the subsist pictures at the beginning of the test. Wouldn & # x27; t it be great if there were a way to do this instantly, as part of exam setup? Luckily, there is!

If you & # x27; re not a big Android person, you might not know aboutADB, the & quot; Android Debug Bridge & quot;. ADB is a powerful tool provided as portion of the Android SDK by Google, that allows running all kind of interesting commands on a connected emulator or device. One of these commands isadb shell, which gives you blast access to the twist filesystem (include root access on emulators or rooted device). adb shellis the perfect puppet for solving the problem above, because with it we can run therm command to remove any existing image from the SD card prior to our test.

Execute automated Android app testing on real devices worldwide to progress high-performing Android apps..

For a long time, Appium did not allow run of arbitrary ADB dictation. This is because Appium was designed to run in a remote environment, possibly partake an OS with other services or Appium servers, and potentially many link Android devices. It would be a immense protection hole to afford any Appium node the full power of ADB in this circumstance. Recently, the Appium squad decided to unlock this functionality behind a special waiter flag, so that someone running an Appium host could intentionally open up this protection hole (in situations where they know they & # x27; re the only one using the server, for example).

Accelerate Appium examination rhythm with the HeadSpin..

As of Appium 1.7.2, the-- relaxed-securityflag is uncommitted, so you can now start up Appium like this:

appium -- relaxed-security

With Appium lead in this style, you get admittance to a new & quot; mobile: & quot; command phone & quot; mobile: shell & quot;. The Appium & quot; mobile: & quot; dictation are special commands that can be accessed usingexecuteScript(at least until client libraries make a nicer interface for taking advantage of them). Here & # x27; s how a call to & quot; mobile: shell & quot; looks in Java:

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

driver.executeScript (`` mobile: shell '',);

What is arg here? It needs to be a JSONifiable object with two keys:

  1. command: a String, the command to be run underadb shell
  2. args: an raiment of Strings, the statement passed to the shell bidding.

For the purposes of our example, let & # x27; s say we want to unclutter out the icon on the SD card, and that on our gimmick, these are located at/mnt/sdcard/Pictures. If we were pass ADB on our own without Appium, we & # x27; d achieve our destination by running:

adb shield rm -rf /mnt/sdcard/Pictures/ *. *

To translate this to Appium & # x27; s & quot; mobile: shell & quot; command, we simply strip offadb shellfrom the beginning, and we are left with:

rm -rf /mnt/sdcard/Pictures/ *. *

The first intelligence here is the & quot; command & quot;, and the relief constitute the & quot; args & quot;. So we can construct our object as follows:

List & lt; String & gt; removePicsArgs = Arrays.asList (`` -rf '', `` /mnt/sdcard/Pictures/ *. * ''); Map & lt; String, Object & gt; removePicsCmd = ImmutableMap.of (`` bidding '', `` rm '', `` args '', removePicsArgs); driver.executeScript (`` mobile: carapace '', removePicsCmd);

Essentially, we construct an Object that in JSON would seem like:

{`` dictation '': `` rm '', `` args '': [`` -rf '', `` /mnt/sdcard/Pictures/ *. * '']}

We can also retrieve the outcome of the ADB call, for example if we wish to verify that the directory is now indeed empty:

List & lt; String & gt; lsArgs = Arrays.asList (`` /mnt/sdcard/Pictures/ *. * ''); Map & lt; String, Object & gt; lsCmd = ImmutableMap.of (`` bidding '', `` ls '', `` args '', lsArgs); String lsOutput = (String) driver.executeScript (`` mobile: shell '', lsCmd);

The yield of our dictation is returned to us as a String which we can do whatever we want with, include making assertion on it. Putting it all together now, here & # x27; s a entire test that uses Appium to combine the two actions above. Of line, it would be most utile in the circumstance of some other actions, like the ones in the former edition.

import com.google.common.collect.ImmutableMap; meaning io.appium.java_client.android.AndroidDriver; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.List; importee java.util.Map; import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.remote.DesiredCapabilities; public category Edition003_Arbitrary_ADB {individual static String ANDROID_PHOTO_PATH = `` /mnt/sdcard/Pictures ''; @ Test public nothingness testArbitraryADBCommands () throws MalformedURLException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` Android ''); capabilities.setCapability (`` deviceName '', `` Android Emulator ''); capabilities.setCapability (`` automationName '', `` UiAutomator2 ''); capabilities.setCapability (`` appPackage '', `` com.google.android.apps.photos ''); capabilities.setCapability (`` appActivity '', `` .home.HomeActivity ''); // Open the app. AndroidDriver driver = new AndroidDriver < > (new URL (`` http: //localhost:4723/wd/hub ''), capabilities); try {ListremovePicsArgs = Arrays.asList (`` -rf '', ANDROID_PHOTO_PATH + `` / *. * ''); MapremovePicsCmd = ImmutableMap .of (`` command '', `` rm '', `` args '', removePicsArgs); driver.executeScript (`` mobile: shell '', removePicsCmd); ListlsArgs = Arrays.asList (`` /mnt/sdcard ''); MaplsCmd = ImmutableMap.of (`` command '', `` ls '', `` args '', lsArgs); String lsOutput = (String) driver.executeScript (`` mobile: shield '', lsCmd); Assert.assertEquals (`` '', lsOutput);} last {driver.quit ();}}}

In this edition we & # x27; ve explore the power of ADB through a few simple filesystem commands. You can actually do many more useful things than delete file with ADB, so go out thither and have fun with it. Let me know if you come up with any ingenious uses! As always, you can check out the codification in the context of all its dependenceon GitHub.

Also, if you ’ re using a cloud service like HeadSpin, talking to your account manager to see whether this characteristic can be enabled for your devices.

Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in craft engaging narrative and marketing collateral across divers manufacture. She excels in collaborating with cross-functional teams to develop innovative content strategies and render compelling, authentic, and impactful content that resonates with target audiences and enhances marque authenticity.

LinkedIn

Running arbitrary ADB commands via Appium

4 Parts

regression intelligence blog
-

Regression Intelligence practical usher for advanced users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence hard-nosed guide for advanced users (Part 4)

Coming Soon

Discover how HeadSpin can endue your concern with superior testing capableness

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a militant edge
faster development cycles
Boost developer/QA productivity with quicker growing cycles
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent results
gain better visibility into functional & performance issues
Gain better visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate sound, picture, and content quality of experience (QoE) effortlessly
The sure option for globular enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitory edge
faster development cycles
Boost developer/QA productivity with quicker development cycles
automated buil-over-build regression testing
Automate build-over-build fixation test for coherent results
gain better visibility into functional & performance issues
Gain best visibility into functional and execution issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted choice for global go-ahead
Close

Discover how HeadSpin can empower your concern with superior testing capableness

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with faster development round
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent results
gain better visibility into functional & performance issues
Gain best visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during tryout, QA, and product
evaluate audio, video & qoe
Evaluate audio, video, and contented quality of experience (QoE) effortlessly
The trusted choice for global enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free