iOS WebDriverAgent 環境搭建
WebDriverAgent簡介
WebDriverAgent是Facebook 在去年的 SeleniumConf 大會上推出了一款新的iOS移動測試框架。當時的推文申明,還只支持模擬器,不過在今年4月更新的版本中,官方宣稱支持真機測試了,大家可以查看官方github 的介紹:https://github.com/facebook/WebDriverAgent
下面摘錄一段官方對於WebDriverAgent的介紹字段:
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。
WebDriverAgent特點
根據官方的資料介紹,WebDriverAgent具有如下特點:
- 真機和模擬器都支持
- 實現了大部分的 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
想要了解更多的資料介紹可以通過下面的鏈接來了解:https://testerhome.com/topics/4904
環境搭建
介紹完WebDriverAgent後,我們來看一下如何在Mac系統上順利編譯出WebDriverAgent。
軟件環境
要搭建WebDriverAgent編譯環境,首先需要安裝如下的軟件:
- Homebrew
- carthage
- python
- node.js
- Xcode8.0+(IOS9.3,Xcode8.0+才能正常編譯)
環境安裝
打開Mac命令行(終端),如下圖所示:
如果你電腦上沒有安裝Homebrew,使用下面的命令安裝:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 1
- 1
如果沒有安裝carthage,使用下面的命令安裝:
brew install carthage
- 1
- 1
當然還可以下載carthage.pkg文件安裝,下載官方地址。
然後按照Python環境。
brew install python
- 1
- 1
安裝Node環境,命令如下:
brew install node
- 1
- 1
基本軟件環境安裝好之後,就需要安裝WebDriverAgent了。
安裝WebDriverAgent
首先,使用git clone命令將WebDriverAgent項目克隆到本地。
git clone https://github.com/facebook/WebDriverAgent
- 1
- 1
下載完畢後,進入到 WebDriverAgent 目錄,執行如下腳本。
- cd ./WebDriverAgent/
- //執行腳本
- ./Scripts/bootstrap.sh
- 1
- 2
- 3
- 1
- 2
- 3
如果出現錯誤,那麽重新打開一個終端, 再輸入一次。該腳本會使用Carthage下載所有的依賴,使用npm打包響應的js文件。
執行完成後,直接雙擊打開WebDriverAgent.xcodeproj這個文件。
安裝證書
因為安裝到真機上都是需要證書簽名的,需要先在xcode中設置賬號。
如圖所示,選擇Team那一欄,選擇你的開發者證書帳號(個人開發者賬戶也行)。接著在TARGETS裏面選中WebDriverAgentRunner,用同樣的方法設置好證書。
如果是免費版的個人證書,還需要修改下WebDriverAgent的BundleID,主要不和別人的重名就行。
運行與測試
到此,基本環境就搭建好了,為了驗證是否能夠真正的運行,下面進行簡單的運行測試。
然後,Scheme選擇WebDriverAgentRunner。
最後運行 Product -> Test選項,一切正常的話,手機上會出現一個無圖標的WebDriverAgent應用。
測試WebDriverAgent
打開瀏覽器safari,在地址欄輸入 :127.0.0.1:8100/inspector 回車 看到 下圖說明正確。
ATX安裝和使用
ATX(AutomatorX的簡稱)的安裝比較簡單,主要有兩個命令。
- pip install --pre --upgrade atx
- pip install opencv_python
- 1
- 2
- 1
- 2
ATX的編寫都在 python 實現,例如:
- import atx
- d = atx.connect(‘http://localhost:8100‘, platform=‘ios‘)
- print d.status()
- #命令行執行
- python test.py
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
其他問題
當然,在搭建WebDriverAgent環境的可能會遇到一些問題,這裏總結了以下,可能出現的問題。
1,Failed to authorize rights (0x1) with status: -60007。
2,The bundle “WebDriverAgentRunner” couldn’t be loaded because it is damaged or missing necessary resources。
關於這兩個問題,直接刪除文件,重新下載源碼即可,關於這兩個問題的緣由,搭建可以查看官方文檔。
附:Python自動化框架地址ATX
WebDriverAgent源碼
iOS WebDriverAgent 環境搭建