iOS UI測(cè)試

iOS UI測(cè)試

前言

  • UITesting 和 Accessibility
  • 測(cè)試app的功能和UI界面是否正確, UI測(cè)試可以省去人為直接操作app進(jìn)行測(cè)試。

創(chuàng)建UI測(cè)試

  • File——New——Target——iOS UI Testing Bundle
  • 也可以如下圖操作


    UITesting_1.png

代碼

  • 前提須寫的代碼:設(shè)置UI控件accessibilityIdentifier屬性
- (void)viewDidLoad {
    [super viewDidLoad];
    self.userTextField.accessibilityIdentifier = @"userTextField";
    self.passwordTextField.accessibilityIdentifier = @"passwordTextField";
    // 輔助標(biāo)識(shí)
    self.loginBtn.accessibilityIdentifier = @"login";
    
}

  • 測(cè)試樣例
- (void)testEmptyUserNameAndPassword {
    
    // XCUIApplication app對(duì)象代理 繼承自XCUIElement
    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app.buttons[@"login"] tap];
    
    // XCUIElement UI元素的代理
    XCUIElement *label = app.alerts.staticTexts[@"Empty username/password"];
    
    // XCUIElementQuery 查詢UI元素的類
    XCUIElementQuery *alerts = app.alerts;
    
    NSPredicate *alertCount = [NSPredicate predicateWithFormat:@"count == 1"]; // XCUIElementQuery有count屬性 ,元素?cái)?shù)量
    NSPredicate *labelExist = [NSPredicate predicateWithFormat:@"exists == 1"]; // XCUIElement有exists屬性,是否存在
    
    [self expectationForPredicate:alertCount evaluatedWithObject:alerts handler:nil];
    [self expectationForPredicate:labelExist evaluatedWithObject:label handler:nil];
    
    [self waitForExpectationsWithTimeout:5 handler: nil];
    
}

UI行為錄制

  • 將輸入光標(biāo)放在方法實(shí)現(xiàn)中,并點(diǎn)擊工具欄上的錄制按鈕,就可以進(jìn)行實(shí)時(shí)錄制了


    UITesting_2.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容