在我们的应用程序中,我们在调试版本中有一个隐藏的测试屏幕,它允许我们操纵应用程序的状态。对于多个UI测试(包括snapshot脚本),我们需要访问此测试屏幕。这可以通过在屏幕上的任意位置用两根手指进行三次敲击来完成。
extension XXXTestCase {
/// Performs a hidden gesture which presents the testing screen.
func navigateToTestingScreen(file: StaticString = #file, line: UInt = #line) {
app.navigationBars
.element
.tap(withNumberOfTaps: 3, numberOfTouches: 2)
testingScreen.assertExists(file: file, line: line)
}
}
这在Xcode 9.2(和11.2模拟器)中运行良好,但Xcode 9.3(11.3模拟器)在.tap
方法上给出了以下运行时错误:
No element found at point {5, 42} while computing gesture coordinates, internal error possibly due to orientation or remote view hosting.
我通过将tap更改为.tap()
来检查它与XCUIElement本身没有任何关系,这不会产生任何运行时错误。 Xcode 9.3上的XCTest似乎在多点触控方面遇到了麻烦。我该如何解决这个问题?
当然,猴子的方法是改变手势来访问测试屏幕,但我并没有放弃这么简单:)
+-------+-----------+--------+
| Xcode | Simulator | Result |
+-------+-----------+--------+
| 9.2 | 11.2 | v | <-- not an option when migrated to Swift 4.1
| 9.3 | 11.3 | X |
| 9.3 | 11.2 | X | *
| 9.3 | 11.1 | X | *
| 9.3 | 11.0.1 | X | *
| 9.3 | 10.3.1 | v | <-- not an option, iOS 10 status bar is styled noticeably different
+-------+-----------+--------+
*这个组合在其他地方崩溃,即:
app.tabBars["main-tab-bar"].buttons["some-identifier"].tap()
使用最有用的短语EXC_BAD_ACCESS
。该元素存在(并且可以通过单击模拟器手动操作),但向其发送tap()
会引发异常。