用户界面结果测试
User interface result test
是否可以在 ios 中使用自动化测试来测试用户操作的结果?例如,如果用户单击保存按钮,我如何检查应用程序是否创建了文件。我已经尝试过 Appium 和 Apple 制造的 XCUITesting,但我就是想不通。
使用 Apple 的 XCUI测试测试应用程序存在于单独的进程中并且无法直接访问您的应用程序的沙箱,因此,除非您的应用程序的 UI 提供某种视觉反馈表明文件已创建,无法使用官方工具进行检查。
您可以使用SBTUITestTunnel(免责声明,我是库的作者)扩展UI测试功能允许编写这样的测试.例如,假设您的应用在应用的文档文件夹中保存了 test_file.txt,您可以编写以下测试:
func testThatFileExistsAfterTap() {
// launch app
app = SBTUITunneledApplication()
app.launchTunnelWithOptions([SBTUITunneledApplicationLaunchOptionResetFilesystem]) {
// do additional setup before the app launches, if needed
}
app.buttons["action"].tap() // button that triggers file save
// add some expectation on the UI to wait for the write to complete (UIActivity indicator, etc)
let fileData = app.downloadItemFromPath("test_file.txt", relativeTo: .DocumentDirectory)
// XCTAssert() that fileData contains the expected data
}
请注意如何传递 SBTUITunneledApplicationLaunchOptionResetFilesystem
以在启动时重置应用程序的文件系统。此选项允许您编写独立于先前会话的测试。
是否可以在 ios 中使用自动化测试来测试用户操作的结果?例如,如果用户单击保存按钮,我如何检查应用程序是否创建了文件。我已经尝试过 Appium 和 Apple 制造的 XCUITesting,但我就是想不通。
使用 Apple 的 XCUI测试测试应用程序存在于单独的进程中并且无法直接访问您的应用程序的沙箱,因此,除非您的应用程序的 UI 提供某种视觉反馈表明文件已创建,无法使用官方工具进行检查。
您可以使用SBTUITestTunnel(免责声明,我是库的作者)扩展UI测试功能允许编写这样的测试.例如,假设您的应用在应用的文档文件夹中保存了 test_file.txt,您可以编写以下测试:
func testThatFileExistsAfterTap() {
// launch app
app = SBTUITunneledApplication()
app.launchTunnelWithOptions([SBTUITunneledApplicationLaunchOptionResetFilesystem]) {
// do additional setup before the app launches, if needed
}
app.buttons["action"].tap() // button that triggers file save
// add some expectation on the UI to wait for the write to complete (UIActivity indicator, etc)
let fileData = app.downloadItemFromPath("test_file.txt", relativeTo: .DocumentDirectory)
// XCTAssert() that fileData contains the expected data
}
请注意如何传递 SBTUITunneledApplicationLaunchOptionResetFilesystem
以在启动时重置应用程序的文件系统。此选项允许您编写独立于先前会话的测试。