UITest iOS waitForExistence返回false,但是元素可见

时间:2019-09-13 11:27:28

标签: ios xcuitest

我是iOS UITest的新手,因此对某些不合理的内容深表歉意。

我试图断言staticText是否可见,但是尽管显示了它总是返回false。

屏幕看起来像这样:

enter image description here

测试功能代码如下:

func verifyBlockedAccountsEmptyState() {
    print(profileListScreen.app.navigationBars["Blocked Accounts"].waitForExistence(timeout: 5))
    print(profileListScreen.app.staticTexts.element.label)
    print(profileListScreen.app.staticTexts["No blocked accounts"].waitForExistence(timeout: 5))

    var elementLabels = [String]()
    for i in 0..<profileListScreen.app.staticTexts.count {
        elementLabels.append (profileListScreen.app.staticTexts.element(boundBy: i).label)
    }
    print("staticTexts -> ", elementLabels)
}

输出:

true
12:25 PM
false
staticTexts ->  ["12:25 PM"]

有什么主意吗?

谢谢

编辑 如果我尝试记录XCUIElement,则会出现以下错误:

Timestamped Event Matching Error: Failed to find matching element

2 个答案:

答案 0 :(得分:1)

听起来您应该将AccessiblityId分配给感兴趣的视图的一部分。通过获取容器XCUIElement的debugDescription,您可以查看给定视图中的可用内容。

答案 1 :(得分:1)

使用错误的元素类型可能会导致问题。

您可能应该添加一个断点并使用lldb检查此屏幕。

键入po print(app.debugDescription)以打印元素的整个层次结构及其实际类型。