Skip to content

Commit

Permalink
Enable Uno Wasm UI Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 23, 2020
1 parent ed292e8 commit 073790c
Show file tree
Hide file tree
Showing 22 changed files with 479 additions and 30 deletions.
3 changes: 3 additions & 0 deletions build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ variables:
value: windows-latest
- name: MacImage
value: macOS-latest
- name: LinuxImage
value: ubuntu-latest
- name: BuildConfiguration
value: Release
- name: BuildPlatform
Expand Down Expand Up @@ -72,6 +74,7 @@ stages:
versionName: '8.0.$(Build.BuildId)'

- template: jobs/xamarin-uitest.yml
- template: jobs/uno-uitest.yml

- template: jobs/e2e-uitest.yml
parameters:
Expand Down
2 changes: 0 additions & 2 deletions build/jobs/prism-uno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ jobs:
parameters:
solution: PrismLibrary_Uno.sln
solutionName: Prism.Uno

# - template: ../steps/test-uno.yml
107 changes: 107 additions & 0 deletions build/jobs/uno-uitest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
jobs:

- job: UnoUITest_Wasm
displayName: Uno UITest WebAssembly

container: unoplatform/wasm-build:2.0

pool:
vmImage: $(LinuxImage)

workspace:
clean: all

steps:

- bash: |
build/scripts/wasm-uitest-run.sh
env:
BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)"
BUILD_ARTIFACTSTAGINGDIRECTORY: "$(build.artifactstagingdirectory)"
displayName: 'Run UI Tests'
- task: PublishTestResults@2
condition: always()
inputs:
testRunTitle: 'WebAssembly Test Run'
testResultsFormat: 'NUnit'
testResultsFiles: '$(build.sourcesdirectory)/build/TestResult.xml'

- task: PublishBuildArtifacts@1
condition: always()
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
ArtifactName: UnoUITests
ArtifactType: Container


- job: UnoUITest_Android
displayName: Uno UITest Android

pool:
vmImage: $(MacImage)

workspace:
clean: all

steps:

- bash: |
build/scripts/android-uitest-run.sh
env:
BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)"
BUILD_ARTIFACTSTAGINGDIRECTORY: "$(build.artifactstagingdirectory)"
displayName: 'Run UI Tests'
- task: PublishTestResults@2
condition: always()
inputs:
testRunTitle: 'Android Test Run'
testResultsFormat: 'NUnit'
testResultsFiles: '$(build.sourcesdirectory)/build/TestResult.xml'

- task: PublishBuildArtifacts@1
condition: always()
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
ArtifactName: UnoUITests
ArtifactType: Container


- job: UnoUITest_iOS
displayName: Uno UITest iOS

pool:
vmImage: $(MacImage)

workspace:
clean: all

steps:

- bash: |
build/scripts/ios-uitest-run.sh
env:
BUILD_SOURCESDIRECTORY: "$(build.sourcesdirectory)"
BUILD_ARTIFACTSTAGINGDIRECTORY: "$(build.artifactstagingdirectory)"
displayName: 'Run UI Tests'
- task: PublishTestResults@2
inputs:
testRunTitle: 'iOS Test Run'
testResultsFormat: 'NUnit'
testResultsFiles: '$(build.sourcesdirectory)/build/TestResult.xml'

- task: PublishBuildArtifacts@1
condition: always()
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
ArtifactName: UnoUITests
ArtifactType: Container

41 changes: 41 additions & 0 deletions build/scripts/android-uitest-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# Install AVD files
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-28;google_apis;x86'

# Create emulator
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n xamarin_android_emulator -k 'system-images;android-28;google_apis;x86' --force

echo $ANDROID_HOME/emulator/emulator -list-avds

echo "Starting emulator"

# Start emulator in background
nohup $ANDROID_HOME/emulator/emulator -avd xamarin_android_emulator -no-snapshot > /dev/null 2>&1 &

# build the sample, while the emulator is starting
msbuild /r /p:Configuration=Release $BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.UITests/HelloUnoWorld.UITests.csproj
msbuild /r /p:Configuration=Release $BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.Droid/HelloUnoWorld.Droid.csproj

# 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"

export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/e2e/uno/wasm
export UNO_UITEST_PLATFORM=Android
export UNO_UITEST_ANDROIDAPK_PATH=$BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.Droid/bin/Release/com.prismlibrary.helloworld-Signed.apk

cd $BUILD_SOURCESDIRECTORY/build

wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
mono nuget.exe install NUnit.ConsoleRunner -Version 3.10.0

mkdir -p $UNO_UITEST_SCREENSHOT_PATH

mono $BUILD_SOURCESDIRECTORY/build/NUnit.ConsoleRunner.3.10.0/tools/nunit3-console.exe \
$BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.UITests/bin/Release/net47/HelloUnoWorld.UITests.dll
29 changes: 29 additions & 0 deletions build/scripts/ios-uitest-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

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

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

cd $BUILD_SOURCESDIRECTORY
msbuild /r /p:Configuration=Release $BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.UITests/HelloUnoWorld.UITests.csproj
msbuild /r /p:Configuration=Release "/p:Platform=iPhoneSimulator" $BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.iOS/HelloUnoWorld.iOS.csproj

cd $BUILD_SOURCESDIRECTORY/build

wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
mono nuget.exe install NUnit.ConsoleRunner -Version 3.10.0

export UNO_UITEST_PLATFORM=iOS
export UNO_UITEST_IOSBUNDLE_PATH=$BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.iOS/bin/iPhoneSimulator/Release/HelloUnoWorld.app
export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/e2e/uno/wasm

