如何编写UI测试以测试单击UITableView中的第一个单元格时图像是否存在?
我的故事板上有一个UITableView
.它包含5个表格视图单元格.
当我单击第一个单元格时,它将转到第二个UIView并显示相应的图像.我该如何编码UITest部分以测试单击第一个单元格时图像是否显示?
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?
XCode 7的神奇组成部分- UIRecording
There is a magic part of XCode 7- UIRecording
首先选择测试用例,然后像Gif一样开始录制.
First selected the testCase,and start recording like the Gif
然后您将看到,UIRecording为您创建UITest代码,就我而言,我得到
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)
所以,主要有两个步骤
- 让UIRecording为您创建代码
- 进行一些更改,例如添加断言,按索引查询等等.
然后运行