UItesting : Click on UIcollectionview then testing it get failed

元气小坏坏 提交于 2019-12-13 03:48:57

问题


I am new at ui-testing. During recording, when I tap on ui-collection view first object is shown on UI and corresponding to code written in test-example method is:

XCUIElement *window = [[app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0];
    XCUIElement *element2 = [[[[window childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element;
    [element2 tap]; 

And when automating the test-example method, it's unable to fetch first object of ui-collection view. please suggest a way to do that. Thanks in advance.


回答1:


Recording UITests tends to give you really long and ugly queries. I strongly suggest that you have a look on how to write UITests manually. It's really easy and the queries look much better.

For example: to tap on the first cell of your collection view all you need to do is this (providing that there is only one UICollectionView on the current screen):

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()
}


来源:https://stackoverflow.com/questions/46691376/uitesting-click-on-uicollectionview-then-testing-it-get-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!