XCUIElement始终存在

时间:2015-08-05 05:58:10

标签: xcode7 ios9 ui-testing xcode-ui-testing

我在xcode 7 beta上尝试UI测试。

在XCUIElement被解雇后,其.exists属性仍为YES。

e.g。

XCUIElement *button = app.sheets[@"Sample sheet"].buttons[@"Sample button"];
[button tap]; // Tapping will dismiss UIActionSheet and its button will no longer exist.
XCTAssertFalse(button.exists); // -> Error here.

有没有办法在被解雇后检测到XCUIElement不存在?

3 个答案:

答案 0 :(得分:2)

XCUIElement有一个返回BOOL的exists方法。

在您的代码中:

if (button.exists) {
   [button tap];
}

答案 1 :(得分:1)

最好的方法是在点击事件之前检查XCUIElement是否存在并且是否匹配

在您的代码中:

if (button.exists && button.isHitable) {
   [button tap];
}

答案 2 :(得分:0)

您可以查看app.sheets.count

相关问题