WebDriverAgent 是什么

 

去年的 SeleniumConf 上,Facebook 推出了一款新的iOS移动测试框架 —— WebDriverAgent,当时的推文上,写的还只支持模拟器。半年过过去了,如今在看官方github —— https://github.com/facebook/WebDriverAgent,已经宣称支持真机测试了(亲测的确支持)。我把它的 ReadMe 搬运过来:

WebDriverAgent 在 iOS 端实现了一个 WebDriver server ,借助这个 server 我们可以远程控制 iOS 设备。你可以启动、杀死应用,点击、滚动视图,或者确定页面展示是否正确。This makes it a perfect tool for application end-to-end testing or general purpose device automation.(它说它是iOS上一个完美的e2e的自动化解决方案) It works by linking XCTest.framework and calling Apple's API to execute commands directly on a device.(链接XCTest.framework调用苹果的API直接在设备上执行命令) WebDriverAgent is developed and used at Facebook for end-to-end testing and is successfully adopted by Appium. (Appium封装工作正在进行中,如果一旦封装好,那么以后就可以直接用Appium提供的binding了。)It is currently maintained by Marek Cirkos and Mehdi Mulani.

它有如下特性:

  • 真机和模拟器都支持
  • 实现了大部分的 WebDriver spec
  • USB support for devices,所谓的usb支持,指的是设备不需要上网,目前client binding 还没有。
  • 提供了一个 Inspector
  • Easy development cycle as it can be launched & debugged directly via Xcode
  • Unsupported yet, but works with tvOS & OSX

 

WebDriverAgent 的使用

To get the project set up just run bootstrap script:

./Scripts/bootstrap.sh

It will:

  • fetch all dependencies with Carthage
  • build Inspector bundle using npm

After it is finished you can simply open WebDriverAgent.xcodeproj and start WebDriverAgentRunner test and start sending requests.

More about how to start WebDriverAgent here.

官方的文档讲的很清晰,基本没有什么坑。Carthage 是用来解决 xcode project 依赖的,大家可能知道 cocoapod,那你就把 Carthage 理解成和 cocoapod 一样的东西就可以了,可以通过 brew install carthage 安装。npm 是用来构建 Inspector, Inspector 是一个 react 的应用,通过往 WebDriverAgent 发 HTTP 请求,返回页面的结构。

下面是我运行 ./Scripts/bootstrap.sh 的结果:

➜  WebDriverAgent git:(master) ./Scripts/bootstrap.sh
Fetching dependencies
*** Checking out KissXML at "5.0.3"
*** Checking out peertalk at "5a0495a7b7d81b68e25ea1933c755b677cb040da"
*** Checking out RoutingHTTPServer at "v1.0.0"
*** Downloading ocmock.framework binary at "OCMock 3.2.2"
*** Checking out ocmock at "v3.2.2"
*** xcodebuild output can be found in /var/folders/11/wh7ypz2s7q17lxxjphxd4z6h0000gn/T/carthage-xcodebuild.XhkH5T.log
*** Building scheme "OCMock iOS" in OCMock.xcodeproj
2016-05-14 17:45:36.012 xcodebuild[14231:270807] [MT] DVTPlugInManager: Required plug-in compatibility UUID ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C for KSImageNamed.ideplugin (com.ksuther.KSImageNamed) not present
2016-05-14 17:45:36.159 xcodebuild[14231:270807] [MT] PluginLoading: Required plug-in compatibility UUID ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-05-14 17:45:36.160 xcodebuild[14231:270807] [MT] PluginLoading: Required plug-in compatibility UUID ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-05-14 17:45:46.318 xcodebuild[14494:271598] [MT] DVTPlugInManager: Required plug-in compatibility UUID ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C for KSImageNamed.ideplugin (com.ksuther.KSImageNamed) not present
2016-05-14 17:45:46.376 xcodebuild[14494:271598] [MT] PluginLoading: Required plug-in compatibility UUID ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-05-14 17:45:46.377 xcodebuild[14494:271598] [MT] PluginLoading: Required plug-in compatibility UUID ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
Building Inspector
Creating bundle directory...
Building inspector.js... > web-driver-inspector@1.0.0 build /Users/lihuazhang/code/WebDriverAgent/Inspector
> webpack --progress --colors Hash: 536587fce0cad79f8558
Version: webpack 1.12.2
Time: 2794ms
Asset Size Chunks Chunk Names
inspector.js 706 kB 0 [emitted] main
[0] multi main 28 bytes {0} [built]
+ 182 hidden modules
Done
➜ WebDriverAgent git:(master)

