iOS 系统UI自动化测试介绍(5)

发表于:2016-11-15来源:简书作者:孢子菌点击数: 标签:自动化测试
, status : 0 }[MJSONWP] Responding to client with driver.findElements() result : [{ ELEMENT : 1A29AE60-5433-4B52-83F8-B4E2C794972E , type : XCUIElementTypeTextField , label : TextField1 },{ ELEMENT :
,"status":0} [MJSONWP] Responding to client with driver.findElements() result: [{"ELEMENT":"1A29AE60-5433-4B52-83F8-B4E2C794972E","type":"XCUIElementTypeTextField","label":"TextField1"},{"ELEMENT":"575EE2C2-4AFF-4320-B4D0-C30F59410DA9","type":"XCUIElementTypeTextField","label":"TextField2"}] // server ----http----> client [HTTP] <-- POST /wd/hub/session/94f7526c-94ba-4ece-8740-d94bd3d4f50f/elements 200 225 ms - 285

其中
[MJSONWP] 打印的是S内部的处理日志。

[JSONWP Proxy] 打印的是S/D之间的通信日志。

可以看到,Client、Server、Device是通过Http协议通信的,大致流程为:
Client通过http协议,将指定格式的命令发送给server。server调用中间层AppiumDriver解析命令,发送给实际的处理者。实际处理者依据平台、版本不同而不一样,这里是XCUITest(iOS)。而Device(iphone、模拟器)和Server的通讯也是通过http协议。

到这里,大家会有疑问了,Server怎么找到对应的Device,他们之间如何通过Http通讯的?这里就要引出WebDriverAgent。它的作用:

WebDriverAgent 在 iOS 端实现了一个 WebDriver server ,借助这个 server 我们可以远程控制 iOS 设备。
参考

WDA的inspector演示:直接在浏览器端打开 http://192.168.0.105:8100/inspector

TextField赋值

再看TextField赋值java代码elem.sendKeys(String.valueOf(rndNum));的执行步骤

[HTTP] --> POST /wd/hub/session/94f7526c-94ba-4ece-8740-d94bd3d4f50f/element/1A29AE60-5433-4B52-83F8-B4E2C794972E/value {"id":"1A29AE60-5433-4B52-83F8-B4E2C794972E","value":["1"]}

[MJSONWP] Calling AppiumDriver.setValue() with args: [["1"],"1A29AE60-5433-4B52-83F8-B4E2C794972E","94f7526c-94ba-4ece-8740-d94bd3d4f50f"]
[debug] [XCUITest] Executing command 'setValue'

[JSONWP Proxy] Proxying [GET /element/1A29AE60-5433-4B52-83F8-B4E2C794972E/attribute/type] to [GET http://localhost:8100/session/79CBBB84-DB6E-48BA-B79F-91539E1E4708/element/1A29AE60-5433-4B52-83F8-B4E2C794972E/attribute/type] with no body
[JSONWP Proxy] Got response with status 200: "{\n  \"value\" : \"XCUIElementTypeTextField\",\n  \"sessionId\" : \"79CBBB84-DB6E-48BA-B79F-91539E1E4708\",\n  \"status\" : 0\n}"
[debug] [BaseDriver] Set implicit wait to 0ms
[debug] [BaseDriver] Waiting up to 0 ms for condition
[JSONWP Proxy] Proxying [POST /element] to [ 



           

原文转自:http://www.jianshu.com/p/aae160cb9cc4

...