C#中appium自動化執行移動命令mobile:shell用法


官網: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 ); 
View Code

   *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 ); 
View Code
  • command:遠程命令的名稱。也可以是可執行文件的完整路徑該參數是必需的。
  • args:一個字符串數組,傳遞給shell命令的參數。
  • includeStderr:將此參數設置為to true,以便將stderr輸出與stdout一起包含在返回的結果中。如果啟用,則返回的結果將是包含相應字符串的鍵stdoutstderr的映射,否則它只是一個簡單的字符串。false默認情況下。
  • timeout:shell命令超時(以毫秒為單位)。如果命令需要更多時間來完成執行,那么將拋出異常。默認為20000毫秒。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM