iOS UI Test總結
新增UI Test target
1.如果是新建專案,在新增新專案時,勾選UI Test,即可新增UI Test。

如果是為已有的專案新增UI Test,選擇File->New->Target 新建

2.選擇iOS UI Testing Bundle

3.為UI Test命名,並選擇依賴的target

新增UI Test target後,會自動生成CalcUITests資料夾,其中,有CalcUITests.m和Info.plist兩個檔案。

錄製UI Test
1.如果想使用UI Test的錄製功能,則UI Test target必須配置相應的Build Phase。

2.使用錄製按鈕開始錄製UI Test,此時模擬器會自動啟動,可以點選螢幕進行操作。

3.在錄製的過程中,Xcode會根據使用者互動,自動生成程式碼。
4.再次點選錄製按鈕結束錄製。
生成的程式碼如下:
<pre><code>
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.buttons[@"8"] tap];
[app.buttons[@"+"] tap];
[app.buttons[@"5"] tap];
[app.buttons[@"="] tap];
</pre></code>
具體操作,如下圖:(PS:因為是gif格式,有幾幀圖片丟失,所以8+5=13的過程不是特別連貫)

UI Test
錄製好UI Test,點選該圖示進行UI Test。此時,模擬器自動啟動,並自動執行UI Test。

具體操作,如下圖:

在真機上進行UI Test的效果與在模擬器上的效果一致。
遇到的問題
1.Please select a scheme where “iOS_Calc” is the executable。
解決方案:target一定要選擇關聯的target,而不是UI Test的target。

2.編譯後報錯:Incomplete universal character name
由於是使用公司專案進行UI Test,專案中很多UI 元素都沒有tag,生成的指令碼都是以元素的title或其他屬性來區分。
生成的程式碼如下:
<pre><code>
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tabBars.buttons[@"\U60a3\U8005"] tap];
XCUIElementQuery *tablesQuery2 = app.tables;
XCUIElementQuery *tablesQuery = tablesQuery2;
[tablesQuery.buttons[@"\U79d1\U5ba4\U5de5\U5177"] tap];
[tablesQuery.staticTexts[@"\U65e5\U7a0b"] tap];
XCUIElement *reminderoverviewviewNavigationBar =
app.navigationBars[@"ReminderOverviewView"];
[reminderoverviewviewNavigationBar.buttons[@"\U6dfb\U52a0"] tap];
[tablesQuery.textFields[@"\U6807\U9898"] tap];
[[[tablesQuery2 childrenMatchingType:XCUIElementTypeCell] elementBoundByIndex:0]
childrenMatchingType:XCUIElementTypeTextField].element;
[app.buttons[@"Done"] tap];
[app typeText:@"\n"];
</pre></code>
解決方案:這其實是Xcode的一個bug,需要手動將\U替換為\u即可。
3.編譯後報錯:missing '[' at start of message send expression uitest
解決方案:在錄製UI Test的過程中,如果涉及到鍵盤輸入事件,Xcode生成的程式碼不完整,導致編譯不過。此時,需手動修改程式碼。
4.閃退
Xcode在進行UI Test過程中經常性閃退,希望蘋果能儘快解決這些bug,提高UI Test的使用者體驗。
總結
提供錄製功能,減少程式碼輸入,方便開發者進行UI 測試
錄製功能,還是有很多bug,經常閃退
目前只能進行一些簡單的測試,且測試的過程還需要人工干預
一次錄製可以在不同裝置、不同螢幕尺寸上進行自動化測試,在一定程度上解放了測試同學們的雙手
demo下載地址:
相關文章
- iOS開發UI篇--iOS動畫(Core Animation)總結iOSUI動畫
- iOS RunTime 總結iOS
- iOS RAC總結iOS
- Kendo UI Grid 使用總結UI
- iOS 小坑總結iOS
- iOS 面試總結iOS面試
- iOS 面試題總結iOS面試題
- iOS 知識點總結iOS
- iOS快取的總結iOS快取
- iOS中常見Crash總結iOS
- iOS 音訊-audioUnit 總結iOS音訊
- IOS元件化方案總結iOS元件化
- iOS 效能優化總結iOS優化
- UI技術總結--效能優化UI優化
- Element-UI個人使用總結UI
- iOS 多執行緒總結iOS執行緒
- iOS面試題總結(四)iOS面試題
- iOS面試題總結(三)iOS面試題
- iOS底層原理總結 – RunLoopiOSOOP
- iOS面試題總結(七)iOS面試題
- iOS面試題總結(五)iOS面試題
- iOS面試題總結(六)iOS面試題
- iOS底層面試總結iOS面試
- iOS開發經驗總結iOS
- iOS野指標定位總結iOS指標
- iOS面試題總結(一)iOS面試題
- IOS常用程式碼總結(一)iOS
- iOS底層原理總結 - RunLoopiOSOOP
- iOS面試題總結(二)iOS面試題
- iOS邊下邊播總結iOS
- 翻譯:iOS Swift單元測試 從入門到精通 Unit Test和UI測試 UITestiOSSwiftUI
- android ios UIAndroidiOSUI
- Kendo UI Grid 批量編輯使用總結UI
- iOS中WKWebView互動使用總結iOSWebView
- iOS開發經驗總結2iOS
- iOS @property 屬性相關的總結iOS
- iOS開發經驗總結3iOS
- iOS初學之填坑總結iOS
- iOS 動畫基礎總結篇iOS動畫