Shuhari
Shuhari

Reputation: 327

How can I control the time after an UIButton has been tapped to prepare for next action in UI Testing with Xcode

I am using UI Test with Xcode 7 but have a few problems. When I do record UI Test, Xcode translates Chinese to Unicode with uppercase 'U' and it shows errors. And ui test code

XCUIApplication *app = [[XCUIApplication alloc] init];
[app.navigationBars[@"\u5934\u6761"].images[@"new_not_login30"] tap];
XCUIElementQuery *tablesQuery = app.tables;
[tablesQuery.cells.staticTexts[@"\u6211\u7684\u864e\u94b1"] tap];

the problem is: after tapping image, there is an animation showing sidebar with UITableView or showing UIAlertController but I cannot handle the duration time. Actually, within animation the testing continues to find next elements to match but these elements do not exist or generating. So the test always be failed. Any solution to answer this question? Please help me. Thanks.

Upvotes: 0

Views: 81

Answers (1)

emoleumassi
emoleumassi

Reputation: 5149

try it with expectationForPredicate. I don't know the syntax in objective-c. But here is a part of code in swift:

let app = XCUIApplication()
app.navigationBars["\u5934\u6761"].images["new_not_login30"].tap()
let label = app.cells.staticTexts["\u6211\u7684\u864e\u94b1"]
let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: label) {
    // If the label exists, also check that it is enabled
    if label.enabled {
        label.tap()
        return true
    } else {
        return false
    }
}
waitForExpectationsWithTimeout(5) { error in
     if (error != nil) { assertion ....}

}

Just translate this code in objective-c.

Cheers

Upvotes: 1

Related Questions