Appium問題集錦

出處:https://blog.csdn.net/niubitianping/article/details/52624417

問題

1. error: Failed to start an Appium session, err was: Error: Requested a new session but one was in progress

之前的會話沒有關(guān)閉,然后你又運行了測試實例,也沒有設(shè)置覆蓋.

解決:
1. 重新停止appium服務(wù),開啟Appium服務(wù)
2. 在Genarel Setting那里設(shè)置覆蓋Session,重啟Appium

測試結(jié)束在AfterClass加driver.quit()

2. error: Failed to start an Appium session, err was: Error: Command failed: C:\Windows\system32\cmd.exe /s /c “D:\android-sdk-windows\platform-tools\adb.exe -s adb server version (32) doesn’t match this client (36); killing…

wait-for-device”
error: could not install smartsocket listener: cannot bind to 127.0.0.1:5037:

沒有鏈接上手機或者模擬器,請確認已經(jīng)連接成功,重新鏈接

3. error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.

手機系統(tǒng)低于4.2,appium不支持4.2.2以下的系統(tǒng),請換一個手機或者模擬器來測試。

4. Error: Permission to start activity denied.

這里寫圖片描述activity在清單文件里面沒添加android:exported=”true”的話,你不能直接打開對應(yīng)的activity,需要從啟動頁activity打開。 exported屬性就是設(shè)置是否允許activity被其它程序調(diào)用

5. error: Failed to start an Appium session, err was: Error: Activity used to start app doesn’t exist or cannot ve launched! Make usre it exists and is launchable activity

要打開的activity不存在,activity路徑錯誤,改為完整正確的activity路徑

6. error: Failed to start an Appium session, err was: Error: ‘java - version’ failed. Error: Command failed: C:\Windows\system32\cmd.exe /s /c “java -version”

Java版本錯誤,請安裝最新的版本

7.> info: [debug] Error: Command failed: C:\Windows\system32\cmd.exe /s /c “D:\android-sdk-windows\platform-tools\adb.exe -s 8806a0b0 shell “echo ‘ready‘“error: unknown host service

鏈接手機失敗,重新鏈接手機即可,我就是重新拔插了一下usb

Error: Command failed: C:\Windows\system32\cmd.exe /s /c “D:\android-sdk-windows\platform-tools\adb.exe -s 8806a0b0 shell “echo ‘ping’”“

error: unknown host service

adb被突然占用導致,例如你在運行用例的時候運行了模擬器。

7. UIAutomatorViewer提示: Unable to connect to adb. Check if adb is installed correctly

解決,sdk升級到了25產(chǎn)生的問題。

解決方法:

  1. 將adb.exe 復(fù)制一份到uiautomatorviewer.bat 目錄下
  2. 修改uiautomatorviewer.bat文件最后一行(改binddir=%prog_dir%為自己的platform-tools本地路徑)


    image

技巧

1. 每次測試都重新安裝app

為capabilities色設(shè)置noReset為true
capabilities.setCapability(“noReset”, true);

2. 中文亂碼

這都是編碼問題:

1.方法1:

Android Studio修改文件編碼的方法,最底部的UTf-8,點擊選GBK就可以了,reload文件。(ps: 先把文件內(nèi)容全選復(fù)制一下再轉(zhuǎn)換編碼,再粘貼,不然文件內(nèi)容就變亂碼了)

2.方法2:

用的是原來的UTF-8編碼,然后在測試module的build.gradle里面添加三行代碼

tasks.withType(JavaCompile){
    options.encoding = 'UTF-8'
}

3. 清除編輯框EditText內(nèi)容

這個問題好像是看手機系統(tǒng)的,我之前的手機就會出現(xiàn)sendKeys的時候沒有全選去掉本來的內(nèi)容,現(xiàn)在都會自動全選覆蓋了,這個也不算問題了。

    /**
     * 逐字刪除編輯框中的文字
     * @param element 文本框架控件
     */
    public void clearText(AndroidElement element){
        String className = element.getClass().getSimpleName();
        if (className.equals("EditText")){
            String text = element.getText();
            //跳到最后
            driver.pressKeyCode(KEYCODE_MOVE_END);
            for (int i = 0; i < text.length(); i ++){
                //循環(huán)后退刪除
                driver.pressKeyCode(BACKSPACE);
            }
        }else {
            print("不是文本輸入框架,無法刪除文字");
        }

    }

4. 點擊輸入法鍵盤的回車搜索

方法1: 切換輸入法

利用adb命令先切換為自己的輸入法,按了搜索再切換為appium的輸入法

查看當前手機的輸入法

cmd執(zhí)行下面的的代碼

adb shell ime list -s

可以看到類似下面的結(jié)果,

C:\Users\LITP>adb shell ime list -s
com.baidu.input_mi/.ImeService
com.sohu.inputmethod.sogou.xiaomi/.SogouIME
io.appium.android.ime/.UnicodeIME

C:\Users\LITP>

執(zhí)行adb命令

先寫好一個執(zhí)行cmd的方法

    /**
     * 執(zhí)行adb命令
     * @param s 要執(zhí)行的命令
     */
    private void excuteAdbShell(String s) {
        Runtime runtime=Runtime.getRuntime();
        try{
            runtime.exec(s);
        }catch(Exception e){
            print("執(zhí)行命令:"+s+"出錯");
        }
    }

在需要搜索的時候執(zhí)行下面的代碼,切換的輸入法用自己查看列表的輸入法內(nèi)容,我這里是搜狗輸入法

        //使用adb shell 切換輸入法-更改為搜狗拼音,這個看你本來用的什么輸入法
        excuteAdbShell("adb shell ime set com.sohu.inputmethod.sogou.xiaomi/.SogouIME");
        //再次點擊輸入框,調(diào)取鍵盤,軟鍵盤被成功調(diào)出
        clickView(page.getSearch());
        //點擊右下角的搜索,即ENTER鍵
        pressKeyCode(AndroidKeyCode.ENTER);
        //再次切回 輸入法鍵盤為Appium unicodeKeyboard
        excuteAdbShell("adb shell ime set io.appium.android.ime/.UnicodeIME");
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容