为 AWS Device Farm 构建 XCTest UI 测试

Building XCTest UI tests for AWS Device Farm

我正在尝试在 AWS Device Farm 上将 iOS XCUI 测试设置为 运行,但似乎无论我如何构建和上传它们,测试不会运行。它们在 XCode 本地 运行 时执行并通过,但在 AWS Device Farm 上不 运行。

我已经设置了我能设法隔离此问题的绝对最简单的应用程序。它由带有单个标签的单个视图和一个验证标签是否存在的 UI 测试组成。

这是 AWS Device Farm 界面中出现的错误。

深入研究日志文件揭示了这一点(在 "Application Output" 日志文件中):

2016-04-03 19:07:39.842 XCTRunner[195:28521] Running tests...
2016-04-03 19:07:39.868 XCTRunner[195:28521] Unable to load configuration data from specified path ; error: The file name is invalid.
2016-04-03 19:07:39.872 XCTRunner[195:28521] Looking for test bundles in /var/mobile/Containers/Bundle/Application/883D7F70-E525-4478-9E5E-C87F72A83879/MyTestAppUITests-Runner.app/PlugIns
2016-04-03 19:07:39.875 XCTRunner[195:28521] Found test bundle at /var/mobile/Containers/Bundle/Application/883D7F70-E525-4478-9E5E-C87F72A83879/MyTestAppUITests-Runner.app/PlugIns/MyTestAppUITests.xctest
2016-04-03 19:07:39.878 XCTRunner[195:28521] Looking for configurations in /var/mobile/Containers/Bundle/Application/883D7F70-E525-4478-9E5E-C87F72A83879/MyTestAppUITests-Runner.app/PlugIns/MyTestAppUITests.xctest
2016-04-03 19:07:39.879 XCTRunner[195:28521] No configurations found, creating a default configuration that will run all tests.
2016-04-03 19:07:39.993 XCTRunner[195:28521] XCTestConfigurationHook: Using Test MyTestAppUITests/testExample
2016-04-03 19:07:39.995 XCTRunner[195:28521] XCTestConfigurationHook: Using Test MyTestAppUITests/testExample
2016-04-03 19:07:39.995 XCTRunner[195:28521] XCTestConfigurationHook: Using Test MyTestAppUITests/testExample
Test Suite 'Selected tests' started at 2016-04-03 19:07:40.008
Test Suite 'MyTestAppUITests' started at 2016-04-03 19:07:40.014
Test Case '-[MyTestAppUITests testExample]' started.
2016-04-03 19:07:40.021 XCTRunner[195:28521] *** Assertion failure in -[XCUIApplication init], /Library/Caches/com.apple.xbs/Sources/XCTest_iOS/XCTest-10112/XCTestFramework/UI Testing/XCUIApplication.m:72
2016-04-03 19:07:40.022 XCTRunner[195:28521] XCTestConfigurationHook: Ignoring skipped tests
2016-04-03 19:07:40.023 XCTRunner[195:28521] XCTestConfigurationHook: Using Test MyTestAppUITests/testExample
2016-04-03 19:07:40.025 XCTRunner[195:28521] XCTestConfigurationHook: Using Session ID 75B97C9E-6F14-4F88-A242-64B79C9A0F04
<unknown>:0: error: -[MyTestAppUITests testExample] : failed: caught "NSInternalInconsistencyException", "No target application path specified via test configuration: <XCTestConfiguration: 0x1652af60>
                      testBundleURL:file:///var/mobile/Containers/Bundle/Application/883D7F70-E525-4478-9E5E-C87F72A83879/MyTestAppUITests-Runner.app/PlugIns/MyTestAppUITests.xctest/
             testBundleRelativePath:(null)
                  productModuleName:(null)
                        testsToSkip:(null)
                         testsToRun:MyTestAppUITests/testExample
                 reportResultsToIDE:no
                  sessionIdentifier:<__NSConcreteUUID 0x1655e5c0> 75B97C9E-6F14-4F88-A242-64B79C9A0F04
         pathToXcodeReportingSocket:(null)
          disablePerformanceMetrics:no
    treatMissingBaselinesAsFailures:no
                    baselineFileURL:(null)
           baselineFileRelativePath:(null)
              targetApplicationPath:(null)
          targetApplicationBundleID:(null)
                   reportActivities:no
           testsMustRunOnMainThread:no
             initializeForUITesting:no
