新手区 第一次运行 appium 就出错,也不会看日志,能帮忙指导下么

Leticia · 2016年08月05日 · 最后由 Leticia 回复于 2016年10月12日 · 1432 次阅读

做完下列步骤后,模拟器无任何反应,请问下,是哪里没正确么 ?

1 搭建好环境
2 创建模拟器 test_avd,并启动
3 启动 appium
4 python 脚本为:

#coding=utf-8
from appium import webdriver
from time import sleep

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'Android Emulator'

desired_caps['app'] = 'Calculator.apk'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
sleep(3)
driver.find_element_by_id('com.android.calculator2:id/digit_5').click()

5 运行该 python 脚本
6 appium 输出:

> Checking if an update is available
> Update not available
> Launching Appium server with command: F:\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --device-ready-timeout 10 --platform-name Android --platform-version 23 --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","logNoColors":true,"androidDeviceReadyTimeout":"10","platformName":"Android","platformVersion":"23","automationName":"Appium"}
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session {"requiredCapabilities":{},"desiredCapabilities":{"deviceName":"Android Emulator","app":"Calculator.apk","platformVersion":"6.0","appPackage":"com.android.calculator2","platformName":"Android","appActivity":".Calculator"}}
> info: Client User-Agent string: Python-urllib/2.7
> info: [debug] App is an Android package, will attempt to run on device
> info: [debug] Creating new appium session 32ee6ce9-589f-4bb7-afd8-028757cd72cd
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_101
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from F:\Android\android-sdk\platform-tools\adb.exe
> warn: No app capability, can't parse package/activity
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Not checking whether app is present since we are assuming it's already on the device
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device emulator-5554
> info: [debug] Setting device id to emulator-5554
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 10)
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 wait-for-device
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 23
> info: Device API level is: 23
> info: [debug] Extracting strings for language: default
> info: [debug] Apk doesn't exist locally
> info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell "rm -rf /data/local/tmp/strings.json"
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Skipping install since we launched with a package instead of an app path
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 forward tcp:4724 tcp:4724
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 push "F:\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
> info: [debug] Pushing settings apk to device...
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 install "F:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> info: [debug] Pushing unlock helper app to device...
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 install "F:\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: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell "ps 'uiautomator'"
> info: [debug] No matching processes found
> info: [debug] Running bootstrap
> info: [debug] spawning: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg Calculator.apk -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
> info: [debug] [BOOTSTRAP] [debug] Loading json...
> info: [debug] Waking up device if it's not alive
> info: [debug] Pushing command to appium work queue: ["wake",{}]
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell "dumpsys window"
> info: [debug] [BOOTSTRAP] [debug] Client connected
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: wake
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] Screen already unlocked, continuing.
> info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data"}
> info: [debug] dataDir set to: /data
> info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":false}
> info: [debug] Getting device API level
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 23
> info: [debug] executing cmd: F:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n Calculator.apk/.Calculator"
> error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
> info: [debug] [BOOTSTRAP] [debug] Closed client connection
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
> info: [debug] [UIAUTOMATOR STDOUT] Time: 3.601
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] UiAutomator shut down normally
> error: Failed to start an Appium session, err was: Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
>     at [object Object].<anonymous> (F:\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1146:21)
>     at [object Object].<anonymous> (F:\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: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)","origValue":"Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity"},"sessionId":null}
共收到 11 条回复 时间 点赞
匿名 #1 · 2016年08月05日
  • 看日志是 apk 没有获取到,是不是路径指定有问题? info: [debug] Apk doesn't exist locally

脚本里,app 参数设错了,应该设待测应用路径。。

@leticia 应该改成:第一次运行 appium 就出错,也不会看日志,能帮忙指导下么

Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
这表示是你的 activity 不对. 你得确保下他存在并且可以被外部调用

#2 楼 @neyo 用自带的计算器作练习的,能具体说下哪个错了么

参数没有设置 appStartActivity,可以手机连接 PC 启动计算器然后用命令 adb shell dumpsys activity | findstr"mFocusedActivity"(windows 下)来看看启动的 activity 是什么,然后再设置这个参数。

#7 楼 @kesha0 看了呢 就是我写的这个呢 .Calculator

mFocusedActivity: ActivityRecord{f0d11de u0 com.android.calculator2/.Calculato r t30}

#8 楼 @leticia 有可能是这个 activity 没有外部调用权限。

mac+appium+python 入门资料谁有啊,跪求

回来写下解决,让开发修改下外部可调用的权限就好。

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