gpt4 book ai didi

ios - 用户界面测试 : Click on UIcollectionview then testing it get failed

转载 作者:行者123 更新时间:2023-11-28 18:48:21 25 4
gpt4 key购买 nike

我是 ui-testing 的新手。在录制过程中,当我点击 ui-collection View 时,第一个对象显示在 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 View 的第一个单元格,您需要做的就是这个(前提是当前屏幕上只有一个 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()
}

关于ios - 用户界面测试 : Click on UIcollectionview then testing it get failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46691376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com