官網:https://appium.readthedocs.io/en/latest/en/commands/mobile-command/#android
1、執行ADB shell命令(需要設置服務器標志 --relaxed-security)
*appium桌面版,在高級設置中可勾選

*命令行啟動appium,啟動命令加上--relaxed-security。
appium --relaxed-security
2、相關執行代碼介紹(C#)。
*adb命令切換com.android.adbkeyboard/.AdbIME輸入法,以及對應代碼
adb shell ime set com.android.adbkeyboard/.AdbIME
Dictionary<string, Object> args = new Dictionary<string, object>(); args.Add("command", "ime set"); args.Add("args", "com.android.adbkeyboard/.AdbIME"); args.Add("includeStderr", true); args.Add("timeout", 20000); driver.ExecuteScript("mobile: shell", args );
*adb命令輸入(輸入中文必須安裝ADBKeyboard.apk)
*https://github.com/senzhk/ADBKeyBoard
adb shell am broadcast -a ADB_INPUT_TEXT --es msg '輸入文本內容'
Dictionary<string, Object> args = new Dictionary<string, object>(); args.Add("command", "am broadcast"); args.Add("args", "-a ADB_INPUT_TEXT --es msg '輸入文本內容'"); driver.ExecuteScript("mobile: shell", args );
- command:遠程命令的名稱。也可以是可執行文件的完整路徑
。該參數是必需的。 - args:一個字符串數組,傳遞給shell命令的參數。
- includeStderr:將此參數設置為to
true,以便將stderr輸出與stdout一起包含在返回的結果中。如果啟用,則返回的結果將是包含相應字符串的鍵stdout和stderr鍵的映射,否則它只是一個簡單的字符串。false默認情況下。 - timeout:shell命令超時(以毫秒為單位)。如果命令需要更多時間來完成執行,那么將拋出異常。默認為20000毫秒。
