Run ADB commands over Appium Server

Are you still relying on underlying command executor of programming language to execute ADB shell commands? I have extensively used ProcessBuilder in Java code and subprocess with Python to execute the ADB commands as shell commands. Thankfully Ruby didn’t need any sorcery to execute shell commands. This is how I execute the shell command from ruby code

sh "adb -s <devive_id> <android_shell_command>"

However, you can skip all of that, because Appium has already added the feature to executed shell commands from appium server. The feature of executing ADB commands in appium is available since appium server version 1.7.2.

Steps for how to execute ADB shell commands over Appium.

  1. Start Appium server with relaxed-security flag ie. appium --relaxed-security
  2. Create the driver instance as usual.
  3. Execute the shell command as below

driver.execute_script('mobile: shell', {'command': 'input text', 'args':'hello'})

The code sample is in python, but you can modify it for the language binding you are using.
Be aware that if you don’t follow the step 1 you will get below error

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Appium server must have relaxed security flag set in order to run any shell commands

Here’s the screengrab of the steps mentioned above

Sending ADB commands Appium Server

This is far easier and it should even work for the devices connected over Grid setup or any of the cloud infrastructure providers.


Run ADB commands over Appium Server
https://automationlog.in/Executing-ADB-command-over-Appium-Server.html
Author
Prabhash Singh
Posted on
July 22, 2018
Licensed under