我有以下层次结构: 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/