测试UIImagePicker

时间:2016-02-09 17:18:04

标签: swift testing automation ios9

我正在尝试测试UiImagePicker我已经使用Xcode上的记录功能来完成我的大部分测试,但是它无法捕获用于确认我想要选择的图片的元素。同样的事情发生在另一个选项“哪个是取消”我记得一些方法来获取视图上的所有元素的列表或那种效果。所以我的问题是如何在视图中获取ImagePicker对象中的选项的引用。

我正在为iOS9构建并运行Xcode7.2

我目前的测试看起来像这样 ` func testMenu(){         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(。其他).elementBoundByIndex(2).childrenMatchingType(。其他).element.exists)

//这是事情变得模棱两可的地方,并且在测试运行时实际上没有选择任何东西。

app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(。其他).elementBoundByIndex(2).childrenMatchingType(。其他).element.tap()

    brButton.tap()
    photosFromSheet.buttons["Cancel"].tap()
    app.buttons["LogoButton"].tap()

`

2 个答案:

答案 0 :(得分:1)

The UIImagePicker is apparently not $scope.dates = [$scope.date1, $scope.date2, $scope.date3, $scope.date4]; so this is the workaround

If you see tap() in documentation it says

hittable

Now you can call as

/*!
 * 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()
        }
    }
}

This does not work on the 6S+ tho. Hopefully that will be resolved soon.

答案 1 :(得分:0)

/*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版本。