Appium Appium Server 的健壮性问题

扫地僧 · 2016年05月23日 · 最后由 扫地僧 回复于 2016年07月21日 · 1794 次阅读

Appium Server version:1.4.13

问题一

问题描述:发送一个非法的 xpath 请求,例如:driver.findElement(By.xpath("delay->8")).click(),导致 Appium Server 直接崩溃退出
开始以为服务端顶多抛个异常,通知用户非法指令或非法参数之类的,也不至于退出吧,自己犯的的一个低级错误无意踩中 Appium 的一个问题

Appium Server Log
error: uncaughtException: selectedNodes.slice is not a function date=Mon May 23 2016 11:10:30 GMT+0800 (CST)

问题二

问题描述:iOS 真机运行 1 个多小时,instruments 异常导致 Appium Server 退出
问题分析:是否是 app 内存泄露、溢出导致 instruments 工作异常而退出,最终导致 appium 服务的退出?

App Log
2016-05-30 22:06:09 app_log : May 30 22:02:31 iPhone XXX[1973] <Warning>: TalkingData: event 主页面:主页面_点击_财经快讯 parameters:{
2016-05-30 22:06:09 app_log : May 30 22:02:31 iPhone XXX[1973] <Warning>: TalkingData: trackPage begin pageName:财经快讯_首页
2016-05-30 22:06:09 app_log : May 30 22:02:32 iPhone XXX[1973] <Warning>: TalkingData: 页面简单理财停留时间: 10
2016-05-30 22:06:09 app_log : May 30 22:02:33 iPhone XXX[1973] <Warning>: Received memory warning.

Appium Client Log
org.openqa.selenium.WebDriverException: Instruments died while responding to command, please check appium logs (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 155.20 seconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'macdeMBP', ip: '192.168.1.5', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_74'
Driver info: io.appium.java_client.ios.IOSDriver

Appium Server Log
info: [debug] [INST] 2016-05-30 13:44:08 +0000 Debug: Got new command 2899 from instruments: au.tapById('219')
info: [debug] [INST] 2016-05-30 13:44:08 +0000 Debug: evaluating au.tapById('219')
info: [debug] [INST] 2016-05-30 13:44:08 +0000 Debug: target.frontMostApp().elements()[0].elements()[1].elements()[21].tap()
info: [debug] [INST] 2016-05-30 13:44:08 +0000 Debug: evaluation finished
info: [debug] [INST] 2016-05-30 13:44:08 +0000 Debug: responding with:
info: [debug] [INST] 2016-05-30 13:44:08 +0000 Debug: Running system command #2900: /usr/local/Cellar/node/5.9.0/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] [INST] 2016-05-30 13:44:10 +0000 Debug: Got new command 2900 from instruments: au.mainApp().getTreeForXML()
info: [debug] [INST] 2016-05-30 13:44:10 +0000 Debug: evaluating au.mainApp().getTreeForXML()
info: [debug] [INST] 2016-05-30 13:44:11 +0000 Debug: evaluation finished
info: [debug] [INSTSERVER] Instruments exited with code null
info: [debug] Cleaning up after instruments exit
info: [debug] Instruments exited unexpectedly
info: [debug] Shutting down command proxy and ignoring any errors
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Stopping iOS log capture
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killing any other simulator daemons
info: [debug] Killall iOS Simulator
info: [debug] On a real device; cannot clean device state
info: [debug] We were in the middle of processing a command when instruments died; responding with a generic error
info: [debug] Cleaning up appium session
info: [debug] Responding to client with error: {"status":13,"value":{"message":"Instruments died while responding to command, please check appium logs","name":"UnknownError","origValue":"Instruments died while responding to command, please check appium logs"},"sessionId":null}
info: <-- GET /wd/hub/session/f4b19ca1-ca3d-4d78-afd6-39d9e8ce9177/source 500 155113.474 ms - 230 
info: --> GET /wd/hub/session/f4b19ca1-ca3d-4d78-afd6-39d9e8ce9177/source {}
info: <-- GET /wd/hub/session/f4b19ca1-ca3d-4d78-afd6-39d9e8ce9177/source 404 2.884 ms - 40 
info: --> POST /wd/hub/session/f4b19ca1-ca3d-4d78-afd6-39d9e8ce9177/appium/app/close {}
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 28 条回复 时间 点赞

第二个问题只是推测,每次运行 1 个多小时就重现,谁比较清楚这个报错,能给个确切的结果?

每次都崩溃?

#2 楼 @mer163 每次都会

你是不是用的 GUI? 换成命令行的吧。

#4 楼 @lylyliuyu 我是用命令行的

楼主是不是每个 case 都重新启动 App 呢?如果是的话,我之前也是因为这样,二十个 cases,在 Android 上跑完十五六个 ADB server 就挂掉了

#6 楼 @cxli2 没有,是自动遍历持续跑

匿名 #8 · 2016年06月12日

我这边 iOS 真机测试,跑了几个小时,instrument 到了几十 G。然后 Instruments exited with code null。我也不太清楚是哪个环节出了问题。我是用 appcrawler 跑的。

#8 楼 @guaixiaomei 可能是一样的问题

匿名 #10 · 2016年06月13日

@quqing 可我这里显示的是 instrument 内存占用很大,在 PC 端的,应该不是 iOS APP 本身内存问题吧?楼主有解决思路么

#10 楼 @guaixiaomei 还没,我觉得这个和遍历工具本身无关,我这边 android 跑 2 个小时没问题的,基本也能排除 appium 的问题,很可能是 instrument 本身的问题吧

匿名 #12 · 2016年06月13日

@quqing 请教一个问题,最近在搞 iOS 的遍历,android 上如果跳转到其它 app 里面了,可以返回到原来的 app。iOS 这类问题怎么解决?就是比如测试 a 应用,点了分享到微博,应用就切换到了微博应用,然后遍历程序和 appium 的通信就卡住了。请问下楼主,这种情况有方法回退到原来的测试 a 应用么?谢谢了

#12 楼 @guaixiaomei 目前我是通过设置黑名单、触发器等手段避免跳转到其他应用的

#13 楼 @quqing 请问楼主遍历测试是用的什么工具,或者怎么实现的?

跑了一会 appium server 也会自动死掉。目前无解。

对于 appium 的 seesion 存在时间有设置的办法吗

#17 楼 @shasia 我不清楚这么做的目的是什么,一般会关注 session 的超时时间,即一定时间内未收到请求则失效

#18 楼 @quqing 像 selenium 的话,可以通过 idel 编译器进行一行代码的运行,也就是可以不需要从头开始运行,因为它没有 session 这东西。appium 带了这 session,如果没有后续的代码服务器就会自动断开,要从头开始运行,所以想能否控制 session 的时间,来让服务器一直保持连接状态,写一段运行一下,方便调试

#19 楼 @shasia 启动服务加参数 --command-timeout xx,表示 session 在 xx 时间内未接收到 command request 就失效,不清楚你要的是这个效果吗

#5 楼 @quqing 你好,我用命令行启动 appium 来测试 android 的 app,已经安装过 app 后,总是在创建 AndroidDriver 的时候说找不到.SplashActivity,但是我使用 GUI 版本的 appium 就是没有这个问题的。你有什么建议么?

#21 楼 @janec 这个还得看具体日志

#22 楼 @quqing 我对比了 GUI 版本和我的命令行,就差如图红框处的选项,如果勾上就 OK,不勾上就提示错误的 activity,log 如下:
2016-07-20 10:21:12:930 - [HTTP] <-- GET /wd/hub/status - - ms - -
2016-07-20 10:21:12:962 - [debug] [ADB] Waiting for pkg: 'xxxxx' and activity: 'xxxxx.SplashActivity' to be focused
2016-07-20 10:21:12:963 - [debug] [ADB] Possible activities, to be checked: xxxxx.SplashActivity, .SplashActivity, .xxxxx.SplashActivity
2016-07-20 10:21:12:964 - [debug] [ADB] Getting focused package and activity
2016-07-20 10:21:12:965 - [debug] [ADB] Getting connected devices...
2016-07-20 10:21:12:988 - [debug] [ADB] 1 device(s) connected
2016-07-20 10:21:12:989 - [debug] [ADB] Running /Users/cy/Documents/ADT-Eclipse/sdk/platform-tools/adb with args: ["-P",5037,"-s","85GBBM9235WL","shell","dumpsys","window","windows"]
2016-07-20 10:21:13:045 - [debug] [ADB] Found package: 'xxxxx' and activity: '.ui.tab.MainTabActivity'
2016-07-20 10:21:13:046 - [debug] [ADB] Incorrect package and activity. Retrying.
2016-07-20 10:21:13:797 - [debug] [ADB] Getting focused package and activity
2016-07-20 10:21:13:798 - [debug] [ADB] Getting connected devices...

请问你知道这个对应的命令行参数是什么么?我在代码里面设置了
capabilities.setCapability("StopAppOnReset", "True");
但是好像没有效果

#23 楼 @janec 服务器参数 appActivity 有设置吗,你把代码中的环境配置发出来看看呢

#24 楼 @quqing
代码中的设置如下:

// set up appium
File classpathRoot = new File(System.getProperty("user.dir"));
// 被测应用存放的目录
File appDir = new File(classpathRoot, CommonData.appPath);
// 被测应用的apk名字
File app = new File(appDir, CommonData.appName);

// 设置DesiredCapabilities信息
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

// 以下两项为了支持中文输入
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");
capabilities.setCapability("device", "Android");

// 安卓真机的信息,版本5.0.1,魅族MX5
capabilities.setCapability("deviceName", CommonData.deviceName);
capabilities.setCapability(CapabilityType.VERSION,CommonData.deviceVersion);

// 使用的是mac平台
capabilities.setCapability(CapabilityType.PLATFORM, "Mac OS X");
// 设置apk路径
capabilities.setCapability("app", app.getAbsolutePath());

// 应用的主包名
capabilities.setCapability("app-package", CommonData.appPackage);
//
capabilities.setCapability("StopAppOnReset", "True");
capabilities.setCapability("noReset", "True");
driver = new AndroidDriver<WebElement>(new URL(CommonData.serverUrl), capabilities);

我设置了 ‘capabilities.setCapability("StopAppOnReset", "True");’
但是好像没有生效,因为走到最后的 new AndroidDriver 这里的时候就提示错误了,没有等到.SplashActivity 了

#25 楼 @janec 什么错误呢,日志贴出来

#26 楼 @quqing 就是上面回复你的那段呀,在 server 里面打印出来的
log 如下:

2016-07-20 10:21:12:930 - [HTTP] <-- GET /wd/hub/status - - ms - - 
2016-07-20 10:21:12:962 - [debug] [ADB] Waiting for pkg: 'xxxxx' and activity: 'xxxxx.SplashActivity' to be focused
2016-07-20 10:21:12:963 - [debug] [ADB] Possible activities, to be checked: xxxxx.SplashActivity, .SplashActivity, .xxxxx.SplashActivity
2016-07-20 10:21:12:964 - [debug] [ADB] Getting focused package and activity
2016-07-20 10:21:12:965 - [debug] [ADB] Getting connected devices...
2016-07-20 10:21:12:988 - [debug] [ADB] 1 device(s) connected
2016-07-20 10:21:12:989 - [debug] [ADB] Running /Users/cy/Documents/ADT-Eclipse/sdk/platform-tools/adb with args: ["-P",5037,"-s","85GBBM9235WL","shell","dumpsys","window","windows"]
2016-07-20 10:21:13:045 - [debug] [ADB] Found package: 'xxxxx' and activity: '.ui.tab.MainTabActivity'
2016-07-20 10:21:13:046 - [debug] [ADB] Incorrect package and activity. Retrying.
2016-07-20 10:21:13:797 - [debug] [ADB] Getting focused package and activity
2016-07-20 10:21:13:798 - [debug] [ADB] Getting connected devices...

#27 楼 @janec 2016-07-20 10:21:13:046 - [debug] [ADB] Incorrect package and activity. Retrying.
请确保 DesiredCapabilities 配置的 package 和 activity 是正确的

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册