有一个UITableView
在我的故事板中。它包含 5 个表视图单元格。
当我单击第一个单元格时,它将转到第二个 UIView 并显示相应的图像。如何编写 UITest 部分来测试单击第一个单元格时图像是否显示?
XCode 7 有一个神奇的部分——UI录制
First selected the testCase,and start recording like the Gif![enter image description here](https://i.stack.imgur.com/qlgsN.gif)
然后你会看到,正在为你录制创建 UI 测试代码,就我而言,我得到
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)
所以,主要有两步
- 让 UIRecording 为您创建代码
- 做一点改动,比如添加Assert、按索引查询等。
Then run
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)