swift - 测试 UIImagePicker

标签 swift testing automation ios9

我正在尝试测试一个 UiImagePicker 我已经使用 Xcode 上的记录功能来完成我的大部分测试,但它无法捕获用于确认我要选择的图片的元素。同样的事情发生在另一个选项“哪个是取消”我记得某种获取 View 上所有元素列表或类似效果的方法。所以我的问题是如何在 View 中的 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()

`

最佳答案

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+ 上不起作用。希望这会很快得到解决。

关于swift - 测试 UIImagePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35298158/

相关文章:

Swift - 如何在自定义类中设置 UIBarButtonItem 的图像

xcode - 用于 Swift 框架文档的 XCODE IDE 中的上下文相关帮助

ios - 从详细 View Controller 返回时,侧边栏菜单不起作用

database - 如何使用 Selenium 进行数据库测试?

php:我想要每1分钟执行一次代码

excel - Microsoft Excel - 如何自动填充列中的公式?

ios - 与 ROS 同步时仅删除本地 Realm

ruby-on-rails - 目录 : integration test fail

macos - 用于测试客户端/服务器交互的邪恶代理

api - 如何使用 Carina 测试框架在代码中设置数组属性值进行 API 测试?