确认真机环境

1、确认所需要测试的手机以及apk安装成功
2、打开终端,输入adb devices出现一个实例id说明监听成功
3、安装所需要测试的app,adb install xxxx.apk
4、第一次连接会在手机上自动安装appium settings,如果需要手动安装,下载链接:https://github.com/appium/io.appium.settings/releases,然后adb install命令安装至手机

确认appium 环境

1、打开appium,点击start server启动;
2、新版本需要打开appium inspector,;在菜单栏下选择new session window
旧版本直接点击:
在这里插入图片描述
点击后界面设置的一些参数:
在这里插入图片描述
remote host:远程主机,需要填写appium server 服务的主机地址,默认为127.0.0.1
remote post:远程端口,需要填写appium server 服务的主机端口,默认为4723
remote path:远程路径,需要填写appium 服务器的路径,默认填写/wd/hub
其中remote path未修改使用默认 / 时,会报failed to create session错误
在这里插入图片描述

desired capabilities的配置

在这里插入图片描述

参数 含义
platformName 测试的平台,安卓或者ios
platformVersion 系统版本,此处代表安卓10,可以在设置中查看,也可以使用 命令adb shell getpropro.build.version.release查看
deviceName 设备名称,填手机型号就行,随便填也可,连接多台设备时,设备名建议填写adb devices 出现的设备名,以便区分
app app的安装包的位置
appPackage app的包名
appActivity app的activity名,主界面进程名

如何获取当前app的包名以及进程名呢?
1、手机进入相应的app主界面
2、打开终端
3、终端输入

dumpsys window | grep mCurrentFocus
或者
dumpsys activity | grep mFocusedActivity
或者adb shell dumpsys window w | find "/" | find "name="

在这里插入图片描述
配置完成后,点击start session,就可以看到测试机打开了相应的apk,手机桌面已经安装了appium setting以及unlock表示appium 配置成功;

一些问题解决

1、Failed to create session. An unknown server-side error occurred while processing the command, Original error: Appium Settings app is not running after 5000ms
在这里插入图片描述
先检查API版本,更新SDK以及其他多种办法,都没解决,后面回退了appium版本至1.18.0才可连接成功
2、An unknown server-side error occurred while processing the command,original error:The instrumentation process cannot be initialized within 30000ms timeout Make sure the application under test does not crash and investigate the logcat output. You could also try to increase the value of uiautomator2ServerlaunchTimeout’ capability
在这里插入图片描述
出现这个问题是因为安装了不同版本的uiautomator
使用命令查看pm list package | grep uiautomator
在这里插入图片描述
后使用命令卸载
adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test
重启
连接一次后,后续会重复安装,可添加此desired capabilities参数
“skipServerInstallation”:True,
‘skipDeviceInitialization’:True
但需注意,设备上没有uiautomator2包时,不能设置跳过安装
3、若打开app后一直需要允许权限,可添加此参数,跳过软件充值
在这里插入图片描述

元素定位工具

可以用appium自带的inspector

这个在我的电脑上使用有些卡顿,所以我是和Android 自己提供的定位工具来定位元素的

uiautomatorviewer.bat

这个是Android自带的定位工具,在Android SDK以下目录,用来扫描和分析应用的UI 控件
,在使用之前,需要保证你的Android SDK tools是revision 21或者更高,Android SDK platform API 16 或者更高
在这里插入图片描述
点击uiautomatorviewer.bat之后如果出现了闪退,打不开图形界面,在此bat脚本中添加pause可以看到
在这里插入图片描述
这是因为安装的JDK版本在9或者更高,JDK不再提供JRE,导致appium和uiautomatorviewer会因为找不到JDK目录下的JRE而报错,可以回退至JDK8版本即可解决这个问题;

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