Repository navigation
Closed
Labels
Milestone
Description
Problem
We want our unit tests to not just be able to test .NET code, but also be able to exercise the UI to the extent possible in the UWP/WinUI test app scenarios.
Existing Solution
In the toolkit, we have a helper class called VisualUITestBase which allows a developer writing a unit test with UITestMethod to set the content of the test app temporarily in order to exercise a component, check its layout, and test other parts which may be required for the control to be visualized.
New Solutions
- Currently a lot of these tests use
XamlReaderto load XAML from code-behind to create their scenarios. This is a bit cumbersome, especially without the upcoming raw C# string literals. I'd like to investigate using an attribute style solution like we did for the Toolkit UI tests, so loose XAML files can be used to load test scenarios directly within the application. - Once we reach this point, we get pretty close to being able to do more complex UI testing, it'd be great if we could try and bridge the complexity gap of the UI Testing systems that are really hard to work with on automation APIs and connecting test runners and the test hosting apps (and being able to run those in the CI across multiple automation framework technologies)... to instead just build on what we know works easily in the unit test structure that exists with MSTest and see if we can provide some basic UI manipulation helpers in order to test more complex scenarios.
Proposal Breakdown
- Independent: Rename
CommunityToolkit.Labs.Sharedproject toCommunityToolkit.Labs.SampleApp.Shared - Create a new
common\Communitytoolkit.Labs.UnitTests.Sharedshared project (to appear under theSharedSolution folder)- Add this to the root test heads
- Remove all
App.xaml/UnitTestApp.xamlandMainWindow.xamlfiles from unit test heads - Centralize on
CommunityToolkit.Labs.UnitTestsnamespace - Use a common
App.xamlfile to include WinUI 2 and WinUI 3 for all the test heads (just like the individual platform heads do) - Abstract the startup for UWP vs. WinUI 3 (see project heads shared
App.xaml.csfile) - Make sure
WINAPPSDKconditional works the same for unit test projects
- Add
VisualUITestBaseclass from Toolkit version- Add the new shared unit test project to the experiment shared projects
- Add 7.1.2 Toolkit references for UWP/WinUI 3 for Visual Tree helpers and the like
- New
VisualUITestBaseimprovements - handled by API Spec for Reunion Deployment Information API microsoft/WindowsAppSDK#156 now- Add ability to lookup attribute in
TestInitializein base class - Load from page in shared experiment project
- Auto Dispatch? (all these UI tests had to dispatch to the UI thread to load, so we can automatically handle that I think?).
- Add ability to lookup attribute in
- Test works in all environments:
- UWP/WinUI 3 with all solution
- UWP/WinUI with experiment solution
- CI
-
Investigate helper methods for more 'ui testing' scenarios-
Since we own the apps and their deployment can we use more restricted capabilities like the InputInjection rescap? And does that work in WinUI 3 as well? -
Does this work in the CI?
-
-
UseGridSplitteras a test case and see if we can:- [ ]~ Test Localization (will be good test for UWP/WinUI 3 and resource loading)~
-
Test a mouse drag (if we get injector working) replicate the UI Test we had for GridSplitter
Activity
michael-hawker commentedon May 19, 2022
Figured out my
Newtonsoft.Jsonissue see comment here in microsoft/WindowsAppSDK#59.Have the shared infrastructure setup, so going to test with bringing in
VisualUITestBaseand writing someGridSplitter tests. If that works we can snap microsoft/WindowsAppSDK#126 I think before doing the rest?Add initial touch injection API test
michael-hawker commentedon Jun 16, 2022
Built off of microsoft/WindowsAppSDK#156 and tested some of the Input Injector API stuff, looks really promising. Few issues though.
Test failures weren't bubbling up, left comment on the PR.
WinAppSDK seems slow to load the test content (especially on 1.0.3, updating to 1.1.1 seemed to help). Not sure if there's an issue with the API the CompositionTargetHelper uses or just things saying they're loaded when they're not rendered yet...
I do see an
InvalidCastExceptionwhen we call the CompositionTargetHelper in WinUI 3...Filed issue: CompositionTarget.Rendering throws InvalidCastException microsoft/microsoft-ui-xaml#7247
The docs don't show how to simulate a mouse move, filed an issue here: Input Injection Sample doesn't show how to move mouse points MicrosoftDocs/windows-dev-docs#3887 - would need to figure out what needs to be done for this, but theoretically possible. May be able to ask @shweaver-MSFT for some ideas here depending on how similar it works compared to something like WinAppDriver.
Once I updated to WinAppSDK 1.1.1, I saw the touch point, but it was in the wrong spot. So need to follow-up with the WinUI folks on that, currently using this issue to track:
InputInjectormouse click error microsoft/microsoft-ui-xaml#10688Finally, if this does seem all viable (it's so close), then would want to design a more fluent API like the toolkit animations to help build up the chain of execution for easier testing. May ask @Sergio0694 for some thoughts on this later.
Have a branch on top of 156 at llama/input-injection, will rebase once that PR is merged.
Sergio0694 commentedon Jun 16, 2022
Happy to help brainstorm a fluent API surface if we get to that point, of course! Ping me any time 😄
michael-hawker commentedon Jun 16, 2022
Thanks @Sergio0694, yeah I was roughly thinking something like:
As we need to preface and end the operation with initializing/uninitializing the touch injector code, as well as generate/use a unique pointer id across the instructions (and if we want to use relative positioning between operations keep track of the initial point).
Anyway, bit more investigation to do, as not sure if this is going to run in the CI yet (though even then may have value).
Add initial touch injection API test
Add initial touch injection API test
michael-hawker commentedon Jun 29, 2022
Opened microsoft/WindowsAppSDK#176 to track remaining work, rest of this has been done for now.
Add initial touch injection API test
Add initial touch injection API test
Add initial touch injection API test
Add initial touch injection API test
Add initial touch injection API test