如何在Swift中进行UITest的UIButton图像更改?

时间:2018-07-28 19:47:07

标签: swift uibutton xcode-ui-testing

当我点击UIButton时,图像应更改以反映其新状态(例如,记录->暂停等)。

在我的XCode UITest函数中,如何在点击以断言其图像已正确更改为正确图像的.png文件后询问按钮当前图像?

1 个答案:

答案 0 :(得分:0)

我是这样做的

// Find the button by the image name
// In this example the image's names are "record_image" and "pause_image"
// "_" are replaced by " " in the image name when searching
let recordButton = XCUIApplication().buttons["record image"]
recordButton.tap()
XCTAssertFalse(recordButton.exists) // Record button won't exist anymore since the image has changed
let pauseButton = XCUIApplication().buttons["pause image"]
XCTAssertTrue(pauseButton.exists)
pauseButton.tap()
XCTAssertFalse(pauseButton.exists)
XCTAssertTrue(recordButton.exists)