The UI Test repository is a collection of WinAppDriver-based test scenarios that cover basic interactions with WinUI 3 controls. See the Windows Platform controls reference for more information on available controls.
The test scenarios are written to test the controls in the WinUI 3 Gallery app. The procedure below outlines the steps needed to build and deploy WinUI 3 Gallery and WinAppDriver to run the UI Tests. These steps mirror what azure-pipelines.yml does in pipeline runs.
The easiest way to deploy the WinUI 3 Gallery for unit test execution is to simply build WinUIGallery\WinUIGallery.sln and F5 deploy it from within Visual Studio. Alternatively, the following commands can be used for automation.
- Generate the test signing certificate:
PS> .\build\GenerateTestPfx.ps1
- Build and publish the WinUI 3 Gallery from the command line, e.g.:
>dotnet.exe publish WinUIGallery\WinUIGallery.sln /p:AppxPackageDir=AppxPackages\ /p:platform=x64 /p:PublishProfile=./WinUIGallery/Properties/PublishProfiles/win-x64.pubxml
- Locate the WinUI 3 Gallery package output folder from above and deploy for testing:
PS> .\WinUIGallery\AppxPackages\WinUIGallery.Desktop_Test\Install.ps1
The test runner (vstest.console.exe and VS Test Explorer) should automatically launch WinAppDriver. Alternatively, it can be launched manually to observe diagnostic output as follows:
-
Download and install the latest version of WinAppDriver from here
-
Run WinAppDriver:
>C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe
The easiest way to run/debug the UI tests is with Visual Studio, as follows:
- Open
UITests\UITests.sln
in Visual Studio - Select Test > Windows > Test Explorer
- Select Run All on the test pane or through menu Test > Run > All Tests
Once the project is successfully built, you can use the Test Explorer to choose test scenarios to run/debug
Alternatively, the following commands can be used for automation:
- Build UITests:
>dotnet build UITests\UITests.sln
--or--
>msbuild UITests\UITests.sln
- Run test cases built above on command line:
>dotnet test .\UITests\UITests.csproj
--or--
>vstest.console.exe .\UITests\bin\x64\Debug\net7.0\UITests.dll
In either scenario above (cmdline or VS), if the tests run successfully, you should see:
- The WinUI 3 Gallery launch and run with automated UI interactions
- vstest.console.exe spew or Test Explorer indications of test case status
- Optionally, WinAppDriver console spew indicating successful launch of the test app
Please follow the guidelines below to maintain test reliability and reduce test execution time:
- Provide a complete set of interactions (if applicable) for each new control
- Aim for simple and reliable scenario using the least amount of test steps