本文日志為在IOS模擬器上進(jìn)行的測(cè)試
在appium服務(wù)端中漫仆,日志分為log.info和log.debug 一般每個(gè)文件夾下面都有l(wèi)ogger.js 該js中規(guī)定當(dāng)前l(fā)og格式诵肛。
info為基礎(chǔ)信息
debug可以看做為調(diào)試信息据悔。
本篇為初步分析创坞,后來(lái)對(duì)日志又進(jìn)行了更細(xì)致的斷點(diǎn)查找尔艇,待整理桨仿,如有錯(cuò)誤還請(qǐng)指出
假如日志前面打印出的[Appium][XUCITES]等,根據(jù)該名字可以查到日志來(lái)源于哪個(gè)文件夾下谎痢,[debug][MJSONWP]代表當(dāng)前是采用log.debug方式打印日志磕昼,且日志來(lái)源于appium-base-driver/mjsonwp
的文件夾
第一部分 啟動(dòng)服務(wù)并創(chuàng)建sessionID
appium啟動(dòng):
[Appium] Welcome to Appium v1.7.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
客戶端發(fā)送http請(qǐng)求,并傳遞配置參數(shù)
[HTTP] --> POST /wd/hub/session {"capabilities":{"alwaysMatch":{"platformName":"iOS"},"firstMatch":[{}]},"desiredCapabilities":{"platformVersion":"11.2","deviceName":"iPhone 6s","app":"/Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app","platformName":"iOS"}}
[MJSONWP]為來(lái)自于appium服務(wù)端中封裝好的類庫(kù)appium-base-driver
中mjsonwp文件夾下的mjsonwp.js节猿,一般用于server端的交互票从,包括處理HTTP的請(qǐng)求,session會(huì)話的創(chuàng)建刪除沐批。以下為創(chuàng)建Session
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"platformVersion":"11.2","deviceName":"iPhone 6s","app":"/Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app","platformName":"iOS"},null,{"alwaysMatch":{"platformName":"iOS"},"firstMatch":[{}]}]
[BaseDriver]日志來(lái)源于appium-base-driver/basedriver
文件夾纫骑。
下面日志主要用于打印整個(gè)appium中的事件觸發(fā),所有的請(qǐng)求都會(huì)觸發(fā)各種類下的executeCommand
函數(shù)九孩,而這些函數(shù)全部繼承driver.js中的WebDriver先馆,所以所有的請(qǐng)求都會(huì)打印出driver.js
中的logHistory。
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1516514435268 (14:00:35 GMT+0800 (CST))
[Appium]日志來(lái)源于lib
文件夾下
[Appium] Merged W3C capabilities {"alwaysMatch":{"platformName":"iOS"},"firstMat... into desiredCapabilities object {"platformVersion":"11.2","deviceName":"iPhone ...
[Appium] Requested iOS support with version >= 10, using XCUITest driver instead of UIAutomation-based driver, since the latter is unsupported on iOS 10 and up.
[Appium] Creating new XCUITestDriver (v2.64.0) session
[Appium] Capabilities:
[Appium] platformVersion: 11.2
[Appium] deviceName: iPhone 6s
[Appium] app: /Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app
[Appium] platformName: iOS
[BaseDriver]打印出當(dāng)前sessionId創(chuàng)建成功躺彬,來(lái)源于appium-base-driver/basedriver/session.js
文件煤墙。
- creatSession跳轉(zhuǎn)過(guò)程說(shuō)明:
創(chuàng)建creatSession路線:mjsonwp.js-》appium.js中的createSession-》跳轉(zhuǎn)到XCUITEST中的createSession-》跳轉(zhuǎn)到appium-base-driver/basedriver/driver.js中的creatSession - 如何聯(lián)系起了XCUITest?
通過(guò)appium.js中的curSessionDataForDriver(InnerDriver)
宪拥,當(dāng)判斷出當(dāng)前是什么系統(tǒng)配置時(shí)仿野,InnerDriver此時(shí)已變成IOS或者Android的Driver
[BaseDriver] Session created with session id: 8790f1db-9627-41ce-a534-bc40159c7194
當(dāng)創(chuàng)建SessionID之后,此時(shí)進(jìn)入的是appium-xcuitest-driver
類庫(kù)中她君。
[debug] [XCUITest] Current user: '用戶名'
[debug] [XCUITest] Current version of libimobiledevice: stable 1.2.0 (bottled), HEAD
[debug] [XCUITest] Xcode version set to '9.2' (tools v9.2.0.0.1.1510905681)
[debug] [XCUITest] iOS SDK Version set to '11.2'
來(lái)自于appium-base-driver/basedriver/driver.js
中的logHistory函數(shù)
[debug] [BaseDriver] Event 'xcodeDetailsRetrieved' logged at 1516514436354 (14:00:36 GMT+0800 (CST))
[iOSSim]來(lái)自于appium-ios-simulator
的日志脚作,接下來(lái)都是在IOS檢測(cè)模擬器,判斷APP缔刹,安裝APP的操作
[iOSSim] Constructing iOS simulator for Xcode version 9.2 with udid '2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5'
[XCUITest] Determining device to run tests on: udid: '2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5', real device: false
[BaseDriver] Using local app '/Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app'
[debug] [BaseDriver] Event 'appConfigured' logged at 1516514436692 (14:00:36 GMT+0800 (CST))
[debug] [XCUITest] Checking whether app '/Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app' is actually present on file system
[debug] [XCUITest] App is present
[debug] [iOS] Getting bundle ID from app '/Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app': 'io.appium.TestApp'
[debug] [BaseDriver] Event 'resetStarted' logged at 1516514436695 (14:00:36 GMT+0800 (CST))
[XCUITest] Not scrubbing third party app in anticipation of uninstall
[debug] [BaseDriver] Event 'resetComplete' logged at 1516514436881 (14:00:36 GMT+0800 (CST))
[debug] [XCUITest] Starting log capture for iOS Simulator with udid '2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5', using 'xcrun simctl spawn 2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5 log stream --style compact'
[debug] [BaseDriver] Event 'logCaptureStarted' logged at 1516514437312 (14:00:37 GMT+0800 (CST))
[XCUITest] Setting up simulator
[debug] [iOS] No reason to set locale
[debug] [iOS] No iOS / app preferences to set
[debug] [iOSSim] Matched 1 Simulator cache item for cleanup: /Users/用戶名/Library/Developer/CoreSimulator/Devices/2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5/data/Library/Caches/com.apple.mobile.installd.staging
[debug] [iOSSim] Setting common Simulator preferences to {"ConnectHardwareKeyboard":false}
[debug] [iOSSim] Updated 2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5 Simulator preferences at '/Users/用戶名/Library/Preferences/com.apple.iphonesimulator.plist' with {"ConnectHardwareKeyboard":false}
[debug] [iOSSim] The count of running Simulator UI client instances is 1
[iOSSim] Both Simulator with UDID 2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5 and the UI client are currently running
[debug] [BaseDriver] Event 'simStarted' logged at 1516514437783 (14:00:37 GMT+0800 (CST))
[debug] [XCUITest] Reset requested. Removing app with id 'io.appium.TestApp' from the device
[debug] [XCUITest] Installing '/Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app' on Simulator with UUID '2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5'...
[debug] [XCUITest] The app has been installed successfully.
[debug] [BaseDriver] Event 'appInstalled' logged at 1516514440337 (14:00:40 GMT+0800 (CST))
APP安裝成功之后開(kāi)始處理WDA
[XCUITest] Using WDA path: '/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent'
[XCUITest] Using WDA agent: '/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj'
[debug] [XCUITest] No obsolete cached processes from previous WDA sessions listening on port 8100 have been found
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\n \"value\" : {\n \"state\" : \"success\",\n \"os\" : {\n \"name\" : \"iOS\",\n \"version\" : \"11.2\",\n \"sdkVersion\" : \"11.2\"\n },\n \"ios\" : {\n \"simulatorVersion\" : \"11.2\",\n \"ip\" : \"192.168.0.102\"\n },\n \"build\" : {\n \"time\" : \"Jan 14 2018 23:25:10\"\n }\n },\n \"sessionId\" : \"17DE3FB9-3196-4C9C-9D55-3BFFDD0C1DEB\",\n \"status\" : 0\n}"
[XCUITest] Will reuse previously cached WDA instance at 'http://localhost:8100/'. Set the wdaLocalPort capability to a value different from 8100 if this is an undesired behavior.
[debug] [BaseDriver] Event 'wdaStartAttempted' logged at 1516514440422 (14:00:40 GMT+0800 (CST))
[XCUITest] Using provided WebdriverAgent at 'http://localhost:8100/'
[debug] [BaseDriver] Event 'wdaSessionAttempted' logged at 1516514440423 (14:00:40 GMT+0800 (CST))
[debug] [XCUITest] Sending createSession command to WDA
在XCUITest中開(kāi)啟WDA之后球涛,此時(shí)鏈接的request和response進(jìn)入了 appium-base-driver/lib/jsonwp-proxyproxy.js
,這個(gè)js主要是做S/D的鏈接校镐,即server服務(wù)端與devices設(shè)備的鏈接
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\n \"value\" : {\n \"state\" : \"success\",\n \"os\" : {\n \"name\" : \"iOS\",\n \"version\" : \"11.2\",\n \"sdkVersion\" : \"11.2\"\n },\n \"ios\" : {\n \"simulatorVersion\" : \"11.2\",\n \"ip\" : \"192.168.0.102\"\n },\n \"build\" : {\n \"time\" : \"Jan 14 2018 23:25:10\"\n }\n },\n \"sessionId\" : \"17DE3FB9-3196-4C9C-9D55-3BFFDD0C1DEB\",\n \"status\" : 0\n}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"io.appium.TestApp","arguments":[],"environment":{},"shouldWaitForQuiescence":true,"shouldUseTestManagerForVisibilityDetection":false,"maxTypingFrequency":60,"shouldUseSingletonTestManager":true}}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"sessionId":"95403F32-CD9B-4A0E-AA89-4BE9C899FBBC","capabilities":{"device":"iphone","browserName":"TestApp","sdkVersion":"11.2","CFBundleIdentifier":"io.appium.TestApp"}},"sessionId":"95403F32-CD9B-4A0E-AA89-4BE9C899FBBC","status":0}
[debug] [BaseDriver] Event 'wdaSessionStarted' logged at 1516514443103 (14:00:43 GMT+0800 (CST))
[debug] [BaseDriver] Event 'wdaStarted' logged at 1516514443103 (14:00:43 GMT+0800 (CST))
[XCUITest] Skipping setting of the initial display orientation. Set the "orientation" capability to either "LANDSCAPE" or "PORTRAIT", if this is an undesired behavior.
[debug] [BaseDriver] Event 'orientationSet' logged at 1516514443103 (14:00:43 GMT+0800 (CST))
上邊WDA開(kāi)啟完畢亿扁,session創(chuàng)建成功,這個(gè)session的創(chuàng)建過(guò)程是從
mjsonwp.js(HTTP請(qǐng)求入口)-》appium.js中的createSession-》跳轉(zhuǎn)到XCUITEST中的createSession-》跳轉(zhuǎn)到appium-base-driver/basedriver/driver.js中的creatSession 創(chuàng)建成功之后回到了appium.js中將log打印鸟廓,最后回到了mjsonwp.js將response返回并通知从祝。
[Appium] New XCUITestDriver session created successfully, session 8790f1db-9627-41ce-a534-bc40159c7194 added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1516514443104 (14:00:43 GMT+0800 (CST))
[debug] [MJSONWP] Responding to client with driver.createSession() result: {"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"networkConnectionEnabled":false,"platformVersion":"11.2","deviceName":"iPhone 6s","app":"/Users/用戶名/Documents/github/python-client-master/appium/TestApp/build/release-iphonesimulator/TestApp-iphonesimulator.app","platformName":"iOS","udid":"2EF911A2-CA9C-4D28-96EB-3DBC8DF39FA5"}
[HTTP] <-- POST /wd/hub/session 200 7841 ms - 515
第二部分 發(fā)送操作請(qǐng)求執(zhí)行并返回
客戶端傳來(lái)請(qǐng)求獲取element,該請(qǐng)求進(jìn)入mjsonwp.js進(jìn)行處理引谜,通過(guò)executeCommand函數(shù)進(jìn)入appium.js 進(jìn)入appium-xcuitest-driver‘類庫(kù) 與JSONWP Proxy[appium-base-driver/lib/jsonwp/proxy.js]進(jìn)行協(xié)議交互 交互結(jié)果返回MJSONWP[appium-base-driver/lib/mjsonwp/mjsonwp.js]
[HTTP] --> POST /wd/hub/session/8790f1db-9627-41ce-a534-bc40159c7194/element {"using":"accessibility id","sessionId":"8790f1db-9627-41ce-a534-bc40159c7194","value":"TextField1"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["accessibility id","TextField1","8790f1db-9627-41ce-a534-bc40159c7194"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/95403F32-CD9B-4A0E-AA89-4BE9C899FBBC/element] with body: {"using":"accessibility id","value":"TextField1"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"A3063789-1A9E-4FA2-A645-F2E257F0BB30"},"sessionId":"95403F32-CD9B-4A0E-AA89-4BE9C899FBBC","status":0}
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"A3063789-1A9E-4FA2-A645-F2E257F0BB30"}
[HTTP] <-- POST /wd/hub/session/8790f1db-9627-41ce-a534-bc40159c7194/element 200 83 ms - 122
客戶端再次傳來(lái)請(qǐng)求牍陌,以下都是重復(fù)請(qǐng)求與返回,直到客戶端傳來(lái)刪除會(huì)話员咽。
當(dāng)客戶端單個(gè)任務(wù)執(zhí)行完畢時(shí)毒涧,客戶端傳來(lái)刪除會(huì)話,通訊與其它沒(méi)有什么差別骏融。
[HTTP] --> DELETE /wd/hub/session/5469f63c-9b2b-4a3a-bbdb-fa26bd6315f9 {}
[debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: ["5469f63c-9b2b-4a3a-bbdb-fa26bd6315f9"]
[debug] [BaseDriver] Event 'quitSessionRequested' logged at 1516514455122 (14:00:55 GMT+0800 (CST))
[Appium] Removing session 5469f63c-9b2b-4a3a-bbdb-fa26bd6315f9 from our master session list
[debug] [JSONWP Proxy] Proxying [DELETE /session/5469f63c-9b2b-4a3a-bbdb-fa26bd6315f9] to [DELETE http://localhost:8100/session/E9944FDA-46DC-48B4-824B-A2C99D0B3BD2] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\n \"value\" : {\n\n },\n \"sessionId\" : \"334D0B8A-6B9E-4BAA-9BDA-BFEE66EBB584\",\n \"status\" : 0\n}"
[debug] [XCUITest] Not clearing log files. Use `clearSystemFiles` capability to turn on.
[debug] [iOSLog] Stopping iOS log capture
[debug] [BaseDriver] Event 'quitSessionFinished' logged at 1516514455352 (14:00:55 GMT+0800 (CST))
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning
[debug] [MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/5469f63c-9b2b-4a3a-bbdb-fa26bd6315f9 200 231 ms - 76