如何从 Azure DevOps 运行 Microsoft AppCenter 中的 XCUITests
How to run XCUITests in Microsoft AppCenter from Azure DevOps
我 posted issues 在相应的 Microsoft Github 存储库中,但鉴于他们将我重定向到 Whosebug,我将在这里重新 post 这个问题。
我的问题是:如何运行来自 Azure DevOps 的 Microsoft AppCenter 中的自动化 XCUI测试?
我研究了documentation on how to manually build the app from the console and then upload it to AppCenter (which works). Now I would like to use the official 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 文件:
- 使用 XCode 构建原生 iOS 应用程序,该应用程序至少有一个 UI 测试
- 将应用程序上传到 AppCenter 和 运行UI 在真实设备上测试的应用程序
以下来自 Microsoft 文档中的 XCUItest example。
In your pipeline, before the App Center Test task, you will need an Xcode task step with an action of build-for-testing to build the test runner app needed for testing. In that task, under Arguments in the Advanced section, specify a derived data path, typically using -derivedDataPath DerivedData. You will also need an .ipa file for your application. You can build the .ipa file in the same Xcode build-for-testing task by checking the Create app package option, or in a separate Xcode build step or in a Bash script step.
根据上述,您可以尝试设置 packageApp=true
并指定 archivePath
创建的存档应放置的目录。请在此处查看有关 xcode task.
的更多信息
对于以下示例,将创建 .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 Test task, you need to set appFile = $(build.artifactStagingDirectory)/achive/{myapp}.ipa
. and xcUITestBuildDirectory
to the XCUITest bundle location(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
希望以上内容对您有所帮助!
我们最终得到了以下实际有效的构建脚本。请注意,您不能任意组合步骤,因为 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
我 posted issues 在相应的 Microsoft Github 存储库中,但鉴于他们将我重定向到 Whosebug,我将在这里重新 post 这个问题。
我的问题是:如何运行来自 Azure DevOps 的 Microsoft AppCenter 中的自动化 XCUI测试?
我研究了documentation on how to manually build the app from the console and then upload it to AppCenter (which works). Now I would like to use the official 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 文件:
- 使用 XCode 构建原生 iOS 应用程序,该应用程序至少有一个 UI 测试
- 将应用程序上传到 AppCenter 和 运行UI 在真实设备上测试的应用程序
以下来自 Microsoft 文档中的 XCUItest example。
In your pipeline, before the App Center Test task, you will need an Xcode task step with an action of build-for-testing to build the test runner app needed for testing. In that task, under Arguments in the Advanced section, specify a derived data path, typically using -derivedDataPath DerivedData. You will also need an .ipa file for your application. You can build the .ipa file in the same Xcode build-for-testing task by checking the Create app package option, or in a separate Xcode build step or in a Bash script step.
根据上述,您可以尝试设置 packageApp=true
并指定 archivePath
创建的存档应放置的目录。请在此处查看有关 xcode task.
对于以下示例,将创建 .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 Test task, you need to set appFile = $(build.artifactStagingDirectory)/achive/{myapp}.ipa
. and xcUITestBuildDirectory
to the XCUITest bundle location(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
希望以上内容对您有所帮助!
我们最终得到了以下实际有效的构建脚本。请注意,您不能任意组合步骤,因为 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