iOS:如何断言在 UITest 中选择了一个单元格?

标签 ios ios9 xcode-ui-testing uitest

我有以下层次结构: ViewController -> TableView -> TableViewCell -> CollectionView -> CollectionViewCell -> UIImage

在 tableViewCell 上,在 collectionView 内部,有 4 个单元格。每个单元格都有一个唯一的标签。

当用户点击 collectionViewCell 时,单元格被选中并且 UIImageView 也被突出显示。在这种情况下,这意味着那里有不同的图像。我启用了 UIImageView 的可访问性,并将特征设置为按钮和图像以尝试访问那些 XCUIElementTypes

我无法使任何 UITest 工作,因为它总是告诉我 UIImageView 有多个结果,即使 ImageView 所在的单元格具有唯一标识符。

如何断言单元格已被选中?

使用记录功能我得到: 让 whatIsYourFilingStatusCellsQuery = XCUIApplication().tables.cells.containingType(.StaticText, identifier:"Single").childrenMatchingType(.Image).matchingIdentifier("btn_unselected").tap()

最佳答案

@Che 的想法是正确的。

didSelectItemAtIndexPath: 中,我这样做了:

cell.accessibilityIdentifier = @"isSelected";

然后,在测试文件中:

XCTAssertEqualObjects(randomCellToTap.value, @"isSelected");

我还将在 didDeselect...

中执行相反的操作

关于iOS:如何断言在 UITest 中选择了一个单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34058695/

相关文章:

swift - 如何自定义 DatePickerDialog 以在文本中显示自定义日期? - swift

ios - 无法覆盖 Swift XCTestCase 中的 init() 函数

ios - UIPresentation Controller - 从后台返回后布局出错

ios - 使用 Core Animation 的 Glitch-style 动画

ios - 重复符号 Apple Mach-O 链接器错误

iOS 9 Spritekit 双击在 iPhone 6S 上不起作用

ios - UITableView 尾部滑动短与长或长滑动后返回单元格

objective-c - Xcode 7 和 IOS 9 中的 SpriteKit 问题

ios - 如何在 swift UI Test 下检查应用程序状态

Xcode UI 测试 : Automatically taking snapshot when predicates fail?