appium_真机测试_No route found. Setting content type to 'text/plain'

问题描述:

在使用appium进行真机测试的时候,在配置好需要的参数后点击Start Session就出现了问题

appium_真机测试_No route found. Setting content type to 'text/plain'

 报错如下:

[MJSONWP] Calling AppiumDriver.createSession() with args: [{"appActivity":".ui.LauncherUI","appPackage":"com.tencent.mm","deviceName":"ONEPLUS_A6000","platformName":"Android","newCommandTimeout":0,"connectHardwareKeyboard":true},null,null]
[BaseDriver] Event 'newSessionRequested' logged at 1547127578106 (21:39:38 GMT+0800 (中国标准时间))
[Appium] Creating new AndroidDriver (v4.8.0) session
[Appium] Capabilities:
[Appium]   appActivity: .ui.LauncherUI
[Appium]   appPackage: com.tencent.mm
[Appium]   deviceName: ONEPLUS_A6000
[Appium]   platformName: Android
[Appium]   newCommandTimeout: 0
[Appium]   connectHardwareKeyboard: true
[BaseDriver] Creating session with MJSONWP desired capabilities: {"appActivity":".ui.Launche...
[BaseDriver] The following capabilities were provided, but are not recognized by appium: connectHardwareKeyboard.
[BaseDriver] Session created with session id: 20e1edb0-4925-409e-bbba-989dd2d8bcc3
[AndroidDriver] Java version is: 1.8.0_191
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[AndroidDriver] Using device: ca0fc03b
[ADB] Setting device id to ca0fc03b
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell getprop ro.build.version.sdk'
[ADB] Current device property 'ro.build.version.sdk': 28
[ADB] Device API level: 28
[AndroidDriver] Consider setting 'automationName' capability to 'uiautomator2' on Android >= 6, since UIAutomator framework is not maintained anymore by the OS vendor.
[AndroidDriver] App file was not listed, instead we're going to run com.tencent.mm directly on the device
[AndroidDriver] Checking whether package is present on the device
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell pm list packages com.tencent.mm'
[AndroidDriver] Starting Android session
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b wait-for-device'
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell echo ping'
[AndroidDriver] Pushing settings apk to device...
[ADB] Getting install status for io.appium.settings
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell dumpsys package io.appium.settings'
[ADB] 'io.appium.settings' is installed
[ADB] Getting package info for 'io.appium.settings'
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell dumpsys package io.appium.settings'
[AndroidDriver] Ignored error while installing Appium Settings helper: 'Could not find aapt Please set the ANDROID_HOME environment variable with the Android SDK root directory path.'. Manually uninstalling the application with package id 'io.appium.settings' may help. Expect some Appium features may not work as expected unless this problem is fixed.
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell ps'
[ADB] Device API level: 28
[ADB] Device API level: 28
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
[AndroidDriver] Failed to launch settings app: Cannot start the 'io.appium.settings' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Android\\adb.exe -P 5037 -s ca0fc03b shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000' timed out after 20000ms'; Stderr: ''; Code: 'null'
[ADB] Device API level: 28
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell appops set io.appium.settings android\:mock_location allow'
[Logcat] Starting logcat capture
[ADB] Getting device platform version
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 9
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell wm size'
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell getprop ro.product.model'
[ADB] Current device property 'ro.product.model': ONEPLUS A6000
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell getprop ro.product.manufacturer'
[ADB] Current device property 'ro.product.manufacturer': OnePlus
[AndroidDriver] No app sent in, not parsing package/activity
[AndroidDriver] No app capability. Assuming it is already on the device
[ADB] Getting install status for com.tencent.mm
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell dumpsys package com.tencent.mm'
[ADB] 'com.tencent.mm' is installed
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am force-stop com.tencent.mm'
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell pm clear com.tencent.mm'
[AndroidDriver] Performed fast reset on the installed 'com.tencent.mm' application (stop and clear)
[AndroidBootstrap] Watching for bootstrap disconnect
[ADB] Forwarding system: 4724 to device: 4724
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b forward tcp\:4724 tcp\:4724'
[UiAutomator] Starting UiAutomator
[UiAutomator] Moving to state 'starting'
[UiAutomator] Parsing uiautomator jar
[UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b push 'C:\\Program Files (x86)\\Appium\\resources\\app\\node_modules\\appium-android-driver\\bootstrap\\bin\\AppiumBootstrap.jar' /data/local/tmp/'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell ps'
[ADB] No 'uiautomator' process has been found
[UiAutomator] Starting UIAutomator
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","ca0fc03b","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.tencent.mm","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[UiAutomator] Moving to state 'online'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] Android bootstrap socket is now connected
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell dumpsys window'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[AndroidDriver] Screen is locked, trying to unlock
[AndroidDriver] Using app unlock, this is going to be deprecated!
[AndroidDriver] Unlocking screen
[AndroidDriver] Launching .Unlock
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am start -n io.appium.settings/.Unlock -c android.intent.category.LAUNCHER -a android.intent.action.MAIN -f 0x10200000'
[AndroidBootstrap] Emitting alert message...
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Emitting system alert message
[ADB] Device API level: 28
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am start -W -n com.tencent.mm/.ui.LauncherUI -S'
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am start -W -n com.tencent.mm/.ui.LauncherUI -S'
[AndroidDriver] Shutting down Android driver
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am force-stop com.tencent.mm'
[ADB] Pressing the HOME button
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell input keyevent 3'
[AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[AndroidBootstrap] Received command result from bootstrap
[UiAutomator] Shutting down UiAutomator
[UiAutomator] Moving to state 'stopping'
[UiAutomator] UiAutomator shut down normally
[UiAutomator] Moving to state 'stopped'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell ps'
[ADB] No 'uiautomator' process has been found
[UiAutomator] Moving to state 'stopped'
[Logcat] Stopping logcat capture
[ADB] Running 'C:\Android\adb.exe -P 5037 -s ca0fc03b shell am force-stop io.appium.unlock'
[AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[BaseDriver] Event 'newSessionStarted' logged at 1547127664707 (21:41:04 GMT+0800 (中国标准时间))
[MJSONWP] Encountered internal error running command: Error: Cannot start the 'com.tencent.mm' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Android\\adb.exe -P 5037 -s ca0fc03b shell am start -W -n com.tencent.mm/.ui.LauncherUI -S' timed out after 20000ms'; Stderr: ''; Code: 'null'
[MJSONWP]     at ADB.apkUtilsMethods.startApp (C:\Program Files (x86)\Appium\resources\app\node_modules\appium-adb\lib\tools\apk-utils.js:144:11)
[MJSONWP]     at process._tickCallback (internal/process/next_tick.js:68:7)
[HTTP] <-- POST /wd/hub/session 500 86653 ms - 534
[HTTP] 
[HTTP] --> DELETE /wd/hub/session
[HTTP] {}
[HTTP] No route found. Setting content type to 'text/plain'
[HTTP] <-- DELETE /wd/hub/session 404 5 ms - 57

 

原因分析:

在度娘找了好久,有说是因为环境配置的问题,和appium和sdk不兼容导致的,但是我的appium值点击Start Session的时候时而成功,时而出错,目测是环境不兼容导致的,还有个原因就是你的手机锁屏了,真正的原因还在寻找。

解决:

无意间发现了一个偏方,就是将所有appium软件关闭,等一两分钟后在打开,重新执行。不行的话就重启

 

重新打开后在执行就成功了,执行结果:

appium_真机测试_No route found. Setting content type to 'text/plain'