iOS Swift UI测试(XCUITests)稳定性问题-快速通道扫描

时间:2019-03-15 10:56:50

标签: ios swift xcode-ui-testing fastlane xcuitest

在通过快速通道(扫描)运行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

2 个答案:

答案 0 :(得分:0)

好吧,请记住使用removeUiInterrutpionMonitor方法!问题的原因是,有许多UIInterruptionMonitor对象声明并且线程有问题。添加删除UIInterruptionMonitor对象后,问题消失了。 :)

答案 1 :(得分:0)

上周我遇到了类似的问题。我认为在更新构建机上的最新fastlane版本和Xcode版本后,可以解决此问题。几个月来,我一直在对该错误进行故障排除