服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android测试中Appium的一些错误解决技巧

Android测试中Appium的一些错误解决技巧

2022-08-10 11:24tpnet Android

今天小编就为大家分享一篇关于Android测试中Appium的一些错误解决技巧的文章,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

问题

1. error: failed to start an appium session, err was: error: requested a new session but one was in progress

Android测试中Appium的一些错误解决技巧

之前的会话没有关闭,然后你又运行了测试实例,也没有设置覆盖.
解决:

1. 重新停止appium服务,开启appium服务
2. 在genarel setting那里设置覆盖session,重启appium

测试结束在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:

Android测试中Appium的一些错误解决技巧

没有链接上手机或者模拟器,请确认已经连接成功,重新链接

3. error: android devices must be of api level 17 or higher. please change your device to selendroid or upgrade android on your device.

Android测试中Appium的一些错误解决技巧

手机系统低于4.2,appium不支持4.2.2以下的系统,请换一个手机或者模拟器来测试。

4. error: permission to start activity denied.

Android测试中Appium的一些错误解决技巧

**activity在清单文件里面没添加android:exported=”true”的话,你不能直接打开对应的activity,需要从启动页activity打开。
exported属性就是设置是否允许activity被其它程序调用**

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

Android测试中Appium的一些错误解决技巧

要打开的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”

Android测试中Appium的一些错误解决技巧

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

Android测试中Appium的一些错误解决技巧

链接手机失败,重新链接手机即可,我就是重新拔插了一下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被突然占用导致,例如你在运行用例的时候运行了模拟器。

8. uiautomatorviewer提示: unable to connect to adb. check if adb is installed correctly

解决,sdk升级到了25产生的问题。

解决方法:

  1. 将adb.exe 复制一份到uiautomatorviewer.bat 目录下
  2. 修改uiautomatorviewer.bat文件最后一行(改binddir=%prog_dir%为自己的platform-tools本地路径)

Android测试中Appium的一些错误解决技巧

技巧

1. 每次测试都重新安装app

为capabilities色设置noreset为true
capabilities.setcapability(“noreset”, true);

2. 中文乱码

这都是编码问题

1.方法1:

android studio修改文件编码的方法,最底部的utf-8,点击选gbk就可以了,reload文件。(ps: 先把文件内容全选复制一下再转换编码,再粘贴,不然文件内容就变乱码了)

Android测试中Appium的一些错误解决技巧

2.方法2:

用的是原来的utf-8编码,然后在测试module的build.gradle里面添加三行代码

?
1
2
3
tasks.withtype(javacompile){
 options.encoding = 'utf-8'
}

Android测试中Appium的一些错误解决技巧

3. 清除编辑框edittext内容

这个问题好像是看手机系统的,我之前的手机就会出现sendkeys的时候没有全选去掉本来的内容,现在都会自动全选覆盖了,这个也不算问题了。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
 * 逐字删除编辑框中的文字
 * @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 ++){
   //循环后退删除
   driver.presskeycode(backspace);
  }
 }else {
  print("不是文本输入框架,无法删除文字");
 }
}

4. 点击输入法键盘的回车搜索

方法1: 切换输入法

利用adb命令先切换为自己的输入法,按了搜索再切换为appium的输入法

查看当前手机的输入法

cmd执行下面的的代码

?
1
adb shell ime list -s

可以看到类似下面的结果,

?
1
2
3
4
5
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>

执行adb命令

先写好一个执行cmd的方法

?
1
2
3
4
5
6
7
8
9
10
11
12
/**
 * 执行adb命令
 * @param s 要执行的命令
 */
private void excuteadbshell(string s) {
 runtime runtime=runtime.getruntime();
 try{
  runtime.exec(s);
 }catch(exception e){
  print("执行命令:"+s+"出错");
 }
}

在需要搜索的时候执行下面的代码,切换的输入法用自己查看列表的输入法内容,我这里是搜狗输入法

?
1
2
3
4
5
6
7
8
//使用adb shell 切换输入法-更改为搜狗拼音,这个看你本来用的什么输入法
excuteadbshell("adb shell ime set com.sohu.inputmethod.sogou.xiaomi/.sogouime");
//再次点击输入框,调取键盘,软键盘被成功调出
clickview(page.getsearch());
//点击右下角的搜索,即enter键
presskeycode(androidkeycode.enter);
//再次切回 输入法键盘为appium unicodekeyboard
excuteadbshell("adb shell ime set io.appium.android.ime/.unicodeime");

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对服务器之家的支持。如果你想了解更多相关内容请查看下面相关链接

原文链接:https://blog.csdn.net/niubitianping/article/details/52624417

延伸 · 阅读

精彩推荐