Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add mobile UI Tests #2494

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6dd198f
ci: Add mobile UI Tests
eriklimakc Aug 2, 2024
ff499c4
chore: Android apk name
eriklimakc Aug 6, 2024
084b94d
chore: Adjust bundle name
eriklimakc Aug 6, 2024
70afdd4
chore: Add xCodeRoot
eriklimakc Aug 7, 2024
4d469dc
chore: Update android apk name
eriklimakc Aug 8, 2024
9b16b5d
chore: Use UnoTargetFrameworkOverride
eriklimakc Aug 8, 2024
1289ae7
chore: Add android Internet permission
eriklimakc Aug 8, 2024
aa7cd7e
chore: increase android tests timeout
eriklimakc Aug 9, 2024
0f00968
chore: Search for the .app file
eriklimakc Aug 9, 2024
9dd2d63
chore: Correct ios app name
eriklimakc Aug 9, 2024
3c4f95f
chore: bump xamarin uitest
kazo0 Aug 9, 2024
76dc03b
ci: fail on missing test result file
kazo0 Aug 9, 2024
68efaad
ci: Adjust logger for results
eriklimakc Aug 12, 2024
1681a66
ci: increase ios ui tests timeout
eriklimakc Aug 13, 2024
c870ff7
chore: Adjust tests for android limitations
eriklimakc Aug 14, 2024
1f9b63f
chore: Add Calabash initialization
eriklimakc Aug 20, 2024
3fb19d3
ci: fix android uitests
kazo0 Aug 23, 2024
79ee72c
chore: Fix FeedView style indentation
eriklimakc Aug 28, 2024
599a0a0
test: Fix When_Commerce_Backbutton for android
eriklimakc Aug 28, 2024
12a09ed
fix: Right path for BitmapIcon and changes for android
eriklimakc Aug 28, 2024
ba370c5
test: Android full screen and other fixes
eriklimakc Sep 2, 2024
2fafc66
chore: Wrap GetDisplayScreenScaling with USE_UITESTS
eriklimakc Sep 3, 2024
5d8e3fe
test: Add x:Uid to TextBlocks
eriklimakc Sep 3, 2024
8bb66e7
test: copy android error screenshots
eriklimakc Sep 11, 2024
430eb26
chore: Revert "test: copy android error screenshots"
eriklimakc Sep 12, 2024
7f40024
chore: copy android error screenshots
eriklimakc Sep 12, 2024
b65a75e
chore: Trying to copy screenshots
eriklimakc Sep 16, 2024
7973aca
chore: Adjust android screenshots
eriklimakc Sep 18, 2024
aa47268
chore: Revert "chore: Trying to copy screenshots"
eriklimakc Sep 18, 2024
99fde1b
chore: reset to aafe6327cbfc047e78ccd7ae2463526427b27192 version
eriklimakc Sep 18, 2024
b8d2d7a
chore: Use fast tap to make tests run faster
eriklimakc Sep 20, 2024
7171de9
chore: remove extra slash
eriklimakc Sep 20, 2024
e6a661d
chore: Delay after navigation to test
eriklimakc Sep 24, 2024
0696c49
chore: Add delay to wait element
eriklimakc Sep 25, 2024
7748e9b
test: Revert delay before navigation
eriklimakc Sep 25, 2024
b2b8df2
test: bump android api
eriklimakc Sep 27, 2024
9b56596
test: wait before tapping
eriklimakc Sep 27, 2024
253cadc
chore: change emulator settings
eriklimakc Sep 27, 2024
23eff83
chore: Use Tap instead of FastTap
eriklimakc Sep 27, 2024
82e9dd8
chore: run wasm and ios ui tests
eriklimakc Sep 30, 2024
bf72d4d
chore: Test PlatformHelpers for ios not finding navbar
eriklimakc Oct 3, 2024
8c1ad2f
chore: Test PlatformHelpers for ios not finding navbar
eriklimakc Oct 4, 2024
ec38dd8
chore: Fix to get navbar on ios
eriklimakc Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build/ci/.azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ stages:
# Don't trigger this stage if only docs files are changed
condition: ne(dependencies.Determine_Changes.outputs['evaluate_changes.DetermineChanges.docsOnly'], 'true')
jobs:
- template: stage-build-uitests-wasm.yml
# Temporary disabled to make build faster
#- template: stage-build-uitests-wasm.yml
#- template: stage-build-uitests-android.yml
- template: stage-build-uitests-ios.yml
# Disabled waiting on uno fix: https://github.com/unoplatform/uno/pull/17668
# - template: stage-build-runtimetests-skia.yml
85 changes: 85 additions & 0 deletions build/ci/scripts/android-uitest-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