build 好之后就是启动 WebDriverAgent,官方提供了四种方式:

  1. 使用 XCode

  2. 用 xcodebuild

  3. Using fbsimctl from FBSimulatorControl framework

  4. Using FBSimulatorControl framework directly

我使用 XCode (如果自动化的话,可以使用 xcodebuild),打开 WebDriverAgent.xcodeproj,IDE 的显示是这样的:

 

先不要纠结其他,我们只看 UITestingUITests.m,这是一个 XCTestCase 的实现类,我们直接运行,真机或者模拟器都可以。我用的模拟器,运行之后,会在模拟器安装一个 WebDriverAgentRunner 的应用。我们看下运行的日志:

2016-05-15 01:19:43.019 XCTRunner[29300:524372] Running tests...
01:19:43.218 XCTRunner[29300:524495] _XCT_testBundleReadyWithProtocolVersion:minimumVersion: reply received
01:19:43.228 XCTRunner[29300:524495] _IDE_startExecutingTestPlanWithProtocolVersion:16
2016-05-15 01:19:44.732 XCTRunner[29300:524372] Continuing to run tests in the background with task ID 1
Test Suite 'Selected tests' started at 2016-05-15 01:19:45.319
Test Suite 'UITestingUITests' started at 2016-05-15 01:19:45.322
Test Case '-[UITestingUITests testRunner]' started.
2016-05-15 01:19:45.323 XCTRunner[29300:524372] -[_XCTestDriverTestObserver testCaseWillStart:] UITestingUITests testRunner
t = 0.00s Start Test
2016-05-15 01:19:45.324 XCTRunner[29300:524372] -[UITestingUITests testRunner] started activity <XCActivityRecord: 0x7f8acb721660> 2016-05-14 17:19:45 +0000: Start Test
2016-05-15 01:19:45.327 XCTRunner[29300:524372] -[UITestingUITests testRunner] finished activity <XCActivityRecord: 0x7f8acb721660> 2016-05-14 17:19:45 +0000: Start Test (0.00271106s)
t = 0.01s Set Up
2016-05-15 01:19:45.328 XCTRunner[29300:524372] -[UITestingUITests testRunner] started activity <XCActivityRecord: 0x7f8acb7219e0> 2016-05-14 17:19:45 +0000: Set Up
2016-05-15 01:19:45.330 XCTRunner[29300:524372] -[UITestingUITests testRunner] finished activity <XCActivityRecord: 0x7f8acb7219e0> 2016-05-14 17:19:45 +0000: Set Up (0.00130302s)
2016-05-15 01:19:45.331 XCTRunner[29300:524372] Built at May 15 2016 01:19:32
2016-05-15 01:19:45.386 XCTRunner[29300:524372] ServerURLHere->http://192.168.0.105:8100<-ServerURLHere
2016-05-15 01:19:45.386 XCTRunner[29300:524372] Listening on USB

关键字是:

2016-05-15 01:19:45.386 XCTRunner[29300:524372] ServerURLHere->http://192.168.0.105:8100<-ServerURLHere

这个意思是告诉我们,设备中起了一个服务器,我们可以用 http://192.168.0.105:8100 访问到。下面就是在浏览器打开返回的内容:

{
value: "Unhandled endpoint: / -- http://192.168.0.105:8100/ with parameters { wildcards = ( "" ); }",
sessionId: null,
status: 1
}

通道找到了,接下来就是看如何造请求了。官方问题提供了文档:https://github.com/facebook/WebDriverAgent/wiki/Queries。最简单的 statushttp://192.168.0.105:8100/status

{
value: {
state: "success",
os: {
name: "iPhone OS",
version: "9.3"
},
ios: {
simulatorVersion: "9.3"
},
build: {
time: "May 15 2016 01:19:33"
}
},
sessionId: null,
status: 0
}

其他的 API 有兴趣的人可以直接看文档。

服务端有了,就剩下客户端了,但是目前为止没有一个官方的客户端binding,Facebook 的同学没有放出来,看这个issue——https://github.com/facebook/WebDriverAgent/issues/115

 

所以目前为止如果要使用 WebDriverAgent 就要自己实现一套客户端代码。

WebDriverAgent Inspector 的使用

直接在浏览器端打开 http://192.168.0.105:8100/inspector,就可以看见如下界面:

 

inspector 不是很强大,无法实现交互,不过大致能帮大家定位元素。

WebDriverAgent 简单原理

 

总结

WebDriverAgent 取代 UIAutomation 或者 XCUITesting 做为 Appium 底部驱动看来是时间问题了。原因如下:

  1. 支持真机和模拟器

  2. 不受 instruments 单实例的限制

  3. Facebook 出品

转自:https://testerhome.com/topics/4904

