有没有其他人在使用Xcode 11针对iOS 13模拟器或设备运行Xcode UI测试时,查找UIActivityViewController上的按钮会导致崩溃的问题?
我有多个UI测试验证出现在UIActivityViewController中的按钮。 它们进行了预期的设置工作,然后使用类似以下内容查找按钮:
XCTAssertTrue(app.buttons["Copy"].exists)
测试在 iOS 10、11 和 12 上运行良好。但是当我在 iOS 13 模拟器或设备上运行相同的测试时,在代码尝试访问 app.buttons 的那一刻,执行就会停止,并出现一个 "Thread 1: signal SIGABRT" 的错误提示,接着是 "Failed to get matching snapshots: Lost connection to the application (pid 33047).",出错位置是尝试访问 app.buttons 的那一行。
添加等待操作或者老式的 sleep 操作都无效。我尝试查找
XCUIElementTypeQueryProvider
下面的其他查询以查找元素,但都没有成功。如果我在测试访问 app.buttons 之前设置断点并尝试打印其包含的内容,则会收到不同的错误消息。
po app.buttons
t = 49.37s Requesting snapshot of accessibility hierarchy for app with pid 37576
expression produced error: error: /var/folders/f2/zhwz28mn1hd815pc78kg02q80000gp/T/expr5-3b2971..swift:1:72: error: 'XCUIElementQuery' is not a member type of 'XCTest'
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<XCTest.XCUIElementQuery>(bitPattern: 0x10c73f4d0)!.pointee)
这肯定感觉像是Xcode的一个bug。还有其他人遇到这个问题吗?
以下是一段代码,如果有其他人想要尝试,请使用:
从视图控制器:
@IBAction func showPressed(_ sender: Any) {
let text = "I have something to share."
let vc = UIActivityViewController(activityItems: [text], applicationActivities: nil)
vc.popoverPresentationController?.sourceView = self.view
self.present(vc, animated: true, completion: nil)
}
UI测试:
func testActivityViewController() {
let app = XCUIApplication()
app.launch()
app.buttons["Show AVC"].tap()
let buttons = app.buttons
let copy = buttons["Copy"]
sleep(2) // Just keeping things simple for the example.
XCTAssertTrue(copy.exists)
}