[英]Fastlane Scan “Failed to synthesize event” when running UI Tests, works from Xcode
[英]iOS Swift UI Tests (XCUITests) stability problem - fastlane scan
在通过 fastlane (scan) 运行 iOS 测试期间,测试的稳定性存在随机问题。 日志中可见的错误:
Lost connection to the application (pid XXXX).
<unknown>:0
有谁知道与应用程序失去连接的可能原因是什么?
我的测试是在类中实现的,每个类都继承了 BaseTest 类,应用程序以下列方式启动:
import XCTest
class BaseTest: XCTestCase {
let app = XCUIApplication()
...
override func setUp() {
continueAfterFailure = false
app.launch()
...
}
override func tearDown() {
super.tearDown()
let screenshot = XCUIScreen.main.screenshot()
let fullScreenshotAttachment = XCTAttachment(screenshot: screenshot)
fullScreenshotAttachment.lifetime = .deleteOnSuccess
add(fullScreenshotAttachment)
app.terminate()
}
...
}
还实现了 Page Object 类,每个类都继承了 BaseScreen:
import XCTest
class BaseScreen {
let app: XCUIApplication = XCUIApplication()
}
extension BaseScreen {
func findAll(_ type: XCUIElement.ElementType) -> XCUIElementQuery {
return app.descendants(matching: type)
}
}
测试通过 fastlane 运行,如下所示:
lane :ui_tests do
# Performing UI Tests
scan(
clean: true,
reinstall_app: true,
app_identifier: "XXX",
workspace: workspace,
scheme: "uiTests",
devices: devicesUITests,
code_coverage: true,
open_report: false,
output_style: "rspec",
output_types: "html",
output_directory: "./build/DerivedData/test_output",
result_bundle: "true",
buildlog_path: "./XXX",
xcargs: "OTHER_SWIFT_FLAGS=\"-Xfrontend -debug-time-function-bodies\" SWIFT_OPTIMIZATION_LEVEL=\"-Owholemodule\"",
derived_data_path: "./build/DerivedData"
)
puts("Generating Test Report ...")
sh('xchtmlreport -r ../build/DerivedData/test_output')
puts("Test Report Successfully generated")
end
我也在使用 UIInterruptionMonitor 进行警报,这也可能是相关的。
编辑: StandardAndStandardError.txt 的末尾有以下片段:
2019-03-15 12:23:49.511 XXX[35711:8931440] *** Accessing the keyManager while not available yet
2019-03-15 12:23:49.511 XXX[35711:8931440] *** Accessing the keyManager while not available yet
2019-03-15 12:23:50.065 XXX[35711:8931461] Cannot find executable for CFBundle 0x7fd7f74336e0 </.../Library/Developer/CoreSimulator/Devices/.../data/Containers/Bundle/Application/.../XXX.app/Frameworks/DJISDK.framework/DJIFlySafe.bundle> (not loaded)
2019-03-15 12:23:50.073 XXX[35711:8931465] Cannot find executable for CFBundle 0x7fd7f75015d0 </.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/Frameworks/DJISDK.framework/SDKSharedLib.bundle> (not loaded)
CoreData: annotation: Failed to load optimized model at path '/.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
CoreData: annotation: Failed to load optimized model at path '/.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
CoreData: annotation: Failed to load optimized model at path '/.../Library/Developer/CoreSimulator/Devices/xxx/data/Containers/Bundle/Application/xxx/XXX.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
xxx(35711,0x7000060f9000) malloc: Heap corruption detected, free list is damaged at 0x6000009754a0
*** Incorrect guard value: 4416955976
xxx(35711,0x7000060f9000) malloc: *** set a breakpoint in malloc_error_break to debug
好吧,记得使用removeUIInterrutpionMonitor
方法! 问题的原因是声明了很多 UIInterruptionMonitor 对象,并且线程有问题。 添加删除 UIInterruptionMonitor 对象后,问题消失了。 :)
我上周遇到了类似的问题。 我认为在我的构建机器上更新到最新版本的 fastlane 和 Xcode 解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.