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