出處: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
解決:
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:
3. error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.
4. Error: Permission to start activity denied.
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
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”
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
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)生的問題。
解決方法:
- 將adb.exe 復(fù)制一份到uiautomatorviewer.bat 目錄下
-
修改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");