mkdir -p $UNO_UITEST_SCREENSHOT_PATH

mono $BUILD_SOURCESDIRECTORY/build/NUnit.ConsoleRunner.3.10.0/tools/nunit3-console.exe \
--inprocess \
--agents=1 \
--workers=1 \
$BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.UITests/bin/Release/net47/HelloUnoWorld.UITests.dll
36 changes: 36 additions & 0 deletions build/scripts/wasm-uitest-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'


cd $BUILD_SOURCESDIRECTORY

msbuild /r /p:Configuration=Release $BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.UITests/HelloUnoWorld.UITests.csproj
msbuild /r /p:Configuration=Release $BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.Wasm/HelloUnoWorld.Wasm.csproj

cd $BUILD_SOURCESDIRECTORY/build

npm i chromedriver@74.0.0
npm i puppeteer@1.13.0

wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
mono nuget.exe install NUnit.ConsoleRunner -Version 3.10.0

export UNO_UITEST_TARGETURI=http://localhost:8000
export UNO_UITEST_DRIVERPATH_CHROME=$BUILD_SOURCESDIRECTORY/build/node_modules/chromedriver/lib/chromedriver
export UNO_UITEST_CHROME_BINARY_PATH=$BUILD_SOURCESDIRECTORY/build/node_modules/puppeteer/.local-chromium/linux-637110/chrome-linux/chrome
export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/e2e/uno/wasm
export UNO_UITEST_PLATFORM=Browser
export UNO_UITEST_CHROME_CONTAINER_MODE=true

mkdir -p $UNO_UITEST_SCREENSHOT_PATH

# The python server serves the current working directory, and may be changed by the nunit runner
bash -c "cd $BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.Wasm/bin/Release/netstandard2.0/dist/; python server.py &"

mono $BUILD_SOURCESDIRECTORY/build/NUnit.ConsoleRunner.3.10.0/tools/nunit3-console.exe \
--trace=Verbose \
--inprocess \
--agents=1 \
--workers=1 \
$BUILD_SOURCESDIRECTORY/e2e/Uno/HelloUnoWorld.UITests/bin/Release/net47/HelloUnoWorld.UITests.dll
7 changes: 7 additions & 0 deletions e2e/Uno/HelloUnoWorld.Droid/HelloUnoWorld.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<ResourcesDirectory>..\HelloUnoWorld.Shared\Strings</ResourcesDirectory>
</PropertyGroup>
<PropertyGroup>
<IsUiAutomationMappingEnabled>true</IsUiAutomationMappingEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
Expand All @@ -33,6 +36,10 @@
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HelloWorld.Dialogs"
mc:Ignorable="d"
x:Name="contentDialog"
Title="Another Content Dialog" Height="450" Width="800" Background="Green">
<Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Button Command="{Binding CloseDialogCommand}"
CommandParameter="True"
Content="OK"
x:Name="OKButton"
HorizontalAlignment="Right"
Margin="0,10,0,0"
Grid.Row="1" />
Expand Down
35 changes: 19 additions & 16 deletions e2e/Uno/HelloUnoWorld.Shared/Views/Shell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
xmlns:prismMvvm="using:Prism.Mvvm"
xmlns:prismRegions="using:Prism.Regions"
prismMvvm:ViewModelLocator.AutoWireViewModel="True"
xmlns:toolkit="using:Uno.UI.Toolkit"
xmlns:local="clr-namespace:HelloWorld">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ContentControl Grid.Row="1"
prismRegions:RegionManager.RegionName="ContentRegion" />
<StackPanel>
<Button Grid.Row="0"
Command="{Binding NavigateCommand}"
CommandParameter="ViewA"
Content="Navigate to Named View" />
<Button Command="{Binding ShowDialogCommand}"
Content="Show Dialog" />
</StackPanel>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" toolkit:VisibleBoundsPadding.PaddingMask="All">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ContentControl Grid.Row="1"
prismRegions:RegionManager.RegionName="ContentRegion" />
<StackPanel>
<Button x:Name="viewAButton"
Grid.Row="0"
Command="{Binding NavigateCommand}"
CommandParameter="ViewA"
Content="Navigate to Named View" />
<Button x:Name="showDialog"
Command="{Binding ShowDialogCommand}"
Content="Show Dialog" />
</StackPanel>
</Grid>
</ContentControl>
20 changes: 13 additions & 7 deletions e2e/Uno/HelloUnoWorld.Shared/Views/ViewA.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<UserControl x:Class="HelloUnoWorld.Views.ViewA"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:HelloUnoWorld.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Text="View A" FontSize="72" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="viewAText"
Text="View A"
FontSize="72"
FontWeight="Bold"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Grid>
</UserControl>
19 changes: 19 additions & 0 deletions e2e/Uno/HelloUnoWorld.UITests/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Uno.UITest.Helpers.Queries;

namespace Sample.UITests
{
public class Constants
{
public readonly static string WebAssemblyDefaultUri = "http://localhost:62905/";
public readonly static string iOSAppName = "com.prismlibrary.helloworld";
public readonly static string AndroidAppName = "com.prismlibrary.helloworld";
public readonly static string iOSDeviceNameOrId = "iPad Pro (12.9-inch) (3rd generation)";

public readonly static Platform CurrentPlatform = Platform.Browser;
}
}
Loading

0 comments on commit 073790c

Please sign in to comment.