Skip to content

Commit e8b6fce

Browse files
authored
Run UI tests as part of CI (#11)
1 parent 7a7dff8 commit e8b6fce

16 files changed

+472
-69
lines changed

.github/workflows/ci-sample.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ on:
88
pull_request:
99
branches: [ "main" ]
1010

11+
env:
12+
BUILD_CONFIGURATION: Release
13+
CSPROJ_TO_BUILD: samples/Plugin.Maui.UITestHelpers.Sample/Plugin.Maui.UITestHelpers.Sample.csproj
14+
1115
jobs:
1216
build-sample-ci:
1317

1418
runs-on: windows-latest
1519

1620
steps:
1721
- uses: actions/checkout@v4
18-
- name: Build
19-
run: dotnet build samples\Plugin.Maui.UITestHelpers.Sample.sln -c Release
22+
23+
- name: Build Sample App
24+
run: dotnet build ${{ env.CSPROJ_TO_BUILD }} -c ${{ env.BUILD_CONFIGURATION }}

.github/workflows/ui-test-android.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Run UI Tests Android
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths-ignore:
7+
- "**.md"
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
env:
12+
BUILD_CONFIGURATION: Release
13+
CSPROJ_TO_BUILD: samples/Plugin.Maui.UITestHelpers.Sample/Plugin.Maui.UITestHelpers.Sample.csproj
14+
APP_TO_TEST: samples/Plugin.Maui.UITestHelpers.Sample/bin/Release/net8.0-android/com.companyname.uitesthelperssample-Signed.apk
15+
CSPROJ_TO_TEST: samples/UITests.Android/UITests.Android.csproj
16+
APP_ID: com.companyname.uitesthelperssample
17+
TARGET_FRAMEWORK: net8.0-android
18+
TEST_EMULATOR_NAME: UITestEmu
19+
ANDROID_EMULATOR_IMAGE: system-images;android-33;default;x86_64
20+
SCREENCAPTURE_FOLDER: samples/UITests.Android/bin/Debug/net8.0
21+
ARTIFACTS_PATH: ${{ github.workspace }}/output
22+
23+
jobs:
24+
ui-test-android:
25+
26+
runs-on: macos-13
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Restore Workload
32+
run: dotnet workload restore --project ${{ env.CSPROJ_TO_BUILD }}
33+
34+
- name: Publish APK
35+
run: dotnet publish ${{ env.CSPROJ_TO_BUILD }} -f ${{ env.TARGET_FRAMEWORK }}
36+
37+
- name: Install xharness
38+
run: |
39+
dotnet tool install Microsoft.DotNet.XHarness.CLI \
40+
--global \
41+
--add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json \
42+
--version "9.0.0-prerelease*"
43+
44+
- name: Boot Android emulator
45+
run: |
46+
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install '${{ env.ANDROID_EMULATOR_IMAGE }}'
47+
48+
echo "no" | ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/avdmanager create avd --name ${{ env.TEST_EMULATOR_NAME }} --package '${{ env.ANDROID_EMULATOR_IMAGE }}' --force
49+
50+
${ANDROID_HOME}/tools/emulator -avd ${{ env.TEST_EMULATOR_NAME }} -gpu guest -memory 2048 -no-snapshot -no-audio -no-boot-anim -no-window -partition-size 4096 &
51+
52+
# The device is now booting, or close to be booted
53+
# We just wait until the sys.boot_completed property is set to 1.
54+
while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ;
55+
do
56+
echo "Still waiting for boot.."
57+
sleep 10;
58+
done
59+
60+
- name: Install App
61+
run: xharness android install --app=${{ env.APP_TO_TEST }} --package-name=${{ env.APP_ID }} --output-directory=${{ env.ARTIFACTS_PATH }}/xharness-logs
62+
63+
- name: Install Appium
64+
run: |
65+
npm install -g appium
66+
appium driver install uiautomator2
67+
68+
- name: Run UI Tests
69+
run: dotnet test ${{ env.CSPROJ_TO_TEST }} --environment APPIUM_LOG_FILE=${{ env.ARTIFACTS_PATH }}/appium-logs/appium.log --environment APPID="${{ env.APP_ID }}"
70+
71+
- name: Publish Artifacts
72+
uses: actions/upload-artifact@v4
73+
if: always()
74+
with:
75+
name: logs-and-screenshots
76+
path: |
77+
${{ env.ARTIFACTS_PATH }}/**/*.*
78+
${{ env.SCREENCAPTURE_FOLDER }}/*.png

.github/workflows/ui-test-ios.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Run UI Tests iOS
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths-ignore:
7+
- "**.md"
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
env:
12+
# Release builds don't run on the Simulator
13+
BUILD_CONFIGURATION: Debug
14+
CSPROJ_TO_BUILD: samples/Plugin.Maui.UITestHelpers.Sample/Plugin.Maui.UITestHelpers.Sample.csproj
15+
APP_TO_TEST: samples/Plugin.Maui.UITestHelpers.Sample/bin/Debug/net8.0-ios/iossimulator-arm64/Plugin.Maui.UITestHelpers.Sample.app
16+
CSPROJ_TO_TEST: samples/UITests.iOS/UITests.iOS.csproj
17+
APP_ID: com.companyname.uitesthelperssample
18+
TARGET_FRAMEWORK: net8.0-ios
19+
XCODE_VERSION: 15.2
20+
TEST_SIM_NAME: UITestSim
21+
SCREENCAPTURE_FOLDER: samples/UITests.iOS/bin/Debug/net8.0
22+
ARTIFACTS_PATH: ${{ github.workspace }}/output
23+
24+
jobs:
25+
ui-test-ios:
26+
27+
runs-on: macos-14
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Select Xcode version
33+
run: sudo xcode-select -s '/Applications/Xcode_${{ env.XCODE_VERSION }}.app/Contents/Developer'
34+
35+
- name: Restore Workload
36+
run: dotnet workload restore --project ${{ env.CSPROJ_TO_BUILD }}
37+
38+
- name: Build App
39+
run: dotnet build ${{ env.CSPROJ_TO_BUILD }} -f ${{ env.TARGET_FRAMEWORK }} -c ${{ env.BUILD_CONFIGURATION }}
40+
41+
- name: Install xharness
42+
run: |
43+
dotnet tool install Microsoft.DotNet.XHarness.CLI \
44+
--global \
45+
--add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json \
46+
--version "9.0.0-prerelease*"
47+
48+
- name: Install Appium
49+
run: |
50+
npm install -g appium
51+
appium driver install xcuitest
52+
53+
- name: Create iOS Simulator
54+
# This creates a iPhone 15 Pro Simulator with iOS 16.4
55+
run: |
56+
xharness apple simulators install ios-simulator_16.4
57+
simudid=$(xcrun simctl create ${{ env.TEST_SIM_NAME }} com.apple.CoreSimulator.SimDeviceType.iPhone-13 com.apple.CoreSimulator.SimRuntime.iOS-16-4)
58+
echo "SIM_UDID=$(echo $simudid)" >> $GITHUB_ENV
59+
echo "Created Simulator UDID: $simudid"
60+
61+
- name: Install App
62+
run: xharness apple install --app=${{ env.APP_TO_TEST }} --output-directory=${{ env.ARTIFACTS_PATH }}/xharness-logs --device="${{ env.SIM_UDID }}" --target=ios-simulator
63+
64+
- name: Run UI Tests
65+
# We're passing on the values we used to create the Simulator with to the test project to find the correct one
66+
run: |
67+
dotnet test ${{ env.CSPROJ_TO_TEST }} --environment SIMNAME="${{ env.TEST_SIM_NAME }}" --environment SIMID="${{ env.SIM_UDID }}" \
68+
--environment APPIUM_LOG_FILE=${{ env.ARTIFACTS_PATH }}/appium-logs/appium.log --environment APPID="${{ env.APP_ID }}"
69+
70+
- name: Publish Artifacts
71+
uses: actions/upload-artifact@v4
72+
if: always()
73+
with:
74+
name: logs-and-screenshots
75+
path: |
76+
${{ env.ARTIFACTS_PATH }}/**/*.*
77+
${{ env.SCREENCAPTURE_FOLDER }}/*.png

.github/workflows/ui-test-macos.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Run UI Tests macOS
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths-ignore:
7+
- "**.md"
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
env:
12+
BUILD_CONFIGURATION: Release
13+
CSPROJ_TO_BUILD: samples/Plugin.Maui.UITestHelpers.Sample/Plugin.Maui.UITestHelpers.Sample.csproj
14+
APP_TO_TEST: samples/Plugin.Maui.UITestHelpers.Sample/bin/Release/net8.0-maccatalyst/maccatalyst-arm64/Plugin.Maui.UITestHelpers.Sample.app
15+
CSPROJ_TO_TEST: samples/UITests.macOS/UITests.macOS.csproj
16+
APP_ID: com.companyname.uitesthelperssample
17+
TARGET_FRAMEWORK: net8.0-maccatalyst
18+
XCODE_VERSION: 15.2
19+
SCREENCAPTURE_FOLDER: samples/UITests.macOS/bin/Debug/net8.0
20+
ARTIFACTS_PATH: ${{ github.workspace }}/output
21+
22+
jobs:
23+
ui-test-macos:
24+
25+
runs-on: macos-14
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Select Xcode version
31+
run: sudo xcode-select -s '/Applications/Xcode_${{ env.XCODE_VERSION }}.app/Contents/Developer'
32+
33+
- name: Restore Workload
34+
run: dotnet workload restore --project ${{ env.CSPROJ_TO_BUILD }}
35+
36+
- name: Build App
37+
run: dotnet build ${{ env.CSPROJ_TO_BUILD }} -f ${{ env.TARGET_FRAMEWORK }} -c ${{ env.BUILD_CONFIGURATION }}
38+
39+
- name: Install xharness
40+
run: |
41+
dotnet tool install Microsoft.DotNet.XHarness.CLI \
42+
--global \
43+
--add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json \
44+
--version "9.0.0-prerelease*"
45+
46+
- name: Install Appium
47+
run: |
48+
npm install -g appium
49+
appium driver install mac2
50+
51+
- name: Install App
52+
# Deploy the app by running it on this Mac
53+
run: dotnet build ${{ env.CSPROJ_TO_BUILD }} -t:Run -f ${{ env.TARGET_FRAMEWORK }} -c ${{ env.BUILD_CONFIGURATION }}
54+
55+
- name: Run UI Tests
56+
run: |
57+
dotnet test ${{ env.CSPROJ_TO_TEST }} --environment APPIUM_LOG_FILE=${{ env.ARTIFACTS_PATH }}/appium-logs/appium.log --environment APPID="${{ env.APP_ID }}"
58+
59+
- name: Publish Artifacts
60+
uses: actions/upload-artifact@v4
61+
if: always()
62+
with:
63+
name: logs-and-screenshots
64+
path: |
65+
${{ env.ARTIFACTS_PATH }}/**/*.*
66+
${{ env.SCREENCAPTURE_FOLDER }}/*.png

.github/workflows/ui-test-windows.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Run UI Tests Windows
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths-ignore:
7+
- "**.md"
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
env:
12+
BUILD_CONFIGURATION: Release
13+
CSPROJ_TO_BUILD: samples/Plugin.Maui.UITestHelpers.Sample/Plugin.Maui.UITestHelpers.Sample.csproj
14+
APP_TO_TEST: samples/Plugin.Maui.UITestHelpers.Sample/bin/Release/net8.0-windows10.0.19041.0/win10-x64/Plugin.Maui.UITestHelpers.Sample.exe
15+
CSPROJ_TO_TEST: samples/UITests.Windows/UITests.Windows.csproj
16+
TARGET_FRAMEWORK: net8.0-windows10.0.19041.0
17+
SCREENCAPTURE_FOLDER: samples/UITests.Windows/bin/Debug/net8.0
18+
ARTIFACTS_PATH: ${{ github.workspace }}/output
19+
20+
jobs:
21+
ui-test-windows:
22+
23+
runs-on: windows-latest
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Build App
29+
run: dotnet build ${{ env.CSPROJ_TO_BUILD }} -f ${{ env.TARGET_FRAMEWORK }} -c ${{ env.BUILD_CONFIGURATION }}
30+
31+
- name: Install Appium
32+
run: |
33+
npm install -g appium
34+
appium driver install --source=npm appium-windows-driver
35+
36+
- name: Run UI Tests
37+
run: |
38+
# Set environment variable separately because of https://github.com/dotnet/sdk/issues/40848
39+
$absolutePath = ("${{ env.APP_TO_TEST }}" | Resolve-Path).Path
40+
$env:APPID = $absolutePath
41+
dotnet test ${{ env.CSPROJ_TO_TEST }} --environment APPIUM_LOG_FILE=${{ env.ARTIFACTS_PATH }}/appium-logs/appium.log
42+
43+
- name: Publish Artifacts
44+
uses: actions/upload-artifact@v4
45+
if: always()
46+
with:
47+
name: logs-and-screenshots
48+
path: |
49+
${{ env.ARTIFACTS_PATH }}/**/*.*
50+
${{ env.SCREENCAPTURE_FOLDER }}/*.png

samples/Plugin.Maui.UITestHelpers.Sample.sln

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
23
# Visual Studio Version 17
34
VisualStudioVersion = 17.0.31611.283
45
MinimumVisualStudioVersion = 10.0.40219.1
56
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.Maui.UITestHelpers.Sample", "Plugin.Maui.UITestHelpers.Sample\Plugin.Maui.UITestHelpers.Sample.csproj", "{490BB138-9606-4FFF-8AAD-841C5B1ED059}"
67
EndProject
7-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITests.Android", "UITests.Android\UITests.Android.csproj", "{6557E077-F81A-4D64-B3C4-A07BB1BD31D4}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests.Android", "UITests.Android\UITests.Android.csproj", "{6557E077-F81A-4D64-B3C4-A07BB1BD31D4}"
89
EndProject
9-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITests.Shared", "UITests.Shared\UITests.Shared.csproj", "{DFD0E4D0-3519-4B55-8B31-CC7AF8106AAE}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests.Shared", "UITests.Shared\UITests.Shared.csproj", "{DFD0E4D0-3519-4B55-8B31-CC7AF8106AAE}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests.iOS", "UITests.iOS\UITests.iOS.csproj", "{2B36F0AB-6CF2-4EE8-8561-3A436304B744}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests.macOS", "UITests.macOS\UITests.macOS.csproj", "{74557CDA-CB45-4719-9A7D-DE35B10B7345}"
15+
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests.Windows", "UITests.Windows\UITests.Windows.csproj", "{1A0A722B-2D19-42C6-A306-1417A283B244}"
1017
EndProject
1118
Global
1219
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -28,6 +35,18 @@ Global
2835
{DFD0E4D0-3519-4B55-8B31-CC7AF8106AAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
2936
{DFD0E4D0-3519-4B55-8B31-CC7AF8106AAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
3037
{DFD0E4D0-3519-4B55-8B31-CC7AF8106AAE}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{2B36F0AB-6CF2-4EE8-8561-3A436304B744}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{2B36F0AB-6CF2-4EE8-8561-3A436304B744}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{2B36F0AB-6CF2-4EE8-8561-3A436304B744}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{2B36F0AB-6CF2-4EE8-8561-3A436304B744}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{74557CDA-CB45-4719-9A7D-DE35B10B7345}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{74557CDA-CB45-4719-9A7D-DE35B10B7345}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{74557CDA-CB45-4719-9A7D-DE35B10B7345}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{74557CDA-CB45-4719-9A7D-DE35B10B7345}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{1A0A722B-2D19-42C6-A306-1417A283B244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{1A0A722B-2D19-42C6-A306-1417A283B244}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{1A0A722B-2D19-42C6-A306-1417A283B244}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{1A0A722B-2D19-42C6-A306-1417A283B244}.Release|Any CPU.Build.0 = Release|Any CPU
3150
EndGlobalSection
3251
GlobalSection(SolutionProperties) = preSolution
3352
HideSolutionNode = FALSE

samples/Plugin.Maui.UITestHelpers.Sample/Plugin.Maui.UITestHelpers.Sample.csproj

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
<!-- App Identifier -->
1818
<ApplicationId>com.companyname.uitesthelperssample</ApplicationId>
19-
<ApplicationIdGuid>A20E30BB-3BF7-4ACB-89F2-596834136909</ApplicationIdGuid>
2019

2120
<!-- Versions -->
2221
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
@@ -30,6 +29,11 @@
3029
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
3130
</PropertyGroup>
3231

32+
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
33+
<WindowsPackageType>None</WindowsPackageType>
34+
<IsPackable>false</IsPackable>
35+
</PropertyGroup>
36+
3337
<ItemGroup>
3438
<!-- App Icon -->
3539
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

0 commit comments

Comments
 (0)