Appium Android 真机下,跑脚本的时候经常会报 UiAutomator quit before it successfully launched

雪怪 · 2016年01月07日 · 最后由 魏嫚 回复于 2018年11月08日 · 3046 次阅读

问题描述

真机下跑脚本的时候,经常会报这种错误,但是重启 appium 服务几次后再跑的时候又没问题
跑一段时间后,有时又再次报错
网上没找到相关的说明,求帮忙分析可能的出错原因

环境

windows7 x64
Eclipse 4.5.1
java 1.8.0_66
Appium 1.4.16.1

配置信息

capabilities.setCapability("platformName", "Android");  
capabilities.setCapability("deviceName","meizu-m1_note-71MBBKT22ACK"); 
capabilities.setCapability("platformVersion", "5.1"); 

File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps/XSW");
File app = new File(appDir, "xswTeacher.apk");
capabilities.setCapability("app", app.getAbsolutePath());

capabilities.setCapability("appPackage", "com.xsw.teacher"); 
capabilities.setCapability("appActivity", ".activity.WelcomeActivity");
capabilities.setCapability("appWaitActivity", ".activity.ShowLoginActivity");

capabilities.setCapability("automationName", "Appium");        

//启动不重置应用
//capabilities.setCapability("autoLaunch", "false");
//capabilities.setCapability("noReset", true);

//允许输入中文
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");

相关信息