# echo commands
set -x

export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/screenshots/android
export UNO_UITEST_PLATFORM=Android
export UNO_UITEST_ANDROIDAPK_PATH=$BUILD_SOURCESDIRECTORY/testing/TestHarness/TestHarness/bin/Release/net8.0-android/android-x64/com.companyname.TestHarness-Signed.apk
export UNO_UITEST_PROJECT=$BUILD_SOURCESDIRECTORY/testing/TestHarness/TestHarness.UITest
export UNO_UITEST_ANDROID_PROJECT=$BUILD_SOURCESDIRECTORY/testing/TestHarness/TestHarness
export UNO_UITEST_BINARY=$BUILD_SOURCESDIRECTORY/testing/TestHarness/TestHarness.UITest/bin/Release/net47/TestHarness.UITest.dll
export UNO_EMULATOR_INSTALLED=$BUILD_SOURCESDIRECTORY/build/.emulator_started
export UITEST_TEST_TIMEOUT=60m
export ANDROID_SIMULATOR_APILEVEL=28

# Override Android SDK tooling
export ANDROID_HOME=$BUILD_SOURCESDIRECTORY/build/android-sdk
export ANDROID_SDK_ROOT=$BUILD_SOURCESDIRECTORY/build/android-sdk
export CMDLINETOOLS=commandlinetools-mac-8512546_latest.zip
mkdir -p $ANDROID_HOME
wget https://dl.google.com/android/repository/$CMDLINETOOLS
unzip $CMDLINETOOLS -d $ANDROID_HOME/cmdline-tools
rm $CMDLINETOOLS
mv $ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest

