Appium(二):第一條測試腳本

Appium(一):環境搭建上一篇博文中已經搭建好了整個appium的運行環境,接下來就是需要寫一條自動化的測試腳本。

我們需要配置Appium應用程序:

1、手機連接PC,開啓USB調試,從cmd窗口中輸入adb deivces 來獲取當前連接設備的deviceID

2、雙擊打開PC端桌面Appium圖標,進入Appium界面。點擊Android機器人圖標,設置對應的值,

3、點擊設置圖標,勾選Override Existing Session。(這一步的目的是爲了在多次調試時,每次調試完成後,二次調試調起的Session將覆蓋上一次調試的Session)

4、配置爲完成後,點擊啓動按鈕,啓動完成後,如下圖

我這裏,隨便載了個百度的app,我們就自動化實現這樣一條腳本:打開百度app--點擊"同意並繼續"按鈕--點擊搜索框--輸入“demo”--點擊“百度一下”進行搜索

因爲在腳本中我們需要提供app的一些數據,讓腳本可以調用,所以我們先要獲取百度app(被測apk)的一些數據。在這裏,我們可以使用aapt.exe來對apk進行解析並獲取數據。這個工具由Android SDK提供。詳細的目錄:..\sdk-tools\platform-tools>C:\DEV\AndroidStudio-sdk-tools\build-tools\28.0.2\aapt.exe  辣麼,這個工具可以爲我們提供腳本中需要的Activity值和package值(包名)。只需要在cmd窗口中鍵入命令:C:\DEV\AndroidStudio-sdk-tools\build-tools\28.0.2\aapt.exe dump badging  D:\Process\BaiDu.apk  就可以看到CMD命令窗口中彈出了很多信息。爲方便查看,這裏將命令返回值重定向到D:\baiduAppDate.txt。也就是命令 C:\DEV\AndroidStudio-sdk-tools\build-tools\28.0.2\aapt.exe dump badging  D:\Process\BaiDu.apk > d:\baiduAppDate.txt 用Notepad++等編輯器打開查看,定位到包名和Activity名,取出這兩個值。

接下來,在pyCharm工具中(其他IDE也可)創建一個py文件。根據之前設定要的用例步驟,鍵入代碼:

# coding:utf-8
import os
import time
from appium import webdriver

PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p)) # 固定的寫法

desired_caps = {
    'platformName': 'Android',  # 聲明測試對象爲Android平臺
    'deviceName': 'K51LHP1782600106',  # deviceID 取自adb devices cmd命令行返回值
    'platformVersion': '6.0',  # 平臺版本,與之前Appium程序中設置一致
    'app': PATH(r'D:\Process\BaiDu.apk'),  # 待測app目錄地址
    'appPackage': 'com.baidu.searchbox',  # 待測app的包名
    'appActivity': 'com.baidu.searchbox.SplashActivity',  # 待測app的Activity名稱
    # 'resetKeyboard': 'True'   # 用於設定運行完成後是否重置軟鍵盤狀態
}

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)  # 實例化driver
time.sleep(5)  # 等待5秒
# 點擊“同意並繼續”按鈕
driver.find_element_by_name("同意並繼續").click()  # 根據text進行定位後點擊
time.sleep(5)
# 點擊搜索框
driver.find_element_by_id("com.baidu.searchbox:id/baidu_searchbox").click()  # 根據resourceID進行定位後點擊
time.sleep(2)
# 點擊輸入框
driver.find_element_by_id("com.baidu.searchbox:id/SearchTextInput").click()  # 根據resourceID進行定位後點擊
time.sleep(1)
# 在輸入框中鍵入“demo”
driver.find_element_by_id("com.baidu.searchbox:id/SearchTextInput").send_keys('demo')  # 根據resourceID進行定位後輸入
time.sleep(3)
# 點擊"百度一下"按鈕
driver.find_element_by_name("百度一下").click()  # 根據text進行定位後點擊

需要說明的是,如果待測app的PATH沒有在腳本中寫明的話,也可以直接在appium程序中設定。如下圖:

