UItesting:点击 UIcollectionview 然后测试失败
UItesting : Click on UIcollectionview then testing it get failed
我是 ui-testing 的新手。在录制过程中,当我在 ui-collection view 上 tap 时,第一个对象显示在 UI 上并对应于编写的代码在测试示例方法中是:
XCUIElement *window = [[app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0];
XCUIElement *element2 = [[[[window childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element;
[element2 tap];
并且在自动化测试示例方法时,无法获取 ui-collection view 的第一个对象。请提出一种方法来做到这一点。
提前致谢。
录制 UITests 往往会给您带来非常长且丑陋的查询。我强烈建议您查看如何手动编写 UITest。这真的很简单,而且查询看起来好多了。
例如:要点击 collection 视图的第一个单元格,您需要做的就是这个(前提是当前屏幕上只有一个 UICollectionView
):
Objective-C
- (void)testExample {
XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];
[[app.collectionViews.cells elementBoundByIndex:0] tap];
}
Swift
func testExample() {
let app = XCUIApplication()
app.launch()
// tap on the first collection view cell on the current screen
app.collectionViews.cells.element(boundBy:0).tap()
}
我是 ui-testing 的新手。在录制过程中,当我在 ui-collection view 上 tap 时,第一个对象显示在 UI 上并对应于编写的代码在测试示例方法中是:
XCUIElement *window = [[app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0];
XCUIElement *element2 = [[[[window childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element;
[element2 tap];
并且在自动化测试示例方法时,无法获取 ui-collection view 的第一个对象。请提出一种方法来做到这一点。 提前致谢。
录制 UITests 往往会给您带来非常长且丑陋的查询。我强烈建议您查看如何手动编写 UITest。这真的很简单,而且查询看起来好多了。
例如:要点击 collection 视图的第一个单元格,您需要做的就是这个(前提是当前屏幕上只有一个 UICollectionView
):
Objective-C
- (void)testExample {
XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];
[[app.collectionViews.cells elementBoundByIndex:0] tap];
}
Swift
func testExample() {
let app = XCUIApplication()
app.launch()
// tap on the first collection view cell on the current screen
app.collectionViews.cells.element(boundBy:0).tap()
}