为第一个屏幕编写 UI 测试用例似乎很简单。
如下所示。
func testExample() {
let app = XCUIApplication()
let textField = app.otherElements.containing(.navigationBar, identifier:"id").children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .textField).element
textField.tap()
textField.tap()
app.navigationBars["id"].buttons["Done"].tap()
}
但是如何编写一个测试用例,其中一个导航控制器触发另一个屏幕,如下所示。
导航控制器 -> UIViewController1 -> UIViewcontroller2 .....UIViewController5
为了测试 UIViewController5,我将不得不编写大量代码,其中包括以下逻辑
1)启动应用程序。
2) 启动 Controller1 ,执行事件到 Launch Controller2
3)重复步骤2,直到到达Controller5。
我相信 UI 测试用例应该很简单,不应该花时间。
在这种情况下,理想的方法应该是什么,因为要运行 Controller5 的测试用例,它必须执行它之前的所有事件?