junit 的报错信息

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: UiAutomator quit before it successfully launched) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.93 seconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'xili-PC', ip: '192.168.1.69', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: io.appium.java_client.android.AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:161)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:170)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:82)
    at Course.setUp(Course.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

java.lang.NullPointerException
    at Course.tearDown(Course.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


appium 日志

> Launching Appium server with command: D:\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --session-override --platform-name Android --platform-version 22 --automation-name Appium --log-no-color
> info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
> info: Appium REST http interface listener started on 127.0.0.1:4723
> info: [debug] Non-default server args: {"address":"127.0.0.1","sessionOverride":true,"logNoColors":true,"platformName":"Android","platformVersion":"22","automationName":"Appium"}
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"D:\\eclipse\\workspace\\Xsw\\apps\\XSW\\xswTeacher.apk","appPackage":"com.xsw.teacher","appActivity":".activity.WelcomeActivity","platformVersion":"5.1","appWaitActivity":".activity.ShowLoginActivity","automationName":"Appium","unicodeKeyboard":"True","platformName":"Android","deviceName":"meizu-m1_note-71MBBKT22ACK","resetKeyboard":"True"}}
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_66)
> warn: Converting cap unicodeKeyboard from string to boolean. This might cause unexpected behavior.
> warn: Converting cap resetKeyboard from string to boolean. This might cause unexpected behavior.
> info: [debug] Using local app from desired caps: D:\eclipse\workspace\Xsw\apps\XSW\xswTeacher.apk
> info: [debug] Creating new appium session 82a9974a-a034-4442-9aee-5a625a3a3806
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_66
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from D:\Android\android-sdk-windows\platform-tools\adb.exe
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Checking whether app is actually present
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device 71MBBKT22ACK
> info: [debug] Setting device id to 71MBBKT22ACK
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK wait-for-device
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 22
> info: Device API level is: 22
> info: [debug] Extracting strings for language: default
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "getprop persist.sys.language"
> info: [debug] Current device persist.sys.language: zh
> info: [debug] java -jar "D:\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "D:\eclipse\workspace\Xsw\apps\XSW\xswTeacher.apk" "C:\Users\xili\AppData\Local\Temp\com.xsw.teacher" zh
> info: [debug] Reading strings from converted strings.json
> info: [debug] Setting language to default
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK push "C:\\Users\\xili\\AppData\\Local\\Temp\\com.xsw.teacher\\strings.json" /data/local/tmp
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from D:\Android\android-sdk-windows\build-tools\23.0.2\aapt.exe
> info: [debug] Retrieving process from manifest.
> info: [debug] executing cmd: D:\Android\android-sdk-windows\build-tools\23.0.2\aapt.exe dump xmltree D:\eclipse\workspace\Xsw\apps\XSW\xswTeacher.apk AndroidManifest.xml
> info: [debug] Set app process to: com.xsw.teacher
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Checking app cert for D:\eclipse\workspace\Xsw\apps\XSW\xswTeacher.apk.
> info: [debug] executing cmd: java -jar D:\Appium\node_modules\appium\node_modules\appium-adb\jars\verify.jar D:\eclipse\workspace\Xsw\apps\XSW\xswTeacher.apk
> info: [debug] App already signed.
> info: [debug] Zip-aligning D:\eclipse\workspace\Xsw\apps\XSW\xswTeacher.apk
> info: [debug] Checking whether zipalign is present
> info: [debug] Using zipalign from D:\Android\android-sdk-windows\build-tools\23.0.2\zipalign.exe
> info: [debug] Zip-aligning apk.
> info: [debug] executing cmd: D:\Android\android-sdk-windows\build-tools\23.0.2\zipalign.exe -f 4 D:\eclipse\workspace\Xsw\apps\XSW\xswTeacher.apk C:\Users\xili\AppData\Local\Temp\11607-6360-12eaqg7\appium.tmp
> info: [debug] MD5 for app is 3b2c9513bbe74a39958fa82f247fe732
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "ls /data/local/tmp/3b2c9513bbe74a39958fa82f247fe732.apk"
> info: [debug] Getting install status for com.xsw.teacher
> info: [debug] Getting device API level
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 22
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "pm list packages -3 com.xsw.teacher"
> info: [debug] App is installed
> info: App is already installed, resetting app
> info: [debug] Running fast reset (stop and clear)
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "am force-stop com.xsw.teacher"
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "pm clear com.xsw.teacher"
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK forward tcp:4724 tcp:4724
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK push "D:\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
> info: [debug] Enabling Unicode keyboard support
> info: [debug] Pushing unicode ime to device...
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK install "D:\Appium\node_modules\appium\build\unicode_ime_apk\UnicodeIME-debug.apk"
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "settings get secure default_input_method"
> info: [debug] Unsetting IME 'io.appium.android.ime/.UnicodeIME'
> info: [debug] Setting IME to 'io.appium.android.ime/.UnicodeIME'
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "ime enable io.appium.android.ime/.UnicodeIME"
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "ime set io.appium.android.ime/.UnicodeIME"
> info: [debug] Pushing settings apk to device...
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK install "D:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> info: [debug] Pushing unlock helper app to device...
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK install "D:\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
> info: Starting App
> info: [debug] Attempting to kill all 'uiautomator' processes
> info: [debug] Getting all processes with 'uiautomator'
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "ps 'uiautomator'"
> info: [debug] No matching processes found
> info: [debug] Running bootstrap
> info: [debug] spawning: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.xsw.teacher -e disableAndroidWatchers false
> info: [debug] UiAutomator exited
> info: [debug] executing cmd: D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell "echo 'ping'"
> info: [debug] Attempting to uninstall app
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Cleaning up android objects
> error: UiAutomator quit before it successfully launched
> info: [debug] Cleaning up appium session
> error: Failed to start an Appium session, err was: Error: UiAutomator quit before it successfully launched
> info: [debug] Error: UiAutomator quit before it successfully launched
>     at [object Object].<anonymous> (D:\Appium\node_modules\appium\lib\devices\android\android.js:205:23)
>     at [object Object].<anonymous> (D:\Appium\node_modules\appium\lib\devices\android\android-hybrid.js:249:5)
>     at Object.async.eachSeries (D:\Appium\node_modules\appium\node_modules\async\lib\async.js:142:20)
>     at [object Object].androidHybrid.stopChromedriverProxies (D:\Appium\node_modules\appium\lib\devices\android\android-hybrid.js:233:9)
>     at [object Object].<anonymous> (D:\Appium\node_modules\appium\lib\devices\android\android.js:200:10)
>     at [object Object].<anonymous> (D:\Appium\node_modules\appium\lib\devices\android\android.js:222:9)
>     at [object Object].androidCommon.uninstallApp (D:\Appium\node_modules\appium\lib\devices\android\android-common.js:478:5)
>     at [object Object].<anonymous> (D:\Appium\node_modules\appium\lib\devices\android\android.js:220:12)
>     at [object Object].<anonymous> (D:\Appium\node_modules\appium\lib\devices\android\android.js:229:11)
>     at D:\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:901:7
>     at [object Object].<anonymous> (D:\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
>     at ChildProcess.exithandler (child_process.js:742:7)
>     at ChildProcess.emit (events.js:110:17)
>     at maybeClose (child_process.js:1016:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:1088:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: UiAutomator quit before it successfully launched)","origValue":"UiAutomator quit before it successfully launched"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 20773.508 ms - 218 
共收到 13 条回复 时间 点赞

这个帖子。。。信息至少很全。。问题来看看

#2 楼 @monkey 感谢~最近电脑上翻{}墙总是不稳定,在手机上 google 搜索了下,确实多了不少搜索结果,我先手机上查查看

#3 楼 @snowmaster 不过我大概看了下。。貌似 github 上面最后这个问题没有被 close。。。。。

#4 楼 @monkey 搜了下,github 上有好 2 条相关的 issue,但都没关掉,另外还搜到 1 年前的 testerhome 上帖子,我先试试上面的解决方法看看是否有用

#5 楼 @snowmaster hmmm。。先试试看吧。。我估计。。。。= =。。到时候回复下现状吧

翻了一堆网页,并没有什么有效的解决方法。。重启手机再跑一遍吧

uiautomator 启动失败,导致创建 session 失败。为什么启动失败,可以手工执行该命令结合 cmd output 确认问题。

D:\Android\android-sdk-windows\platform-tools\adb.exe -s 71MBBKT22ACK shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.xsw.teacher -e disableAndroidWatchers false

#8 楼 @marker 感谢!这个问题经常遇到,我再查查

uiautomator 获取页面元素中文乱码,机型安卓 5.0.2,请问能解决吗

#9 楼 @snowmaster 你这个问题解决了吗?怎么解决的,看 github 上面的资料显示仍然没有解决

怎么样?解决了吗?我也遇到同样的问题!

eclipse java 代码

二月 22, 2017 4:29:00 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: UiAutomator quit before it successfully launched) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'PC201403181853', ip: '113.250.156.78', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: driver.version: AndroidDriver

appium 日志

nfo: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: UiAutomator quit before it successfully launched)","origValue":"UiAutomator quit before it successfully launched"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 90719.962 ms - 218 

请问解决了吗?怎么解决的?

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