简体   繁体   English

XCUITest等待其中包含特定静态文本的单元格

[英]XCUITest wait for a cell with a specific static text inside it

I have a collection view with some items. 我有一些物品的集合视图。 During my UI tests, I tap a button, and this will trigger a network request, which, when complete, will insert a cell into this collection view at index 0. Although this network request is coming from a local server, it still takes a second or two to complete. 在我的UI测试期间,我点击一个按钮,这将触发一个网络请求,完成该请求后,会将一个单元格插入索引为0的该集合视图中。尽管此网络请求来自本地服务器,但仍然需要一个一两秒就可以完成。

I want to wait for the new cell to be entered, and check it has the right values. 我想等待输入新的单元格,并检查它是否具有正确的值。 This will be visual confirmation that the functionality behind the button has worked. 这将通过视觉确认按钮后面的功能是否起作用。

How would I go about doing that? 我将如何去做? I cannot use application.collectionViews.cells.element(boundBy: 0) because there is a cell in that position already, so it will find it immediately but it will have the wrong values. 我不能使用application.collectionViews.cells.element(boundBy: 0)因为在该位置已经有一个单元格,因此它将立即找到它,但是它将具有错误的值。

I basically need to query the collection view cells by their subviews. 我基本上需要通过子视图查询集合视图单元格。 Something like this: 像这样:

let predicate = NSPredicate(format: "staticTexts['Title Label I'm after'].exists == 1")
application.collectionViews.cells.element(matching: predicate)

But this does not work, in fact it crashes, presumably because staticTexts isn't available to the predicate resolver. 但这是行不通的,实际上是崩溃了,大概是因为staticTexts无法用于谓词解析器。

The other thing I was thinking is that I build my own version of XCTestExpectation that runs every second and runs a handler that would take the first cell and check its contents. 我在想的另一件事是,我构建了自己的XCTestExpectation版本,该版本XCTestExpectation运行一次,并运行一个处理程序,该处理程序将使用第一个单元格并检查其内容。

Got it, you have to use containing instead of matching on the cells list, like below: 知道了,您必须在cells列表中使用containing而不是matching ,如下所示:

let predicate = NSPredicate(format: "label == 'Title Label Value'")
let cell = application.collectionViews.cells.containing(predicate).firstMatch
wait(forElement: cell, timeout: timeout)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM