我必须在 iOS 模拟器上使用 swift 和 XCTestCase 自动执行以下场景。
- 第 1 步:启动应用
- 第 2 步:在应用上执行一些操作
- 第 3 步:终止应用
- 第 4 步:重新启动应用并检查执行的操作是否持续
我在我们的一个问题中发现使用以下代码段。
XCUIDevice.shared().press(XCUIDeviceButton.home)
sleep(60)
XCUIDevice.shared().siriService.activate(voiceRecognitionText: "Open {appName}")
它对我不起作用,有人可以建议任何不同的方法吗。
谢谢,
最佳答案
要启动或重新启动,请使用 launch
:
XCUIApplication().launch()
要终止应用程序,请使用 terminate()
。但是根据documentation :
If the application is already running, this call will terminate the existing instance, to ensure a clean launch state for the newly launched instance.
很快。您的测试可能如下所示:
XCUIApplication().launch()
// some actions
XCUIApplication().launch()
// some action
关于iOS XCTestCase 启动、执行一些操作、终止应用程序并重新启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43882711/