Ios 如何编写UI测试来测试单击UITableView中的第一个单元格时图像是否存在?
在我的故事板中有一个Ios 如何编写UI测试来测试单击UITableView中的第一个单元格时图像是否存在?,ios,swift,uitest,Ios,Swift,Uitest,在我的故事板中有一个UITableView。它包含5个表视图单元格。 单击第一个单元格时,它将转到第二个UIView并显示相应的图像。如何对UITest部分进行编码以测试单击第一个单元格时图像是否显示?XCode 7有一个神奇的部分-UIRecording 首先选择testCase,然后像Gif一样开始录制 然后你会看到,为你创建UITest代码,在我的情况下,我得到 let app = XCUIApplication() app.tables/*@START_MENU_TOKEN@*/
UITableView
。它包含5个表视图单元格。
单击第一个单元格时,它将转到第二个UIView并显示相应的图像。如何对UITest部分进行编码以测试单击第一个单元格时图像是否显示?XCode 7有一个神奇的部分-UIRecording 首先选择testCase,然后像Gif一样开始录制 然后你会看到,为你创建UITest代码,在我的情况下,我得到
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()
那么,我只需要一点零钱
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)
因此,主要有两个步骤
- 让我们为您创建代码
- 进行一些更改,例如添加断言、按索引查询等