0

我已经在各自的 Microsoft Github 存储库中发布了 问题,但鉴于他们将我重定向到 Stackoverflow,我将在此处重新发布问题。

我的问题是:如何从 Azure DevOps 在 Microsoft AppCenter 中运行自动化 XCUITests?

我研究了有关如何从控制台手动构建应用程序然后将其上传到 AppCenter(有效)的文档。现在我想使用官方的Azure App Center Test task,它应该做类似的事情。不幸的是,这两个文档有很大不同,我不知道我必须为该步骤提供什么信息才能使其正常工作。

我注意到的最大区别是 AppCenter 文档使用“build-for-testing”和一个 DerivedData 目录来构建上传的内容,而 AppCenterTest 任务需要一个 IPA、一个构建目录和一个测试 IPA 路径。如何获得这些神器?

我试过这样的事情:

- task: Xcode@5
  inputs:
    actions: 'clean build test'
    configuration: 'Debug'
    sdk: 'iphoneos'
    xcWorkspacePath: 'MyProject/MyProject.xcworkspace'
    scheme: 'MyProject'
    packageApp: true
    exportPath: '$(build.artifactStagingDirectory)/debug'
    signingOption: 'manual'
    signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
    provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'
    destinationPlatformOption: 'iOS'
    destinationSimulators: 'iPhone 11'
    publishJUnitResults: true

- task: Xcode@5
  inputs:
    actions: 'build-for-testing'
    configuration: 'Debug'
    sdk: 'iphoneos'
    xcWorkspacePath: 'MyProject/MyProject.xcworkspace'
    scheme: 'MyProject'
    packageApp: false
    args: '-derivedDataPath $(build.artifactStagingDirectory)/DerivedData'

- task: AppCenterTest@1
  inputs:
    appFile: '$(build.artifactStagingDirectory)/DerivedData/Build/Products/Debug-iphoneos/MyProject.app'
    artifactsDirectory: '$(build.artifactStagingDirectory)/AppCenterTest'
    frameworkOption: 'xcuitest'
    xcUITestBuildDirectory: '$(ProjectDir)/Build/Products/Debug-iphoneos'
    xcUITestIpaFile: '$(build.artifactStagingDirectory)/DerivedData/Build/Products/Debug-iphoneos/MyProjectUITests-Runner.app'
    credentialsOption: 'serviceEndpoint'
    serverEndpoint: 'MyCustomer AppCenter Deployment'
    appSlug: 'MyCustomer/MyProject-iOS'
    devices: 'iphoneDevices'
    localeOption: 'en_US'
    skipWaitingForResults: true

但我收到类似的错误##[error]Error: Cannot find any file based on /Users/runner/runners/2.163.1/work/1/a/DerivedData/Build/Products/Debug-iphoneos/MyProject.app

有没有人有一个完整的工作示例并且可以提供一个示例 YAML 文件:

  • 使用至少有一个 UI 测试的 XCode 构建本机 iOS 应用程序
  • 将应用上传到 AppCenter 并在真实设备上运行该 UI 测试
4

2 回答 2

2

我们最终得到了以下实际有效的构建脚本。请注意,您不能任意组合步骤,因为xcode build-for-testing不允许提供签名证书,因此不能与packageApp: true

# Xcode
# Build, test, and archive an Xcode workspace on macOS.
# Add steps that install certificates, test, sign, and distribute an app, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/xcode

trigger:
- master

pool:
  vmImage: 'macos-latest'

steps:
########################################
# Install development certificates     #
########################################
- task: InstallAppleCertificate@2
  inputs:
    certSecureFile: 'MyCompany-distribution.p12'
    certPwd: $(P12password)
    keychain: 'temp'

- task: InstallAppleProvisioningProfile@1
  inputs:
    provisioningProfileLocation: 'sourceRepository'
    provProfileSourceRepository: 'Signing/Distribution_Profile.mobileprovision'

########################################
# Build App and test it locally        #
########################################
- task: Xcode@5
  inputs:
    actions: 'clean build test'
    configuration: 'Debug'
    sdk: 'iphoneos'
    xcWorkspacePath: 'TestApp-iOS/TestApp-iOS.xcodeproj'
    scheme: 'TestApp-iOS'
    destinationPlatformOption: 'iOS'
    destinationSimulators: 'iPhone 11'
    publishJUnitResults: true

