how to write UI test to test whether image existing when click the first cell in an UITableView?

…衆ロ難τιáo~ 提交于 2019-12-13 14:27:42

问题


There is an UITableView in my storyboard. It contains 5 Table view cells. When I click the first cell, it will go to the second UIView and show the corresponding images. How could I code the UITest part to test whether the image show up when I click the first cell?


回答1:


There is a magic part of XCode 7- UIRecording

First selected the testCase,and start recording like the Gif

Then you will see,UIRecording create UITest code for you,In my case,I get

  let app = XCUIApplication()
  app.tables/*@START_MENU_TOKEN@*/.staticTexts["Hello"]/*[[".cells.staticTexts[\"Hello\"]",".staticTexts[\"Hello\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
  app.otherElements.containingType(.NavigationBar, identifier:"UIView").childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Image).element.tap()

Then,I just need a little change

    let app = XCUIApplication()
    app.tables.cells.elementBoundByIndex(0).tap()
    let imageView =  app.otherElements.containingType(.NavigationBar, identifier:"UIView").childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Image)
    let count = imageView.images.count
    XCTAssert(count != 0)

So,the there are mainly two step

  • Let UIRecording Create codes for you
  • Make a little changes,such as add Assert,query by index,and so on.

Then run



来源:https://stackoverflow.com/questions/33643739/how-to-write-ui-test-to-test-whether-image-existing-when-click-the-first-cell-in

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