iOS 测试 WebDriverAgent 简介的更多相关文章

  1. 使用appium进行ios测试,启动inspector时遇到的问题(一)

    最近在公司,让做ios的自动化测试,因为以前做过android的自动化测试,用的也是appium,觉得没什么,结果一开始在搭建环境就遇到了很多的问题,现在将我遇到的问题,以及解决方法,给大家分享出来. ...

  2. 如何利用Pre.im分发iOS测试包

    大众创新万众创业,在移动互联网的风口,移动APP开发与测试发展方兴未艾,受到了越来越多的重视.相较 iOS,Android 的开发环境更加开放.Android 开发者要测试应用时,只需发个 APK 安 ...

  3. sysbench压力测试工具简介和使用(一)

    sysbench压力测试工具安装和参数介绍 一.sysbench压力测试工具简介: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据 ...

  4. iOS系统版本简介

    iOS系统版本简介 ⽬目前iOS设备所⽀支持的最主流操作系统是iOS6,⼤大概占了93%,⽽而使 ⽤用iOS5的iOS设备⼤大概占6%,剩下的只有1%.( 根据苹果的官⽅方数据 ) 从iOS1到现在的 ...

  5. IOS NSInvocation用法简介

    IOS NSInvocation用法简介 2012-10-25 19:59 来源:博客园 作者:csj007523 字号:T|T [摘要]在 iOS中可以直接调用某个对象的消息方式有两种,其中一种就是 ...

  6. 【读书笔记】iOS-软件测试与iOS测试

    一,软件测试的类型. 1.软件测试按照测试类型,可以划分为:单元测试,集成测试和系统测试. 2.单元测试是指对软件系统中最小可测试单元进行的检查和验证. 3.集成测试,在iOS软件开发中,集成测试主要 ...

  7. 004-restful应用构建、分布式会话、测试工具简介

    一.概述 什么是rest(表述性状态转移,Representational State Transfer)是一种架构风格.他定义了创建可扩展Web服务的最佳实践. 1.Richardson成熟度模型 ...

  8. iOS测试中发现一个textview控制,使用clear()无法清除文字

    iOS测试中发现一个textview控制,使用clear()无法清除

  9. iOS 测试在应用发布前后的痛点探索以及解决方案

    作者-芈 峮 前言 iOS 开发从 2010 年开始在国内不断地升温,开发和测试相关的问题不绝于耳.iOS 测试主要涉及哪些内容?又有哪些挑战呢?带着疑问我们开始第一个大问题的讨论. iOS 测试的范 ...

随机推荐

  1. Haskell路线

    @ 知乎 @ <I wish i have learned haskell> ———— 包括: Ranks, forall, Monad/CPS,  monadic parser, FFI ...

  2. Java集合Map基本方法

    jdk1.7 api中的方法摘要: 参考java集合大全图:https://www.cnblogs.com/xkzhangsanx/p/10889114.html Map为所有Map子类的接口.

  3. python高级编程——网络编程(二)

    UDP 概念和介绍 UDP --- 用户数据报协议,是一个无连接的简单的面向数据报的运输层协议. UDP不提供可靠性,它只是把应用程序传给IP层的数据报发送出去,但是并 不能保证它们能到达目的地. U ...

  4. python高级编程——线程和线程池

    线程模块           线程的特点:                本质上是异步的.需要多个并发活动.每个活动的处理顺序可能是不确定的.或者说是随机的,不可预测的,宏观上是同时运行的       ...

  5. QT在Mac OS上编译运行初体验

    QT是一个跨平台的框架,支持PC端(Windows.Linux和Mac OS)以及移动端(Android和IOS),之前的开发大都在Windows或者Ubuntu上,考虑到项目多平台支持性,本文对Ma ...

  6. cs1.6 人物地址查询

    打开游戏 控制台命令 增加一个BOT:bot_add 增加一个警察:bot_add_ct 增加一个匪徒:bot_add_t 让BOT站在原地不动:bot_stop 1 "-"减号: ...

  7. CentOS7升级内核kernel5.0

    升级过程: 原系统:CentOS7.3 [root@my-e450 ~]# uname -r3.10.0-514.el7.x86_64 安装必需的软件包: # yum update# yum inst ...

  8. Django模板技术

    Django模板技术 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.模板概述 1>.模板的作用 如果使用react实现前端页面,其实Django就没有必须使用模板,它其 ...

  9. Ningx的基本使用

    Ningx的基本使用   user www; worker_processes 2; error_log logs/error.log info; pid logs/nginx.pid;   even ...

  10. Hadoop 学习资料

    Hadoop 学习资料 网址 官方文档 https://hadoop.apache.org/docs/r1.0.4/cn/index.html 版本文档索引 http://hadoop.apache. ...