Skip to content

Commit

Permalink
Add support for the full TCP mode in the visual runner (#26)
Browse files Browse the repository at this point in the history
* Added a TCP result channel
* ResultChannels are now services
   Channels will also need access for services, so they are now in the
   collection. Access is now through the singleton manager to avoid
   duplicate openings or premature closings.
  • Loading branch information
mattleibow authored Mar 14, 2024
1 parent 710047c commit b752406
Show file tree
Hide file tree
Showing 42 changed files with 594 additions and 345 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"microsoft.dotnet.xharness.cli": {
"version": "8.0.0-prerelease.23326.1",
"version": "9.0.0-prerelease.24161.1",
"commands": [
"xharness"
]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Build
run: dotnet build --configuration Release /bl:./artifacts/logs/msbuild-build.binlog
run: dotnet build DeviceRunners.sln --configuration Release /bl:./artifacts/logs/msbuild-build.binlog
- name: Upload Logs
uses: actions/upload-artifact@v1
if: ${{ always() }}
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Build
run: dotnet build --configuration Debug /bl:./artifacts/logs/msbuild-build.binlog
run: dotnet build DeviceRunners.sln --configuration Debug /bl:./artifacts/logs/msbuild-build.binlog
- name: Upload Logs
uses: actions/upload-artifact@v1
if: ${{ always() }}
Expand Down
171 changes: 171 additions & 0 deletions .github/workflows/test-xharness.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: XHarness Test

on:
pull_request:
push:
branches: [ main, 'releases/**' ]
release:
types: [ published ]

jobs:

ios:
name: iOS
runs-on: macos-13
env:
TEST_TARGET_FRAMEWORK: net8.0-ios
TEST_RUNTIME_IDENTIFIER: iossimulator-x64
TEST_CONFIGURATION: Debug
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Publish App
run: |
dotnet build sample/SampleMauiApp/SampleMauiApp.csproj \
-f ${{ env.TEST_TARGET_FRAMEWORK }} \
-r ${{ env.TEST_RUNTIME_IDENTIFIER }} \
-c ${{ env.TEST_CONFIGURATION }} \
-p:TestingMode=XHarness \
/bl:./artifacts/logs/msbuild-publish.binlog
- name: Run Tests
run: |
for i in $(seq 1 2)
do
dotnet xharness apple test \
--target ios-simulator-64 \
--timeout="00:02:00" \
--launch-timeout=00:06:00 \
--app sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/SampleMauiApp.app \
--output-directory artifacts \
&& code=0 && break || code=$? && sleep 15
done
exit $code
- name: Upload Artifacts
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: Test Results - iOS
path: ./artifacts


maccatalyst:
name: Mac Catalyst
runs-on: macos-13
env:
TEST_TARGET_FRAMEWORK: net8.0-maccatalyst
TEST_RUNTIME_IDENTIFIER: maccatalyst-x64
TEST_CONFIGURATION: Debug
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Publish App
run: |
dotnet build sample/SampleMauiApp/SampleMauiApp.csproj \
-f ${{ env.TEST_TARGET_FRAMEWORK }} \
-r ${{ env.TEST_RUNTIME_IDENTIFIER }} \
-c ${{ env.TEST_CONFIGURATION }} \
-p:TestingMode=XHarness \
/bl:./artifacts/logs/msbuild-publish.binlog
- name: Run Tests
run: |
dotnet xharness apple test \
--target maccatalyst \
--timeout="00:02:00" \
--launch-timeout=00:06:00 \
--app sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/SampleMauiApp.app \
--output-directory artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: Test Results - Mac Catalyst
path: ./artifacts


windows:
name: Windows
runs-on: windows-latest
env:
TEST_TARGET_FRAMEWORK: net8.0-windows10.0.19041.0
TEST_RUNTIME_IDENTIFIER: win10-x64
TEST_CONFIGURATION: Release
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Publish App
run: |
$fingerprint = ./scripts/New-Certificate.ps1 -Project sample/SampleMauiApp/SampleMauiApp.csproj
dotnet publish sample/SampleMauiApp/SampleMauiApp.csproj `
-f ${{ env.TEST_TARGET_FRAMEWORK }} `
-c ${{ env.TEST_CONFIGURATION }} `
-p:TestingMode=XHarness `
-p:AppxPackageSigningEnabled=true `
-p:PackageCertificateThumbprint=$fingerprint `
-p:PackageCertificateKeyFile="" `
/bl:./artifacts/logs/msbuild-publish.binlog
./scripts/Remove-Certificate.ps1 -CertificateFingerprint $fingerprint
- name: Run Tests
run: |
$msix = Get-ChildItem "sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/AppPackages/*_Test/*.msix"
./scripts/Start-Tests.ps1 `
-App $msix `
-OutputDirectory artifacts `
-TestingMode XHarness
shell: powershell
- name: Upload Artifacts
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: Test Results - Windows
path: ./artifacts


# android:
# name: Android
# runs-on: macos-13
# env:
# TEST_TARGET_FRAMEWORK: net8.0-android
# TEST_RUNTIME_IDENTIFIER: android-x64
# TEST_CONFIGURATION: Release
# TEST_EMULATOR_IMAGE: system-images;android-34;google_apis;x86_64
# TEST_EMULATOR_DEVICE: pixel_5
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Setup Required Tools
# uses: ./.github/workflows/setup-tools
# - name: Install Emulator Image
# run: dotnet android sdk install --package "${{ env.TEST_EMULATOR_IMAGE }}"
# - name: Create the Emulator
# run: dotnet android avd create --name TestRunnerEmulator --sdk "${{ env.TEST_EMULATOR_IMAGE }}" --device "${{ env.TEST_EMULATOR_DEVICE }}"
# - name: Boot the Emulator
# run: dotnet android avd start --name TestRunnerEmulator --wait-boot
# - name: Publish App
# run: |
# dotnet publish sample/SampleMauiApp/SampleMauiApp.csproj \
# -f ${{ env.TEST_TARGET_FRAMEWORK }} \
# -r ${{ env.TEST_RUNTIME_IDENTIFIER }} \
# -c ${{ env.TEST_CONFIGURATION }} \
# -p:TestingMode=XHarness \
# /bl:./artifacts/logs/msbuild-publish.binlog
# - name: Run Tests
# run: |
# xharness android test \
# --package-name com.companyname.samplemauiapp \
# --instrumentation devicerunners.xharness.maui.XHarnessInstrumentation \
# --app sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/publish/com.companyname.samplemauiapp-Signed.apk
# --output-directory artifacts
# - name: Shutdown the Emulator
# run: dotnet xharness android adb -- emu kill
# - name: Upload Artifacts
# uses: actions/upload-artifact@v1
# if: ${{ always() }}
# with:
# name: Test Results - Android
# path: ./artifacts
143 changes: 15 additions & 128 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,149 +9,36 @@ on:

jobs:

ios:
name: iOS
runs-on: macos-13
env:
TEST_TARGET_FRAMEWORK: net8.0-ios
TEST_RUNTIME_IDENTIFIER: iossimulator-x64
TEST_CONFIGURATION: Debug
windows:
name: Windows
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Publish App
run: |
dotnet build sample/SampleMauiApp/SampleMauiApp.csproj \
-f ${{ env.TEST_TARGET_FRAMEWORK }} \
-r ${{ env.TEST_RUNTIME_IDENTIFIER }} \
-c ${{ env.TEST_CONFIGURATION }} \
/bl:./artifacts/logs/msbuild-publish.binlog
- name: Run Tests
run: |
dotnet xharness apple test \
--target ios-simulator-64 \
--app sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/SampleMauiApp.app \
--output-directory artifacts
- name: Upload Artifacts
- name: Test
run: dotnet test test/DeviceRunners.VisualRunners.Tests --configuration Release /bl:./artifacts/logs/msbuild-test.binlog
- name: Upload Logs
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: Test Results - iOS
path: ./artifacts

name: Logs - Windows
path: ./artifacts/logs

maccatalyst:
name: Mac Catalyst
macos:
name: macOS
runs-on: macos-13
env:
TEST_TARGET_FRAMEWORK: net8.0-maccatalyst
TEST_RUNTIME_IDENTIFIER: maccatalyst-x64
TEST_CONFIGURATION: Debug
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Publish App
run: |
dotnet build sample/SampleMauiApp/SampleMauiApp.csproj \
-f ${{ env.TEST_TARGET_FRAMEWORK }} \
-r ${{ env.TEST_RUNTIME_IDENTIFIER }} \
-c ${{ env.TEST_CONFIGURATION }} \
/bl:./artifacts/logs/msbuild-publish.binlog
- name: Run Tests
run: |
dotnet xharness apple test \
--target maccatalyst \
--app sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/SampleMauiApp.app \
--output-directory artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: Test Results - Mac Catalyst
path: ./artifacts


windows:
name: Windows
runs-on: windows-latest
env:
TEST_TARGET_FRAMEWORK: net8.0-windows10.0.19041.0
TEST_RUNTIME_IDENTIFIER: win10-x64
TEST_CONFIGURATION: Release
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Required Tools
uses: ./.github/workflows/setup-tools
- name: Publish App
run: |
$fingerprint = ./scripts/New-Certificate.ps1 -Project sample/SampleMauiApp/SampleMauiApp.csproj
dotnet publish sample/SampleMauiApp/SampleMauiApp.csproj `
-f ${{ env.TEST_TARGET_FRAMEWORK }} `
-c ${{ env.TEST_CONFIGURATION }} `
-p:AppxPackageSigningEnabled=true `
-p:PackageCertificateThumbprint=$fingerprint `
-p:PackageCertificateKeyFile="" `
/bl:./artifacts/logs/msbuild-publish.binlog
./scripts/Remove-Certificate.ps1 -CertificateFingerprint $fingerprint
- name: Run Tests
run: |
$msix = Get-ChildItem "sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/AppPackages/*_Test/*.msix"
./scripts/Start-Tests.ps1 `
-App $msix `
-OutputDirectory artifacts
shell: powershell
- name: Upload Artifacts
- name: Test
run: dotnet test test/DeviceRunners.VisualRunners.Tests --configuration Release /bl:./artifacts/logs/msbuild-test.binlog
- name: Upload Logs
uses: actions/upload-artifact@v1
if: ${{ always() }}
with:
name: Test Results - Windows
path: ./artifacts


# android:
# name: Android
# runs-on: macos-13
# env:
# TEST_TARGET_FRAMEWORK: net8.0-android
# TEST_RUNTIME_IDENTIFIER: android-x64
# TEST_CONFIGURATION: Release
# TEST_EMULATOR_IMAGE: system-images;android-34;google_apis;x86_64
# TEST_EMULATOR_DEVICE: pixel_5
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Setup Required Tools
# uses: ./.github/workflows/setup-tools
# - name: Install Emulator Image
# run: dotnet android sdk install --package "${{ env.TEST_EMULATOR_IMAGE }}"
# - name: Create the Emulator
# run: dotnet android avd create --name TestRunnerEmulator --sdk "${{ env.TEST_EMULATOR_IMAGE }}" --device "${{ env.TEST_EMULATOR_DEVICE }}"
# - name: Boot the Emulator
# run: dotnet android avd start --name TestRunnerEmulator --wait-boot
# - name: Publish App
# run: |
# dotnet publish sample/SampleMauiApp/SampleMauiApp.csproj \
# -f ${{ env.TEST_TARGET_FRAMEWORK }} \
# -r ${{ env.TEST_RUNTIME_IDENTIFIER }} \
# -c ${{ env.TEST_CONFIGURATION }} \
# /bl:./artifacts/logs/msbuild-publish.binlog
# - name: Run Tests
# run: |
# xharness android test \
# --package-name com.companyname.samplemauiapp \
# --instrumentation devicerunners.xharness.maui.XHarnessInstrumentation \
# --app sample/SampleMauiApp/bin/${{ env.TEST_CONFIGURATION }}/${{ env.TEST_TARGET_FRAMEWORK }}/${{ env.TEST_RUNTIME_IDENTIFIER }}/publish/com.companyname.samplemauiapp-Signed.apk
# --output-directory artifacts
# - name: Shutdown the Emulator
# run: dotnet xharness android adb -- emu kill
# - name: Upload Artifacts
# uses: actions/upload-artifact@v1
# if: ${{ always() }}
# with:
# name: Test Results - Android
# path: ./artifacts
name: Logs - macOS
path: ./artifacts/logs
13 changes: 12 additions & 1 deletion sample/SampleMauiApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

using DeviceRunners.UITesting;
using DeviceRunners.VisualRunners;
#if MODE_XHARNESS
using DeviceRunners.XHarness;
#endif

namespace SampleMauiApp;

Expand All @@ -13,13 +15,22 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
builder
.ConfigureUITesting()
#if MODE_XHARNESS
.UseXHarnessTestRunner(conf => conf
.AddTestAssembly(typeof(MauiProgram).Assembly)
.AddTestAssemblies(typeof(SampleXunitTestProject.UnitTests).Assembly)
.AddXunit())
#endif
.UseVisualTestRunner(conf => conf
#if ENABLE_AUTO_START
#if MODE_NON_INTERACTIVE_VISUAL
.EnableAutoStart(true)
.AddTcpResultChannel(new TcpResultChannelOptions
{
HostNames = ["localhost", "10.0.2.2"],
Port = 16384,
Formatter = new TextResultChannelFormatter(),
Required = false
})
#endif
.AddConsoleResultChannel()
.AddTestAssembly(typeof(MauiProgram).Assembly)
Expand Down
Loading

0 comments on commit b752406

Please sign in to comment.