给定 XCTest UI 测试中的索引,如何验证表视图行中是否存在文本? [英] How can I verify existence of text inside a table view row given its index in an XCTest UI Test?

查看:20
本文介绍了给定 XCTest UI 测试中的索引,如何验证表视图行中是否存在文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XCTest UI 测试框架来检查表视图中的行.在我的测试中,我需要验证给定索引的表视图行中是否存在文本.

I am using XCTest UI Test framework to check rows in a table view. In my test I need to verify the existence of text in a table view row given its index.

我想使用 tableRows.elementBoundByIndex 方法,但它没有返回任何东西.调用 tableRows.count 返回的行数为零.该表存在并填充,因为我可以成功查询行内的文本:

I was thinking of using tableRows.elementBoundByIndex method, but it did not return anything. The number of rows returned by calling tableRows.count is zero. The table is present and filled because I can query the text inside the rows successfully:

XCTAssertEqual(app.tables.staticTexts["Cute Alpaca"].exists)

如何在 XCTest UI 测试中根据文本的索引来验证文本是否存在?

How can I verify existence of a text in a row given its index in an XCTest UI test?

推荐答案

事实证明 tableRows 实际上并没有检测 UITableView 中的行.使用 cells 代替.

It turns out that tableRows doesn't actually detect rows in the UITableView. Use cells instead.

我有一种感觉,tableRowstableColumns 用于在 Mac OS X 上做测试,在那里你有实际的表,而在 iOS 上我们有 UITableViewCellUICollectionViewCell.或者这可能是一个错误,因为我们仍处于测试阶段.

I have a feeling that tableRows and tableColumns are used to do testing on Mac OS X where you have actual tables while on iOS we have UITableViewCell and UICollectionViewCell. Or this could be a bug as we are still in the beta period.

let table = app.tables.element
XCTAssertTrue(table.exists)

let cell = table.cells.elementBoundByIndex(2)
XCTAssertTrue(cell.exists)
let indexedText = cell.staticTexts.element
XCTAssertTrue(indexedText.exists)

或一个班轮

XCTAssertTrue(app.tables.element.cells.elementBoundByIndex(2).exists)

这篇关于给定 XCTest UI 测试中的索引,如何验证表视图行中是否存在文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