IOS客戶端嘗試使用Appium框架進行自動化測試,該框架方便定制符合自身業(yè)務的測試用例,提高測試效率瞬捕。在搭建測試環(huán)境時歉嗓,發(fā)現(xiàn)真機調試安裝中問題比較多丰介,特整理以供其他遇到同樣問題的同學參考。
先列出簡單安裝流程:
1.npm install -g appium
2.安裝 carthage?:brew install carthage
3.npm install -g ios-deploy
4.libimobiledevice:brew install libimobiledevice
5.gem install xcpretty
?WebDriverAgentRunner的處理:
?先使用mac打開終端
?1.? cd ~
?2.? 下載WebDriverAgent 項目最新的代碼:
????? git clone?https://github.com/facebook/WebDriverAgent
3.?? 執(zhí)行?./Scripts/bootstrap.sh
4.??? cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver
5. ???rm –rf WebDriverAgent 刪除自帶的WebDriverAgent
6.?? ?ln –s ~/WebDriverAgent WebDriverAgent 將編譯好的WebDriverAgent放入原來的路徑下
7.??? 打開 WebDriverAgent 項目并按照教程修改, 運行 Product -> Test
(GitHub教程:https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md)
8.? ?訪問http://10.242.35.210(ip):8100鉴分,可以返回一個json哮幢。
如果返回失敗,可以測試使用下面的方法:
?????? 1)轉發(fā)端口志珍,在終端輸入?iproxy 8100 8100?, 窗口不要關閉或者終止運行
?????? 2)訪問?http://localhost:8100/status?有內容顯示
成功之后啟動appium ,start inspector session,startSession橙垢。寫入如下:
9.可以運行寫好的測試腳本
遇到其他問題:
1.需要使用收費的開發(fā)者帳戶編譯WebDriverAgentRunner,其中的bundle identifier自定義可唯一標識就行(地址:https://developer.apple.com/account/)
2.證書沖突,將BuildSettings里的code singing identity設置成iPhone Develpoer伦糯,解決
3.編譯時發(fā)現(xiàn)ServerURLHere->http://10.242.35.210:0柜某,端口號為0
Log如下:
background with task ID 1
Test Suite 'All tests' started at 2018-07-03 14:02:32.203
Test Suite 'WebDriverAgentRunner.xctest' started at 2018-07-03 14:02:32.206
Test Suite 'UITestingUITests' started at 2018-07-03 14:02:32.208
Test Case '-[UITestingUITests testRunner]' started.
??? t =???? 0.01s Start Test at 2018-07-03 14:02:32.214
??? t =???? 0.01s Set Up
2018-07-03 14:02:32.279721+0800 WebDriverAgentRunner-Runner[3133:267743] Built at Jul? 3 2018 13:59:19
2018-07-03 14:02:32.399746+0800 WebDriverAgentRunner-Runner[3133:267743] ServerURLHere->http://10.242.35.210:0<-ServerURLHere
解決方法有兩種:
1)端口參數(shù)指定,增加USE_PORT=8100
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=udid’ USE_PORT=8100 test
2) 如果還是無法解決,Xcode打開WebDriverAgentLib-Routing-FBWebServer.m下的端口
4.xcodebuild failed with code 65
command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: "xcodebuild failed with code 65". Make sure you follow the tutorial athttps://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
解決方法:Desired Capabilities中加入xcodeOrgId敛纲,也就是teamid莺琳。需要填寫
xcodeOrgId——-teamid,可以讓開發(fā)查看载慈,或者登錄https://developer.apple.com/account惭等,membership中的TeamID
到此,真機的測試環(huán)境已經跑通办铡,有什么寫的不對的地方歡迎大家指正辞做。
轉載請記得標明原出處。