OK,接下來就是運行了。(需要說明的是,在運行時,Appium曾經卡住了,從PC端的appium中的log看,卡在了ps uiautomator這個步驟,需要修改adb.js這個文件,詳細的解決方案,可以借鑑網上大神們的博客。解決方案地址:https://www.cnblogs.com/syw20170419/p/7994482.html)

在PyCharm工具中,直接運行剛寫的腳本。觀察手機端的運行響應,同時查看PC端Appium工具中彈出的日誌。

在PC端Appium工具中彈出了日誌,日誌有點多,如果我們詳細一行行的看日誌的話,我們可以看到調起測試後,Appium所做的一切事情,包括獲取java、調用adb、連接設備,起服務,調用aapt.exe去分析待測app、安裝app,最後調起測試等等等。

> Launching Appium server with command: C:\DEV\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --session-override --platform-name Android --platform-version 23 --automation-name Appium --device-name "K51LHP1782600106" --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,"deviceName":"K51LHP1782600106","platformName":"Android","platformVersion":"23","automationName":"Appium"}
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session {"capabilities":{"firstMatch":[{"appium:appActivity":"com.baidu.searchbox.SplashActivity","appium:app":"D:\\Process\\BaiDu.apk","appium:deviceName":"K51LHP1782600106","appium:platformVersion":"6.0","appium:appPackage":"com.baidu.searchbox","platformName":"Android"}]},"desiredCapabilities":{"deviceName":"K51LHP1782600106","app":"D:\\Process\\BaiDu.apk","platformVersion":"6.0","appPackage":"com.baidu.searchbox","platformName":"Android","appActivity":"com.baidu.searchbox.SplashActivity"}}
> info: Client User-Agent string: selenium/3.141.0 (python windows)
> info: [debug] Using local app from desired caps: D:\Process\BaiDu.apk
> info: [debug] Creating new appium session 7cd626ca-ac3a-47ac-8b57-1ad0bec3a124
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.7.0_51
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from C:\DEV\AndroidStudio-sdk-tools\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: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device K51LHP1782600106
> info: [debug] Setting device id to K51LHP1782600106
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 wait-for-device
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 25
> info: Device API level is: 25
> info: [debug] Extracting strings for language: default
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "getprop persist.sys.language"
> info: [debug] Current device persist.sys.language: 
> info: [debug] java -jar "C:\DEV\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "D:\Process\BaiDu.apk" "C:\Users\meitu\AppData\Local\Temp\com.baidu.searchbox" 
> info: [debug] Reading strings from converted strings.json
> info: [debug] Setting language to default
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 push "C:\\Users\\meitu\\AppData\\Local\\Temp\\com.baidu.searchbox\\strings.json" /data/local/tmp
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from C:\DEV\AndroidStudio-sdk-tools\build-tools\28.0.2\aapt.exe
> info: [debug] Retrieving process from manifest.
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\build-tools\28.0.2\aapt.exe dump xmltree D:\Process\BaiDu.apk AndroidManifest.xml
> info: [debug] Set app process to: com.baidu.searchbox
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Checking app cert for D:\Process\BaiDu.apk.
> info: [debug] executing cmd: java -jar C:\DEV\Appium\node_modules\appium\node_modules\appium-adb\jars\verify.jar D:\Process\BaiDu.apk
> info: [debug] App already signed.
> info: [debug] Zip-aligning D:\Process\BaiDu.apk
> info: [debug] Checking whether zipalign is present
> info: [debug] Using zipalign from C:\DEV\AndroidStudio-sdk-tools\build-tools\28.0.2\zipalign.exe
> info: [debug] Zip-aligning apk.
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\build-tools\28.0.2\zipalign.exe -f 4 D:\Process\BaiDu.apk C:\Users\meitu\AppData\Local\Temp\119010-972-8js6z2\appium.tmp
> info: [debug] MD5 for app is 1a7cafa9c33f17f4786a7800ca69ab31
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "ls /data/local/tmp/1a7cafa9c33f17f4786a7800ca69ab31.apk"
> info: [debug] Getting install status for com.baidu.searchbox
> info: [debug] Getting device API level
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 25
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "pm list packages -3 com.baidu.searchbox"
> info: [debug] App is not installed
> info: Installing App
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "mkdir -p /data/local/tmp/"
> info: [debug] Removing any old apks
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "ls /data/local/tmp/*.apk"
> info: [debug] Found an apk we want to keep at /data/local/tmp/1a7cafa9c33f17f4786a7800ca69ab31.apk
> info: [debug] Couldn't find any apks to remove
> info: [debug] Uninstalling com.baidu.searchbox
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "am force-stop com.baidu.searchbox"
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 uninstall com.baidu.searchbox
> info: [debug] App was not uninstalled, maybe it wasn't on device?
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "pm install -r /data/local/tmp/1a7cafa9c33f17f4786a7800ca69ab31.apk"
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 forward tcp:4724 tcp:4724
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 push "C:\\DEV\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
> info: [debug] Pushing settings apk to device...
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 install "C:\DEV\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> info: [debug] Pushing unlock helper app to device...
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 install "C:\DEV\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: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "ps"| grep uiautomator
> info: [debug] No matching processes found
> info: [debug] Running bootstrap
> info: [debug] spawning: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.baidu.searchbox -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] Warning: This version of UI Automator is deprecated. New tests should be written using
> info: [debug] [UIAUTOMATOR STDOUT] UI Automator 2.0 which is available as part of the Android Testing Support Library.
> info: [debug] [UIAUTOMATOR STDOUT] See https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html
> info: [debug] [UIAUTOMATOR STDOUT] for more details.
> 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] json loading complete.
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "dumpsys window"
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> 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\/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: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 25
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.baidu.searchbox/com.baidu.searchbox.SplashActivity"
> info: [debug] Waiting for pkg "com.baidu.searchbox" and activity "com.baidu.searchbox.SplashActivity" to be focused
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "dumpsys window windows"
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "getprop ro.build.version.release"
> info: [debug] Device is at release version 7.1.1
> info: [debug] Device launched! Ready for commands
> info: [debug] Setting command timeout to the default of 60 secs
> info: [debug] Appium session started with sessionId 7cd626ca-ac3a-47ac-8b57-1ad0bec3a124
> info: <-- POST /wd/hub/session 303 37250.642 ms - 74 
> info: --> GET /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124 {"capabilities":{"firstMatch":[{"appium:appActivity":"com.baidu.searchbox.SplashActivity","appium:app":"D:\\Process\\BaiDu.apk","appium:deviceName":"K51LHP1782600106","appium:platformVersion":"6.0","appium:appPackage":"com.baidu.searchbox","platformName":"Android"}]},"desiredCapabilities":{"deviceName":"K51LHP1782600106","app":"D:\\Process\\BaiDu.apk","platformVersion":"6.0","appPackage":"com.baidu.searchbox","platformName":"Android","appActivity":"com.baidu.searchbox.SplashActivity"}}
> info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"7.1.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"deviceName":"K51LHP1782600106","app":"D:\\Process\\BaiDu.apk","platformVersion":"6.0","appPackage":"com.baidu.searchbox","platformName":"Android","appActivity":"com.baidu.searchbox.SplashActivity"},"deviceName":"K51LHP1782600106","app":"D:\\Process\\BaiDu.apk","appPackage":"com.baidu.searchbox","platformName":"Android","appActivity":"com.baidu.searchbox.SplashActivity"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- GET /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124 200 6.718 ms - 701 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"7.1.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"deviceName":"K51LHP1782600106","app":"D:\\Process\\BaiDu.apk","platformVersion":"6.0","appPackage":"com.baidu.searchbox","platformName":"Android","appActivity":"com.baidu.searchbox.SplashActivity"},"deviceName":"K51LHP1782600106","app":"D:\\Process\\BaiDu.apk","appPackage":"com.baidu.searchbox","platformName":"Android","appActivity":"com.baidu.searchbox.SplashActivity"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element {"using":"name","sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","value":"鍚屾剰騫剁戶緇?}
> warn: [DEPRECATED] The name locator strategy has been deprecated and will be removed.  Please use the accessibility id locator strategy instead.
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"鍚屾剰騫剁戶緇?,"context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"鍚屾剰騫剁戶緇?,"context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding 鍚屾剰騫剁戶緇?using NAME with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=鍚屾剰騫剁戶緇? INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=鍚屾剰騫剁戶緇? INSTANCE=0]
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element 200 68.470 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/1/click {"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","id":"1"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"1"}]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"1"}}
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/1/click 200 2325.161 ms - 76 {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element {"using":"id","sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","value":"com.baidu.searchbox:id/baidu_searchbox"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.baidu.searchbox:id/baidu_searchbox","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.baidu.searchbox:id/baidu_searchbox","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding com.baidu.searchbox:id/baidu_searchbox using ID with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.baidu.searchbox:id/baidu_searchbox]
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element 200 54.301 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"2"}}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/2/click {"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","id":"2"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"2"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/2/click 200 596.189 ms - 76 {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element {"using":"id","sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","value":"com.baidu.searchbox:id/SearchTextInput"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.baidu.searchbox:id/SearchTextInput","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.baidu.searchbox:id/SearchTextInput","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding com.baidu.searchbox:id/SearchTextInput using ID with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.baidu.searchbox:id/SearchTextInput]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"3"}}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"3"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element 200 720.191 ms - 87 {"status":0,"value":{"ELEMENT":"3"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/3/click {"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","id":"3"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"3"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"3"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/3/click 200 936.165 ms - 76 {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element {"using":"id","sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","value":"com.baidu.searchbox:id/SearchTextInput"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.baidu.searchbox:id/SearchTextInput","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.baidu.searchbox:id/SearchTextInput","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding com.baidu.searchbox:id/SearchTextInput using ID with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.baidu.searchbox:id/SearchTextInput]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"4"}}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"4"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element 200 50.852 ms - 87 {"status":0,"value":{"ELEMENT":"4"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/4/value {"text":"demo","sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","id":"4","value":["d","e","m","o"]}
> info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"4","text":"demo","replace":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"4","text":"demo","replace":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: setText
> info: [debug] [BOOTSTRAP] [debug] Using element passed in.
> info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
> info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to be hint text.
> info: [debug] [BOOTSTRAP] [debug] Text not cleared. Assuming remainder is hint text.
> info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: demo
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/4/value 200 5589.128 ms - 76 {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element {"using":"name","sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","value":"鐧懼害涓€涓?}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"鐧懼害涓€涓?,"context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"鐧懼害涓€涓?,"context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding 鐧懼害涓€涓?using NAME with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=鐧懼害涓€涓? INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=鐧懼害涓€涓? INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"5"}}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"5"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element 200 246.279 ms - 87 {"status":0,"value":{"ELEMENT":"5"},"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: --> POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/5/click {"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124","id":"5"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"5"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"5"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: <-- POST /wd/hub/session/7cd626ca-ac3a-47ac-8b57-1ad0bec3a124/element/5/click 200 409.808 ms - 76 {"status":0,"value":true,"sessionId":"7cd626ca-ac3a-47ac-8b57-1ad0bec3a124"}
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] Didn't get a new command in 60 secs, shutting down...
> info: Shutting down appium session
> info: [debug] Pressing the HOME button
> info: [debug] executing cmd: C:\DEV\AndroidStudio-sdk-tools\platform-tools\adb.exe -s K51LHP1782600106 shell "input keyevent 3"
> 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] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
> info: [debug] [UIAUTOMATOR STDOUT] close [socket][::/:::4724]
> 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: 89.374
> 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
> info: [debug] We shut down because no new commands came in

在手機端,我們來看下手機端的界面操作:

 

 

 

OK,Appium第一條腳本的編寫和運行,到此處結束啦,後續將持續更新。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章