Appium win10 运行 appium 报错,报错信息如下,麻烦大家帮忙看看

时光走散了故人。 · 2017年09月27日 · 最后由 黑水 回复于 2017年09月29日 · 2426 次阅读

appium 版本:1.4.16
node 版本:v4.4.7

代码如下:

from appium import webdriver
import time

desired_caps = {
                # 这里是声明android还是ios的环境
                'platformName':'Android',
                # 手机设备名称,通过adb devices查看
                'deviceName':'LEY7A06470000540',
                # android系统的版本号
                'platformVersion':'6.0',
                # apk包名
                'appPackage':'com.innext.souyijie',
                # apk的launcherActivity
                'appActivity':'com.innext.souyijie.ui.activity.LaunchActivity',
                }
dr = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)

time.sleep(5)
dr.find_element_by_id('com.innext.souyijie:id/tab_my').click()
time.sleep(2)
print '1'
dr.find_element_by_id('com.innext.souyijie:id/tv_login').click()
dr.implicitly_wait(5)
dr.find_element_by_id('com.innext.souyijie:id/edt_phone_number').send_keys(u'xxxxxx')
dr.find_element_by_id('com.innext.souyijie:id/edt_password').send_keys(u'xxxxxx')
dr.find_element_by_id('com.innext.souyijie:id/btn_login').click()
dr.implicitly_wait(30)
dr.find_element_by_id('com.innext.souyijie:id/tab_home').click()
dr.find_element_by_id('com.innext.souyijie:id/iv_go_sign').click()
dr.find_element_by_id('com.innext.souyijie:id/btn_sign').click()
dr.find_element_by_id('com.innext.souyijie:id/tab_my').click()
dr.find_element_by_id('com.innext.souyijie:id/layout_setting').click()
dr.find_element_by_id('com.innext.souyijie:id/tv_exit').click()
dr.implicitly_wait(5)
dr.find_element_by_id('com.innext.souyijie:id/tv_accomplish').click()

场景描述:被测 app 能启动起来,但启动之后就直接报错了,具体报错日志如下:

PyCharm 报错信息如下

Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/appium_test/start.py", line 25, in <module>
    dr = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
  File "D:\Python27\lib\site-packages\appium\webdriver\webdriver.py", line 36, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
  File "D:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Original error: com.innext.souyijie/.ui.activity.LaunchActivity never started. Current: com.innext.souyijie/.ui.MainActivity,)


Process finished with exit code 1

appium 中的报错信息如下:

Microsoft Windows [版本 10.0.15063]
(c) 2017 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>appium
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"capabilities":{"alwaysMatch":{"platformName":"Android"},"firstMatch":[{}]},"desiredCapabilities":{"waitappActivity":"com.opera.android.OperaMainActivity","deviceName":"LEY7A06470000540","platformVersion":"6.0","appPackage":"com.innext.souyijie","platformName":"Android","appActivity":"com.innext.souyijie.ui.activity.LaunchActivity"}}
info: Client User-Agent string: Python http auth
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : waitappActivity
info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 2a48edfe-db68-4c25-b871-e67a52581b72
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_71
info: [debug] Checking whether adb is present
info: [debug] Using adb from D:\android-sdk-windows\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: D:\android-sdk-windows\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device LEY7A06470000540
info: [debug] Setting device id to LEY7A06470000540
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 wait-for-device
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Getting device API level
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 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: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 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: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 push "D:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 install "D:\Program Files (x86)\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-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 install "D:\Program Files (x86)\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-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.innext.souyijie -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] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
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] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window"
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\/local\/tmp"}
info: [debug] dataDir set to: /data/local/tmp
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: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 23
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.innext.souyijie/com.innext.souyijie.ui.activity.LaunchActivity"
info: [debug] Waiting for pkg "com.innext.souyijie" and activity "com.innext.souyijie.ui.activity.LaunchActivity" to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s LEY7A06470000540 shell "dumpsys window windows"
error: com.innext.souyijie/.ui.activity.LaunchActivity never started. Current: com.innext.souyijie/.ui.MainActivity,
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
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: 21.809
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: com.innext.souyijie/.ui.activity.LaunchActivity never started. Current: com.innext.souyijie/.ui.MainActivity,
info: [debug] Error: com.innext.souyijie/.ui.activity.LaunchActivity never started. Current: com.innext.souyijie/.ui.MainActivity,
    at [object Object].<anonymous> (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1314:12)
    at [object Object].<anonymous> (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1258:7)
    at [object Object].<anonymous> (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
    at ChildProcess.exithandler (child_process.js:204:7)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:827:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: com.innext.souyijie/.ui.activity.LaunchActivity never started. Current: com.innext.souyijie/.ui.MainActivity,)","origValue":"com.innext.souyijie/.ui.activity.LaunchActivity never started. Current: com.innext.souyijie/.ui.MainActivity,"},"sessionId":null}
info: <-- POST /wd/hub/session 500 26189.124 ms - 340

共收到 11 条回复 时间 点赞

根据下面帖子的解决方案,我在 desired_caps 中增加了'waitappActivity':'com.opera.android.OperaMainActivity'
但是依然报错
帖子链接:https://testerhome.com/topics/2287

通过 print 打印数字的方法,发现程序只执行到 print ‘0’ 这一行,下面的 driver 根本就没起来,大家帮忙看一下,麻烦大家了

desired_caps = {
                # 这里是声明android还是ios的环境
                'platformName':'Android',
                # 手机设备名称,通过adb devices查看
                'deviceName':'LEY7A06470000540',
                # android系统的版本号
                'platformVersion':'6.0',
                # apk包名
                'appPackage':'com.innext.souyijie',
                # apk的launcherActivity
                'appActivity':'com.innext.souyijie.ui.activity.LaunchActivity',
                }
print '0'
dr = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
print '1'
time.sleep(5)
dr.find_element_by_id('com.innext.souyijie:id/tab_my').click()
time.sleep(2)
print '2'
A new session could not be created. (Original error: com.innext.souyijie/.ui.activity.LaunchActivity never started. Current: com.innext.souyijie/.ui.MainActivity,)

你的启动 Activity 是不是填错了,光贴日志,自己都不看吗

null 回复

没有填错,看我下面的截图

你先试试换成.ui.MainAcitivity

null 回复

按照你的方法,我把 appActivity 修改了,代码如下:

desired_caps = {
                # 这里是声明android还是ios的环境
                'platformName':'Android',
                # 手机设备名称,通过adb devices查看
                'deviceName':'PBV7N16C29013577',
                # android系统的版本号
                'platformVersion':'7.0',
                # apk包名
                'appPackage':'com.innext.souyijie',
                # apk的launcherActivity
                'appActivity':'.ui.MainAcitivity'
                }

还是一样报错,我怀疑是没有 sessionId 的问题,见下面截图:

这我就不知道了 通常我的 capability 比你这个多了个 udid 和 app 字段

udid 存的是 你这的 “PBV7N16C29013577” app 是 apk 路径 deviceName 都是瞎填的

null 回复

我按照你的试试,加上这两个字段

还是不行,无解了,好气啊😭 😭 😭 😭

没人遇到过我这种问题吗?😣 😢

你需要先弄明白你们 App 启动过程中 Activity 出现顺序
adb logcat -b events | findstr yourAppPackageName

当 apk 包的 activity 与打开应用后其它的 activity 不匹配时候,应该怎么办?

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