【发布时间】:2016-02-09 17:18:04
【问题描述】:
我正在尝试测试 UiImagePicker 我已使用 Xcode 上的记录功能来完成大部分测试,但它无法捕获用于确认我要选择的图片的元素。另一个选项“取消”也会发生同样的事情,我记得有某种方法可以获取视图上所有元素的列表或类似的效果。所以我的问题是如何在视图中获取对 ImagePicker 对象中选项的引用。
我正在为 iOS9 构建并运行 Xcode7.2
我当前的测试看起来像这样 ` 功能测试菜单(){ loginInApp(app) //让你通过登录
app.buttons["LogoButton"].tap() //entry point for menuView
XCTAssert(app.buttons["BR"].exists)
let brButton = app.buttons["BR"]
brButton.tap()
let photosFromSheet = app.sheets["Where would you like to get photos from?"]
XCTAssert(photosFromSheet.exists)
photosFromSheet.staticTexts["Where would you like to get photos from?"].tap()
XCTAssert(photosFromSheet.collectionViews.buttons["Chose from Library"].exists && photosFromSheet.buttons["Cancel"].exists)
photosFromSheet.collectionViews.buttons["Chose from Library"].tap()
XCTAssert(app.tables/*@START_MENU_TOKEN@*/.buttons["Moments"]/*[[".cells[\"Moments\"].buttons[\"Moments\"]",".buttons[\"Moments\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.exists)
app.tables/*@START_MENU_TOKEN@*/.buttons["Moments"]/*[[".cells[\"Moments\"].buttons[\"Moments\"]",".buttons[\"Moments\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
XCTAssert(app.collectionViews.cells["Photo, Landscape, March 12, 2011, 4:17 PM"].exists)
app.collectionViews.cells["Photo, Landscape, March 12, 2011, 4:17 PM"].tap()
XCTAssert(app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).elementBoundByIndex(2).childrenMatchingType(.Other).element.exists)
// 这就是事情变得模棱两可的地方,并且在测试运行时实际上并没有选择任何东西。
app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).elementBoundByIndex(2).childrenMatchingType(.Other).element.tap()
brButton.tap()
photosFromSheet.buttons["Cancel"].tap()
app.buttons["LogoButton"].tap()
`
【问题讨论】:
-
在不明确的行之前放置一个断点并在控制台中运行
po app.debugDescription,它将打印 UI 的可访问性层次结构。应该有助于弄清楚测试主机看到了什么。 -
那里也没有透露。
-
这解决了我的问题,但不适用于 6S+ stackoverflow.com/questions/33422681/…
标签: swift testing automation ios9