测试 UIImagePicker
Testing UIImagePicker
我正在尝试测试 UiImagePicker 我已经使用 Xcode 上的记录功能来完成我的大部分测试,但它无法捕获用于确认我想要的图片的元素 select .另一个选项也会发生同样的事情 "Which is cancel" 我记得有些方法可以获取视图上所有元素的列表或类似的东西。所以我的问题是如何在视图中的 ImagePicker 对象中获取对选项的引用。
我正在建设 iOS9 和 运行ning 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)
// 这就是事情变得模棱两可的地方,在测试 运行.
时实际上 select 什么都没有
app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).elementBoundByIndex(2).childrenMatchingType(.Other).element.tap()
brButton.tap()
photosFromSheet.buttons["Cancel"].tap()
app.buttons["LogoButton"].tap()
`
UIImagePicker 显然不是 hittable
所以这是解决方法
如果您在文档中看到 tap(),它表示
/*!
* Sends a tap event to a hittable point computed for the element.
*/
- (void)tap;
/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
func forceTapElement() {
if self.hittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
coordinate.tap()
}
}
}
现在你可以调用
button.forceTapElement()
这在 6S+ 上不起作用。希望能尽快解决。
/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
func forceTapElement() {
if self.isHittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0))
coordinate.tap()
}
}
}
Swift 4 版本。
我正在尝试测试 UiImagePicker 我已经使用 Xcode 上的记录功能来完成我的大部分测试,但它无法捕获用于确认我想要的图片的元素 select .另一个选项也会发生同样的事情 "Which is cancel" 我记得有些方法可以获取视图上所有元素的列表或类似的东西。所以我的问题是如何在视图中的 ImagePicker 对象中获取对选项的引用。
我正在建设 iOS9 和 运行ning 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)
// 这就是事情变得模棱两可的地方,在测试 运行.
时实际上 select 什么都没有app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).elementBoundByIndex(2).childrenMatchingType(.Other).element.tap()
brButton.tap()
photosFromSheet.buttons["Cancel"].tap()
app.buttons["LogoButton"].tap()
`
UIImagePicker 显然不是 hittable
所以这是解决方法
如果您在文档中看到 tap(),它表示
/*!
* Sends a tap event to a hittable point computed for the element.
*/
- (void)tap;
/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
func forceTapElement() {
if self.hittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
coordinate.tap()
}
}
}
现在你可以调用
button.forceTapElement()
这在 6S+ 上不起作用。希望能尽快解决。
/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
func forceTapElement() {
if self.isHittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0))
coordinate.tap()
}
}
}
Swift 4 版本。