"
(
    0   CoreFoundation                      0x22c90123 <redacted> + 150
    1   libobjc.A.dylib                     0x22436e17 objc_exception_throw + 38
    2   CoreFoundation                      0x22c8ffe1 <redacted> + 0
    3   Foundation                          0x23463b19 <redacted> + 92
    4   XCTest                              0x002625a1 -[XCUIApplication init] + 216
    5   MyTestAppUITests                    0x01d8a4b7 -[MyTestAppUITests setUp] + 182
    6   XCTest                              0x002433bf __24-[XCTestCase invokeTest]_block_invoke_2 + 198
    7   XCTest                              0x00274661 -[XCTestContext performInScope:] + 308
    8   XCTest                              0x002432f3 -[XCTestCase invokeTest] + 184
    9   XCTest                              0x00243a4f -[XCTestCase performTest:] + 566
    10  XCTest                              0x00241375 -[XCTestSuite performTest:] + 460
    11  XCTest                              0x00241375 -[XCTestSuite performTest:] + 460
    12  XCTest                              0x0024e88d -[XCTestObservationCenter _observeTestExecutionForBlock:] + 716
    13  XCTest                              0x00275c7f _XCTestMain + 1150
    14  CoreFoundation                      0x22c535b1 <redacted> + 12
    15  CoreFoundation                      0x22c5306d <redacted> + 216
    16  CoreFoundation                      0x22c515e1 <redacted> + 784
    17  CoreFoundation                      0x22ba4bf9 CFRunLoopRunSpecific + 520
    18  CoreFoundation                      0x22ba49e5 CFRunLoopRunInMode + 108
    19  GraphicsServices                    0x23df0ac9 GSEventRunModal + 160
    20  UIKit                               0x26e34ba1 UIApplicationMain + 144
    21  XCTRunner                           0x000fa255 XCTRunner + 33365
    22  libdyld.dylib                       0x22853873 <redacted> + 2
)
Test Case '-[MyTestAppUITests testExample]' failed (0.239 seconds).
Test Suite 'MyTestAppUITests' failed at 2016-04-03 19:07:40.256.
     Executed 1 test, with 1 failure (1 unexpected) in 0.239 (0.242) seconds
Test Suite 'Selected tests' failed at 2016-04-03 19:07:40.259.
     Executed 1 test, with 1 failure (1 unexpected) in 0.239 (0.251) seconds

在我看来,MyAppUITests-Runner.app 应用程序没有包含允许它定位正确应用程序的配置文件。所以我怀疑这与我用来构建和上传应用程序及其 UI 测试的过程有关。

我用来生成应用程序 ipa 文件的过程是:

  1. 在 Xcode 中,单击“产品”>“存档”
  2. Select 管理器中的存档 window 然后单击导出按钮
  3. Select "Save for Ad Hoc Deployment" 然后点击下一步
  4. Select "use local signing assets" 用于供应
  5. Select "Export one app for all compatible devices"
  6. "Include manifest for over-the-air installation" 未检查
  7. "Rebuild from bitcode"勾选
  8. 将 ipa 导出到桌面上的文件夹

我用来生成 UI 测试 ipa 文件的过程是(遵循 http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-ios-xctest-ui.html 的说明):

  1. 在Xcode中,Select"Generic iOS Device"作为构建目标
  2. 单击产品 > 构建目标 > 测试
  3. 打开项目的 XCode Derived Data 文件夹,转到 Build > Intermediates > Debug-iphoneos。这包含 2 个文件:MyTestApp.app 和 MyTestAppUITests-Runner.app
  4. 在桌面上创建一个名为 "Payload" 的新目录
  5. 复制 MyTestAppUITests-Runner.app 文件到 Payload 目录
  6. 右击有效载荷然后select"Compress 'Payload'"
  7. 将生成的Payload.zip文件重命名为mytestapp-uitests.ipa

我也试过将 MyTestApp.app 和 MyTestAppUITests-Runner.app 都包含到 mytestapp-uitests.ipa 文件中,但这也不起作用。

到 运行 Device Farm 中的测试:

  1. 在我的测试项目中,点击"Create a new run"
  2. Select Android/iOS
  3. 上传之前生成的 MyTestApp.ipa 文件(来自导出存档)并单击下一步
  4. Select "XCTest UI" 从列表中,上传 mytestapp-uitests.ipa 文件

  1. Select 设备池,其中包括 iPad Air 2、iPad Air 和 iPad 2 所有 运行ning iOS 9.2 .1
  2. 将设备状态保留为默认设置
  3. 单击“开始”运行

请注意,如果我使用相同的应用程序 ipa 文件和 运行 内置的 Fuzz 测试,这些都可以正常工作——我可以看到带有单个标签的测试应用程序的屏幕截图。

我看不出有什么明显的遗漏。我需要做什么才能完成这项工作?

我有类似的问题。我再挖一点,似乎以下可能是测试失败的原因。

"Could not receive XCTest bundle ready message from testmanagerd, error code -7”

设置和拆卸方法似乎默认为 运行,因此通过了。我不确定。但是,我会尝试从日志中获取更多信息。

我在 AWS Device Farm 团队工作。 您在下面引用的分析是正确的。

Which to me looks like the MyAppUITests-Runner.app application hasn't included a configuration file which allows it to target the correct application. So I suspect it's something to do with the process I am using to build and upload the application and its UI Tests.

我们目前正在解决一个问题,即如果 .ipa 中缺少 .xctestconfiguration 文件,则无法提取测试。

此问题的解决方法是 运行 本地测试 运行 将在 .app/Plugins 文件夹下生成 .xctestconfiguration 文件

在打包上传到 Device Farm 之前,只需确保 .xctestconfiguration 文件存在于 .app

Fuzz 测试将起作用,因为它不使用您的测试代码。它只需要您的应用程序和 运行 对其进行自定义模糊测试。

关于 *-Runner.app 位置的另一个注意事项是,您应该能够在 Xcode 的 Products 文件夹下找到它,但只要您能找到它,一切都应该没问题。

更新 自 post 的原始时间以来,此问题已得到修复,并且不再需要在您的测试中包含 .xctestconfiguration 文件 运行ner.

一个更简单的解决方案是更改派生数据文件夹的位置 - (在 Xcode 首选项 -> 位置下。

例如我把它放在我的用户文件夹中(类似于我的文档)

这个错误在战斗数小时未成功后立即消失。 (看起来像一个 Xcode 错误)