###############################################
# Run automated UI Tests on physical devices  #
###############################################
- task: Xcode@5
  inputs:
    actions: 'build-for-testing'
    configuration: 'Debug'
    sdk: 'iphoneos'
    xcWorkspacePath: 'TestApp-iOS/TestApp-iOS.xcodeproj'
    scheme: 'TestApp-iOS'
    packageApp: false
    args: '-derivedDataPath $(build.artifactStagingDirectory)/DerivedData'

- task: Xcode@5
  inputs:
    actions: 'build'
    configuration: 'Release'
    sdk: 'iphoneos'
    xcWorkspacePath: 'TestApp-iOS/TestApp-iOS.xcodeproj'
    scheme: 'TestApp-iOS'
    packageApp: true
    exportPath: '$(build.artifactStagingDirectory)/release'
    signingOption: 'manual'
    signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
    provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'
    destinationPlatformOption: 'iOS'
    destinationSimulators: 'iPhone 11'

- task: AppCenterTest@1
  inputs:
    appFile: '$(Build.ArtifactStagingDirectory)/release/TestApp-iOS.ipa'
    artifactsDirectory: '$(Build.ArtifactStagingDirectory)/AppCenterTest'
    frameworkOption: 'xcuitest'
    xcUITestBuildDirectory: '$(build.artifactStagingDirectory)/DerivedData/Build/Products/Debug-iphoneos'
    credentialsOption: 'serviceEndpoint'
    serverEndpoint: 'MyCompany AppCenter Deployment'
    appSlug: 'MyCompany/Moments-iOS'
    devices: 'MyCompany/iphone11'
    localeOption: 'en_US'
    skipWaitingForResults: true
    showDebugOutput: true
于 2020-02-03T10:17:38.000 回答
1

以下来自 Microsoft 文档中的XCUItest 示例

在您的管道中,在 App Center Test 任务之前,您将需要一个带有 build-for-testing 操作的 Xcode 任务步骤来构建测试所需的测试运行器应用程序。在该任务中,在“高级”部分的“参数”下,指定派生数据路径,通常使用 -derivedDataPath DerivedData。您的应用程序还需要一个 .ipa 文件。您可以通过选中 Create app package 选项,或在单独的 Xcode 构建步骤或 Bash 脚本步骤中,在同一 Xcode 构建测试任务中构建 .ipa 文件。

根据上述,您可以尝试设置packageApp=true并指定archivePath应放置已创建档案的目录。请在此处查看有关xcode 任务的更多信息。

对于以下示例,将创建 .ipa 文件并将其保存到$(build.artifactStagingDirectory)/achive

- task: Xcode@5
  inputs:
    actions: 'build-for-testing'
    configuration: 'Debug'
    sdk: 'iphoneos'
    xcWorkspacePath: 'MyProject/MyProject.xcworkspace'
    scheme: 'MyProject'
    packageApp: true
    archivePath: "$(build.artifactStagingDirectory)/achive"
    args: '-derivedDataPath $(build.artifactStagingDirectory)/DerivedData'

然后在App Center 测试任务中,你需要设置appFile = $(build.artifactStagingDirectory)/achive/{myapp}.ipa. 和xcUITestBuildDirectoryXCUITest捆绑包位置( DerivedData/Build/Products/Debug-iphoneos/)。对于以下示例:

- task: AppCenterTest@1
  inputs:
    appFile: '$(build.artifactStagingDirectory)/achive/{myapp}.ipa'
    artifactsDirectory: '$(build.artifactStagingDirectory)/AppCenterTest'
    frameworkOption: 'xcuitest'
    xcUITestBuildDirectory: '$(build.artifactStagingDirectory)/DerivedData/Build/Products/Debug-iphoneos'
    runTests: true
    username:
    password:
    credentialsOption: 'serviceEndpoint'
    serverEndpoint: 'MyCustomer AppCenter Deployment'
    appSlug: 'MyCustomer/MyProject-iOS'
    devices: 'iphoneDevices'
    localeOption: 'en_US'
    skipWaitingForResults: true

以上希望有帮助!

于 2020-01-27T09:18:17.977 回答