有没有办法清除/刷新辅助功能层次缓存

Rob*_*mid 11 xcode-ui-testing

我有一个UI测试,它检查静态文本元素的值,等待几秒钟,然后再次检查以确认更改.起初它没有工作,因为层次结构没有更新.我在日志中注意到了这一点;

使用缓存的辅助功能层次结构

我通过简单地添加一个菜单并打开/关闭它以便合成事件并更新层次结构来为此设置解决方法.

但是,如果有一种方法可以直接清除缓存或强制更新,那就更好了.我还没有在API中找到一个.我错过了什么吗?

有任何想法吗?

这就是我在做的事情;

XCTAssertEqual(app.staticTexts["myText"].label, "Expected 1")
sleep(20)
menu.tap()
sleep(1)
menu.tap()
XCTAssertEqual(app.staticTexts["myText"].label, "Expected 2")
Run Code Online (Sandbox Code Playgroud)

我希望能够做到这一点

XCTAssertEqual(app.staticTexts["myText"].label, "Expected 1")
sleep(20)
app.elements.refresh()
XCTAssertEqual(app.staticTexts["myText"].label, "Expected 2")
Run Code Online (Sandbox Code Playgroud)

Gar*_*ary 8

为了强制更新辅助功能层次结构,请为以下count属性请求属性XCUIElementQuery:

// refresh
_ = XCUIApplication().navigationBars.count

// examine
print(XCUIApplication().debugDescription)
Run Code Online (Sandbox Code Playgroud)

上述结果为:" 获取匹配类型为:后代匹配类型NavigationBar "和" com.myapp的快照可访问性层次结构 ".


Mic*_*ael 0

您应该使用expectationForPredicate, 沿着...

let myText = app.staticTexts["myText"]
let waitFor = NSPredicate(format: "label = 'Expected 2'")
label.tap()
self.expectationForPredicate(waitFor, evaluatedWithObject: myText, handler: nil)
self.waitForExpectationsWithTimeout(2.0, handler: nil)
Run Code Online (Sandbox Code Playgroud)

这将等到 myText 的标签为“Expected 2”,或者达到 2 秒的超时。