if [[ -f $ANDROID_HOME/platform-tools/platform-tools/adb ]]
then
# It appears that the platform-tools 29.0.6 are extracting into an incorrect path
mv $ANDROID_HOME/platform-tools/platform-tools/* $ANDROID_HOME/platform-tools
fi

# Install Android SDK emulators and SDKs
if [ ! -f "$UNO_EMULATOR_INSTALLED" ];
then
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install 'tools'| tr '\r' '\n' | uniq
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install 'platform-tools' | tr '\r' '\n' | uniq
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install 'build-tools;34.0.0' | tr '\r' '\n' | uniq
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install "platforms;android-$ANDROID_SIMULATOR_APILEVEL" | tr '\r' '\n' | uniq
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install 'platforms;android-34' | tr '\r' '\n' | uniq
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install 'extras;android;m2repository' | tr '\r' '\n' | uniq

# Install AVD files
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install "system-images;android-$ANDROID_SIMULATOR_APILEVEL;google_apis_playstore;x86_64"

# Create emulator
echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n xamarin_android_emulator --abi "x86_64" -k "system-images;android-$ANDROID_SIMULATOR_APILEVEL;google_apis_playstore;x86_64" --force

echo $ANDROID_HOME/emulator/emulator -list-avds

echo "Starting emulator"

# Start emulator in background
nohup $ANDROID_HOME/emulator/emulator -avd xamarin_android_emulator -skin 1280x800 -memory 4096 -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim > /dev/null 2>&1 &

touch "$UNO_EMULATOR_INSTALLED"
fi

# Build the sample, while the emulator is starting
cd $UNO_UITEST_ANDROID_PROJECT
dotnet publish -f net8.0-android -p:UnoTargetFrameworkOverride=net8.0-android -c Release -p:RuntimeIdentifier=android-x64 /p:IsUiAutomationMappingEnabled=True /p:AndroidUseSharedRuntime=false /p:AotAssemblies=false -bl:$BUILD_ARTIFACTSTAGINGDIRECTORY/android-app.binlog

cd $BUILD_SOURCESDIRECTORY/build

mkdir -p $UNO_UITEST_SCREENSHOT_PATH

cp $UNO_UITEST_ANDROIDAPK_PATH $UNO_UITEST_SCREENSHOT_PATH

# Wait for the emulator to finish booting
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'

$ANDROID_HOME/platform-tools/adb devices

echo "Emulator started"

cd $UNO_UITEST_PROJECT

dotnet test \
-c Release \
-l:"console;verbosity=normal" \
--logger "nunit;LogFileName=$BUILD_SOURCESDIRECTORY/build/TestResult.xml" \
--blame-hang-timeout $UITEST_TEST_TIMEOUT \
-v m \
|| true
93 changes: 93 additions & 0 deletions build/ci/scripts/ios-uitest-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

export UNO_UITEST_PLATFORM=iOS
export UNO_UITEST_IOSBUNDLE_PATH=$BUILD_SOURCESDIRECTORY/testing/TestHarness/TestHarness/bin/Release/net8.0-ios/iossimulator-x64/TestHarnessApp.app
export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/screenshots/ios
export UNO_UITEST_PROJECT=$BUILD_SOURCESDIRECTORY/testing/TestHarness/TestHarness.UITest
export UNO_UITEST_LOGFILE=$BUILD_ARTIFACTSTAGINGDIRECTORY/screenshots/ios/nunit-log.txt
export UNO_UITEST_IOS_PROJECT=$BUILD_SOURCESDIRECTORY/testing/TestHarness/TestHarness
export UITEST_TEST_TIMEOUT=90m
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved
export UNO_UITEST_SIMULATOR_VERSION="com.apple.CoreSimulator.SimRuntime.iOS-17-2"
export UNO_UITEST_SIMULATOR_NAME="iPad Pro (12.9-inch) (6th generation)"

echo "Listing iOS simulators"
xcrun simctl list devices --json

/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator &

# Prime the output directory
mkdir -p $UNO_UITEST_SCREENSHOT_PATH/_logs

cd $UNO_UITEST_IOS_PROJECT
dotnet build -p:UnoTargetFrameworkOverride=net8.0-ios -r iossimulator-x64 -c Release -p:IsUiAutomationMappingEnabled=True -bl:$BUILD_ARTIFACTSTAGINGDIRECTORY/ios-app.binlog

##
## Pre-install the application to avoid https://github.com/microsoft/appcenter/issues/2389
##

## Install iOS 17.2 simulators
xcodes runtimes install --keep-archive 'iOS 17.2' || true

# Wait while ios runtime 17.2 is not having simulators. The install process may
# take a few seconds and "simctl list devices" may not return devices.
while true; do
export UITEST_IOSDEVICE_ID=`xcrun simctl list -j | jq -r --arg sim "$UNO_UITEST_SIMULATOR_VERSION" --arg name "$UNO_UITEST_SIMULATOR_NAME" '.devices[$sim] | .[] | select(.name==$name) | .udid'`
export UITEST_IOSDEVICE_DATA_PATH=`xcrun simctl list -j | jq -r --arg sim "$UNO_UITEST_SIMULATOR_VERSION" --arg name "$UNO_UITEST_SIMULATOR_NAME" '.devices[$sim] | .[] | select(.name==$name) | .dataPath'`

if [ -n "$UITEST_IOSDEVICE_ID" ]; then
break
fi

echo "Waiting for the simulator to be available"
sleep 5
done

echo "Simulator Data Path: $UITEST_IOSDEVICE_DATA_PATH"
cp "$UITEST_IOSDEVICE_DATA_PATH/../device.plist" $UNO_UITEST_SCREENSHOT_PATH/_logs

echo "Starting simulator: [$UITEST_IOSDEVICE_ID] ($UNO_UITEST_SIMULATOR_VERSION / $UNO_UITEST_SIMULATOR_NAME)"

# check for the presence of idb, and install it if it's not present
export PATH=$PATH:~/.local/bin

if ! command -v idb &> /dev/null
then
echo "Installing idb"
brew install pipx
# # https://github.com/microsoft/appcenter/issues/2605#issuecomment-1854414963
brew tap facebook/fb
brew install idb-companion
pipx install fb-idb
else
echo "Using idb from:" `command -v idb`
fi

xcrun simctl boot "$UITEST_IOSDEVICE_ID" || true

idb install --udid "$UITEST_IOSDEVICE_ID" "$UNO_UITEST_IOSBUNDLE_PATH"


# Run the tests

cd $UNO_UITEST_PROJECT

dotnet test \
-c Release \
-l:"console;verbosity=normal" \
--logger:"nunit;LogFileName=$BUILD_SOURCESDIRECTORY/build/TestResult.xml" \
--blame-hang-timeout $UITEST_TEST_TIMEOUT \
-v m \
|| true


cp $BUILD_SOURCESDIRECTORY/build/TestResult.xml" $UNO_UITEST_SCREENSHOT_PATH

# export the simulator logs
export LOG_FILEPATH=$UNO_UITEST_SCREENSHOT_PATH/_logs
export TMP_LOG_FILEPATH=/tmp/DeviceLog-`date +"%Y%m%d%H%M%S"`.logarchive
export LOG_FILEPATH_FULL=$LOG_FILEPATH/DeviceLog-`date +"%Y%m%d%H%M%S"`.txt

# xcrun simctl spawn booted log collect --output $TMP_LOG_FILEPATH
# log show --style syslog $TMP_LOG_FILEPATH > $LOG_FILEPATH_FULL
43 changes: 43 additions & 0 deletions build/ci/stage-build-uitests-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
jobs:
- job: Android_Tests
displayName: 'Android UI Tests'
timeoutInMinutes: 90
variables:
CI_Build: true
SourceLinkEnabled: false

pool:
vmImage: 'macos-14'

steps:
- checkout: self
clean: true

- template: templates/dotnet-install-mac.yml
- template: templates/canary-updater.yml

- bash: |
chmod +x $(build.sourcesdirectory)/build/ci/scripts/android-uitest-run.sh
$(build.sourcesdirectory)/build/ci/scripts/android-uitest-run.sh
displayName: Build and Run Android Tests
env:
BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)"
BUILD_ARTIFACTSTAGINGDIRECTORY: "$(build.artifactstagingdirectory)"

- task: PublishTestResults@2
condition: always()
retryCountOnTaskFailure: 2
inputs:
testRunTitle: 'Android Test Run'
testResultsFormat: 'NUnit'
testResultsFiles: '$(build.sourcesdirectory)/build/TestResult.xml'
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true

- task: PublishBuildArtifacts@1
condition: always()
retryCountOnTaskFailure: 2
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
ArtifactName: uno-uitest-tests
ArtifactType: Container
56 changes: 56 additions & 0 deletions build/ci/stage-build-uitests-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
jobs:
- job: iOS_Tests
displayName: 'iOS UI Tests'
timeoutInMinutes: 90
variables:
CI_Build: true
SourceLinkEnabled: false

pool:
vmImage: 'macos-14'

steps:
- checkout: self
clean: true

- template: templates/dotnet-install-mac.yml

- template: templates/xcode-select.yml
parameters:
xCodeRoot: '/Applications/Xcode_15.2.app'

- template: templates/canary-updater.yml

- bash: |
chmod +x $(build.sourcesdirectory)/build/ci/scripts/ios-uitest-run.sh
$(build.sourcesdirectory)/build/ci/scripts/ios-uitest-run.sh
displayName: Build and Run iOS Test
env:
BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)"
BUILD_ARTIFACTSTAGINGDIRECTORY: "$(build.artifactstagingdirectory)"

- task: PublishTestResults@2
condition: always()
retryCountOnTaskFailure: 2
inputs:
testRunTitle: 'iOS Test Run'
testResultsFormat: 'NUnit'
testResultsFiles: '$(build.sourcesdirectory)/build/TestResult.xml'
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true

- task: PublishBuildArtifacts@1
condition: always()
retryCountOnTaskFailure: 2
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
ArtifactName: uno-uitest-tests
ArtifactType: Container

- task: PublishBuildArtifacts@1
condition: always()
retryCountOnTaskFailure: 2
inputs:
PathtoPublish: $(build.sourcesdirectory)/testing/TestHarness/TestHarness/bin/Release/net8.0-ios/iossimulator-x64/TestHarnessApp.app
ArtifactName: uno-uitest-ios-bin
ArtifactType: Container
1 change: 1 addition & 0 deletions build/ci/stage-build-uitests-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
testResultsFormat: 'NUnit'
testResultsFiles: '$(build.sourcesdirectory)/build/TestResult.xml'
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true

- task: PublishBuildArtifacts@1
condition: always()
Expand Down
18 changes: 18 additions & 0 deletions build/ci/templates/canary-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,21 @@ steps:
- template: canary-update-template.yml
parameters:
SolutionToUpdate: 'testing/TestHarness/TestHarness.sln'

- pwsh: |
gci -r -include "info.plist" |
foreach-object {
$a = $_.fullname; ( get-content $a ) |
foreach-object { $_ -replace "com.companyname.TestHarness","com.companyname.TestHarness-canary" } |
set-content $a }
displayName: 'Adjust info.plist bundle name'
condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/canaries')

- pwsh: |
gci -r -include AndroidManifest.xml,android-uitest-run.sh |
foreach-object {
$a = $_.fullname; ( get-content $a ) |
foreach-object { $_ -replace "com.companyname.TestHarness","com.companyname.TestHarness.canary" } |
set-content $a }
displayName: 'Adjust AndroidManifest bundle name'
condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/canaries')
10 changes: 10 additions & 0 deletions build/ci/templates/xcode-select.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
xCodeRoot: ''

steps:
- bash: |
echo 'Xcode Root to ${{parameters.xCodeRoot}}'
echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'${{parameters.xCodeRoot}}
sudo xcode-select --switch ${{parameters.xCodeRoot}}/Contents/Developer

displayName: Select Xcode
Loading
Loading