【Appium】appium通过日志分析服务端执行过程-IOS端

本文日志为在IOS模拟器上进行的测试

在appium服务端中,日志分为log.info和log.debug 一般每个文件夹下面都有logger.js 该js中规定当前log格式。
info为基础信息
debug可以看做为调试信息。
本篇为初步分析,后来对日志又进行了更细致的断点查找,待整理,如有错误还请指出

假如日志前面打印出的[Appium][XUCITES]等,根据该名字可以查到日志来源于哪个文件夹下,[debug][MJSONWP]代表当前是采用log.debug方式打印日志,且日志来源于appium-base-driver/mjsonwp的文件夹

第一部分 启动服务并创建sessionID

appium启动:

[Appium] Welcome to Appium v1.7.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

客户端发送http请求,并传递配置参数

[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]为来自于appium服务端中封装好的类库appium-base-driver中mjsonwp文件夹下的mjsonwp.js,一般用于server端的交互,包括处理HTTP的请求,session会话的创建删除。以下为创建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]日志来源于appium-base-driver/basedriver文件夹。
下面日志主要用于打印整个appium中的事件触发,所有的请求都会触发各种类下的executeCommand函数,而这些函数全部继承driver.js中的WebDriver,所以所有的请求都会打印出driver.js中的logHistory。

[debug] [BaseDriver] Event 'newSessionRequested' logged at 1516514435268 (14:00:35 GMT+0800 (CST))

[Appium]日志来源于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]打印出当前sessionId创建成功,来源于appium-base-driver/basedriver/session.js文件。

  • creatSession跳转过程说明:
    创建creatSession路线:mjsonwp.js-》appium.js中的createSession-》跳转到XCUITEST中的createSession-》跳转到appium-base-driver/basedriver/driver.js中的creatSession
  • 如何联系起了XCUITest?
    通过appium.js中的curSessionDataForDriver(InnerDriver),当判断出当前是什么系统配置时,InnerDriver此时已变成IOS或者Android的Driver
[BaseDriver] Session created with session id: 8790f1db-9627-41ce-a534-bc40159c7194

当创建SessionID之后,此时进入的是appium-xcuitest-driver类库中。

[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'

来自于appium-base-driver/basedriver/driver.js中的logHistory函数

[debug] [BaseDriver] Event 'xcodeDetailsRetrieved' logged at 1516514436354 (14:00:36 GMT+0800 (CST))

[iOSSim]来自于appium-ios-simulator的日志,接下来都是在IOS检测模拟器,判断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安装成功之后开始处理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中开启WDA之后,此时链接的request和response进入了 appium-base-driver/lib/jsonwp-proxyproxy.js ,这个js主要是做S/D的链接,即server服务端与devices设备的链接

[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开启完毕,session创建成功,这个session的创建过程是从

mjsonwp.js(HTTP请求入口)-》appium.js中的createSession-》跳转到XCUITEST中的createSession-》跳转到appium-base-driver/basedriver/driver.js中的creatSession 创建成功之后回到了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

第二部分 发送操作请求执行并返回

客户端传来请求获取element,该请求进入mjsonwp.js进行处理,通过executeCommand函数进入appium.js 进入appium-xcuitest-driver‘类库 与JSONWP Proxy[appium-base-driver/lib/jsonwp/proxy.js]进行协议交互 交互结果返回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

客户端再次传来请求,以下都是重复请求与返回,直到客户端传来删除会话。
当客户端单个任务执行完毕时,客户端传来删除会话,通讯与其它没有什么差别。

[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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,189评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,577评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,857评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,703评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,705评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,620评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,995评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,656评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,898评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,639评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,720评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,395评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,982评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,953评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,195评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,907评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,472评论 2 342

推荐阅读更多精彩内容

  • 写在前面 本文档主要是通过断点跟踪对于appium源码,从而记录的appium服务端的启动过程,如有错误或者理解不...
    进击的程序茗阅读 779评论 0 6
  • 前言 要想深入地掌握任何一门测试工具,对工具本身的架构、原理、使用的协议及相关知识点都必须要有相关的了解和认识,才...
    让技术更俗一点阅读 4,725评论 3 55
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,732评论 6 342
  • 那位大名鼎鼎的台湾罗庆导师,终于见到了!看上去普普通通,但眼神很坚定,时常语出惊人,又老是笑场,有时很严肃认真,大...
    美伊g阅读 1,387评论 1 4
  • 心头的那一抹红,是我的最爱。儿子见到我 们时,神采飞扬地向我们炫耀,他买了一个刻有某人名字的茶器,我们称...
    沁墨m阅读 97评论 0 0