onnxruntime/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml
Caroline Zhu 0221693e43
[Mobile] Add E2E BrowserStack tests for iOS tests (#22610)
### Description
- Changes running the E2E iOS tests from running in App Center to
running in BrowserStack
- Steps for running locally can be found in the OneNote

### Motivation and Context
- Follow-up of #22117 
- App Center (the previous platform for running E2E mobile tests) is
getting deprecated in 2025

### Misc info
Additional build steps were required to get the necessary testing
artifacts for BrowserStack. App Center consumed an entire folder, while
BrowserStack requests the following:
1. a ZIP file of all the tests
2. an IPA file of the test app

#### Flow
Here is a rough outline of what is happening in the pipeline:
1. The build_and_assemble_apple_pods.py script builds the relevant
frameworks (currently, this means packages for iOS and Mac)
4. The test_apple_packages.py script installs the necessary cocoapods
for later steps
5. XCode task to build for testing builds the iOS target for the test
app
6. Now that the test app and the tests have been built, we can zip them,
creating the tests .zip file
7. To create the IPA file, we need to create a .plist XML file which is
generated by the generate_plist.py script.
- Attempts to use the Xcode@5 task to automatically generate the plist
file failed.
- Also, building for testing generates some plist files -- these cannot
be used to export an IPA file.
8. We run the Xcode task to build an .xcarchive file, which is required
for creating an IPA file.
9. We use xcodebuild in a script step to build an IPA file with the
xcarchive and plist files from the last two steps.
10. Finally, we can run the tests using the BrowserStack script.

---------

Co-authored-by: Scott McKay <skottmckay@gmail.com>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
2024-11-06 11:22:29 -08:00

96 lines
2.8 KiB
YAML

parameters:
- name: artifactName
displayName: Artifact Name
type: string
default: ''
- name: job_name_suffix
displayName: job name
type: string
default: ''
- name: packageName
displayName: Package Name
type: string
default: 'onnxruntime-android'
- name: ReleaseVersionSuffix
displayName: Release Version Suffix
type: string
default: ''
jobs:
- job: Final_AAR_Testing_Android_${{ parameters.job_name_suffix }}
workspace:
clean: all
pool:
vmImage: 'macOS-13'
variables:
- name: runCodesignValidationInjection
value: false
timeoutInMinutes: 90
dependsOn:
- Android_Java_API_AAR_Packaging_${{ parameters.job_name_suffix }}
steps:
- template: set-version-number-variables-step.yml
- task: DownloadPipelineArtifact@2
displayName: 'Download Final Android AAR'
inputs:
buildType: 'current'
artifactName: '${{parameters.artifactName}}'
targetPath: '$(Build.BinariesDirectory)/final-android-aar'
- task: JavaToolInstaller@0
displayName: Use jdk 17
inputs:
versionSpec: '17'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
- template: use-android-ndk.yml
- template: use-android-emulator.yml
parameters:
create: true
start: true
- script: |
set -e -x
mkdir android_test
cd android_test
cp -av $(Build.SourcesDirectory)/java/src/test/android ./
cd ./android
mkdir -p app/libs
cp $(Build.BinariesDirectory)/final-android-aar/${{parameters.packageName}}-$(OnnxRuntimeVersion)${{parameters.ReleaseVersionSuffix}}.aar app/libs/onnxruntime-android.aar
$(Build.SourcesDirectory)/java/gradlew --no-daemon clean connectedDebugAndroidTest --stacktrace
displayName: Run E2E test using Emulator
workingDirectory: $(Build.BinariesDirectory)
- template: use-android-emulator.yml
parameters:
stop: true
# we run e2e tests on one older device (Pixel 3) and one newer device (Galaxy 23)
- script: |
set -e -x
pip install requests
python $(Build.SourcesDirectory)/tools/python/upload_and_run_browserstack_tests.py \
--test_platform espresso \
--app_path "debug/app-debug.apk" \
--test_path "androidTest/debug/app-debug-androidTest.apk" \
--devices "Samsung Galaxy S23-13.0" "Google Pixel 3-9.0"
displayName: Run E2E tests using Browserstack
workingDirectory: $(Build.BinariesDirectory)/android_test/android/app/build/outputs/apk
timeoutInMinutes: 15
env:
BROWSERSTACK_ID: $(browserstack_username)
BROWSERSTACK_TOKEN: $(browserstack_access_key)
- template: component-governance-component-detection-steps.yml
parameters :
condition : 'succeeded'
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
displayName: 'Clean Agent Directories'
condition: always()