Running arbitrary ADB commands via Appium
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. 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). As of Appium 1.7.2, the-- relaxed-securityflag is uncommitted, so you can now start up Appium like this: 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. What is arg here? It needs to be a JSONifiable object with two keys: 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: To translate this to Appium & # x27; s & quot; mobile: shell & quot; command, we simply strip offadb shellfrom the beginning, and we are left with: 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: Essentially, we construct an Object that in JSON would seem like: We can also retrieve the outcome of the ADB call, for example if we wish to verify that the directory is now indeed empty: 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. 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. 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. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Running arbitrary ADB commands via Appium
AI-Powered Key Takeaways
Execute automated Android app testing on real devices worldwide to progress high-performing Android apps..
Accelerate Appium examination rhythm with the HeadSpin..
appium -- relaxed-securitydriver.executeScript (`` mobile: shell '',adb shield rm -rf /mnt/sdcard/Pictures/ *. *rm -rf /mnt/sdcard/Pictures/ *. *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);{`` dictation '': `` rm '', `` args '': [`` -rf '', `` /mnt/sdcard/Pictures/ *. * '']}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);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 {ListPiali Mazumdar
Running arbitrary ADB commands via Appium
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical usher for advanced users (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence hard-nosed guide for advanced users (Part 4)
Discover how HeadSpin can endue your concern with superior testing capableness







Discover how HeadSpin can empower your business with superior testing capabilities
Discover how HeadSpin can empower your concern with superior testing capableness
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












