我正在尝试将我们的 iOS XCUITests 设置为在 AWS Device Farm 上运行,但似乎无论我如何构建和上传它们,测试都不会运行。它们在 XCode 中本地运行时执行并通过,但不在 AWS Device Farm 上运行。
我已经设置了绝对最简单的应用程序,我可以设法隔离这个问题。它由一个带有单个标签的视图和一个验证标签是否存在的 UI 测试组成。
这是 AWS Device Farm 界面中出现的错误。
挖掘日志文件揭示了这一点(在“应用程序输出”日志文件中):
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 文件的过程是:
- 在 Xcode 中,单击产品 > 存档
- 在管理器窗口中选择存档,然后单击导出按钮
- 选择“Save for Ad Hoc Deployment”并点击下一步
- 选择“使用本地签名资产”进行配置
- 选择“为所有兼容设备导出一个应用程序”
- “包括空中安装清单”未选中
- “从位码重建”被选中
- 将 ipa 导出到桌面上的文件夹
我用来生成 UITests ipa 文件的过程是(按照http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-ios-xctest-ui.html的说明):
- 在 Xcode 中,选择“Generic iOS Device”作为构建目标
- 单击产品 > 构建 > 测试
- 打开项目的 XCode Derived Data 文件夹,转到 Build > Intermediates > Debug-iphoneos。这包含 2 个文件:MyTestApp.app 和 MyTestAppUITests-Runner.app
- 在桌面上创建一个名为“Payload”的新目录
- 将 MyTestAppUITests-Runner.app 文件复制到 Payload 目录
- 右键单击有效负载并选择“压缩'有效负载'”
- 将生成的 Payload.zip 文件重命名为 mytestapp-uitests.ipa
我也尝试将 MyTestApp.app 和 MyTestAppUITests-Runner.app 都包含到 mytestapp-uitests.ipa 文件中,但这也不起作用。
要在 Device Farm 中运行测试:
- 在我的测试项目中,单击“创建新运行”
- 选择安卓/iOS
- 上传之前生成的 MyTestApp.ipa 文件(来自 Exporting the Archive),然后单击 Next
- 从列表中选择“XCTest UI”,并上传 mytestapp-uitests.ipa 文件
- 选择由运行 iOS 9.2.1 的 iPad Air 2、iPad Air 和 iPad 2 组成的设备池
- 将设备状态保留为默认设置
- 点击开始运行
请注意,如果我使用相同的应用程序 ipa 文件并运行内置的 Fuzz 测试,这些测试没有问题——我可以看到带有单个标签的测试应用程序的屏幕截图。
我看不到我遗漏的任何明显的东西。我需要做什么才能完成这项工作?