iOS test WebDriverAgent Profile

What is WebDriverAgent

 

 

 

Last year's SeleniumConf, Facebook launched a new iOS mobile testing framework - WebDriverAgent, the time of the tweet, written also only supports the simulator. Six months had passed, and now look at the official GitHub -  https://github.com/facebook/WebDriverAgent , it has claimed support real test of the (pro-test does support). I put it in the ReadMe carry over:

WebDriverAgent at the end iOS implements a  WebDriver server  , we can help this server remote control iOS devices. You can start, kill applications, click, scroll view, or to determine whether the correct page display. This makes it a perfect tool for application end-to-end testing or general purpose device automation. ( It says it is on iOS a perfect e2e automation solutions) It Works by Linking  XCTest.framework and Calling the Apple's API to the Execute Commands Directly ON A device. (link to XCTest.frameworkcall Apple's API commands executed directly on the device) WebDriverAgent iS aT Facebook Developed and Used for End-to-End Testing and iS successfully Adopted by  Appium . (Appium package work in progress, if once the package is good, then since you can directly binding Appium provided a.) it iS Rate this page Currently Maintained by  Marek Cirkos  and  Mehdi Mulani .

It has the following features:

  • Real machine and emulator support
  • Implements most of  WebDriver spec
  • Support the USB  for Devices, the so-called usb support, referring to the devices do not need the Internet, the current client binding yet.
  • It provides an Inspector
  • Easy development cycle as it can be launched & debugged directly via Xcode
  • Unsupported yet, but works with tvOS & OSX

 

 

 

The use 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.

The official document said very clearly, there is little pit. Carthage is used to solve xcode project dependent, you may know  cocoapod , Carthage understand that you put into cocoapod and the same thing can be, can be  brew install carthage installed. npm is used to construct Inspector, Inspector react an application through an HTTP request sent to WebDriverAgent return structure of the page.

Here is my run ./Scripts/bootstrap.sh results:

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)

After a good start is to build WebDriverAgent, official offers four ways:

  1. Use XCode

  2. With xcodebuild

  3. Using fbsimctl from FBSimulatorControl framework

  4. Using FBSimulatorControl framework directly

I'm using XCode (if automated, you can use xcodebuild), open WebDriverAgent.xcodeproj, IDE show is this:

 

 

 

Do not tangle other, we look at  UITestingUITests.m, this is a XCTestCase implementation class, we run directly, or real machine simulator can be. I use the simulator, after running a WebDriverAgentRunner application will be installed in the simulator. We look running log:

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

Keywords are:

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

This mean to tell us that the device from a server, we can  http://192.168.0.105:8100 have access to. Here is what is returned to open the browser:

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

Channel is found, the next step is to see how to make a request. Official issue provides documentation: https://github.com/facebook/WebDriverAgent/wiki/Queries . The simplest  status, http://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
}

Other API who are interested can see the document directly.

服务端有了,就剩下客户端了,但是目前为止没有一个官方的客户端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

 

Guess you like

Origin www.cnblogs.com/kaola8023/p/12077107.html