iOS开发技术分享iOS Developer

iOS UI测试

2016-11-11  本文已影响319人  dpruin

iOS UI测试

前言

创建UI测试

代码

- (void)viewDidLoad {
    [super viewDidLoad];
    self.userTextField.accessibilityIdentifier = @"userTextField";
    self.passwordTextField.accessibilityIdentifier = @"passwordTextField";
    // 辅助标识
    self.loginBtn.accessibilityIdentifier = @"login";
    
}

- (void)testEmptyUserNameAndPassword {
    
    // XCUIApplication app对象代理 继承自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属性 ,元素数量
    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行为录制

上一篇下一篇

猜你喜欢

热点阅读