[Testing] Rework Catalyst Test Runner to use startup arguments instead of UI navigation #31673
[Testing] Rework Catalyst Test Runner to use startup arguments instead of UI navigation #31673PureWeen merged 10 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR reworks the Mac Catalyst test runner to enable direct test execution via startup arguments instead of requiring UI navigation. The change streamlines test execution by allowing tests to launch directly through environment variables and programmatic page creation.
Key Changes:
- Enhanced test lifecycle management for Mac Catalyst with direct page loading via startup arguments
- Introduced a new
_GalleryUITestbase class to simplify gallery-based test implementations - Added PageFactory mechanism for dynamic test page instantiation
Reviewed Changes
Copilot reviewed 76 out of 78 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/TestUtils/src/UITest.NUnit/UITestContextBase.cs |
Added Mac-specific app launch handling in InitialSetup |
src/TestUtils/src/UITest.NUnit/UITestBase.cs |
Enhanced teardown logic with Mac-specific app closure |
src/TestUtils/src/UITest.Appium/HelperExtensions.cs |
Added LaunchApp overload to support test name parameters |
src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs |
Enhanced Appium options to include environment variables |
src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs |
Modified Mac app launch to use environment variables |
src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs |
Updated NavigateToGallery to skip navigation for Catalyst |
src/Controls/tests/TestCases.Shared.Tests/UITest.cs |
Implemented Close and LaunchAppWithTest methods |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs |
Added Mac Catalyst startup argument support |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_GalleryUITest.cs |
New base class for gallery-based tests |
src/Controls/tests/TestCases.HostApp/TestCases.cs |
Added PageFactory property and TryToGetTestPage method |
src/Controls/tests/TestCases.HostApp/MauiProgram.cs |
Enhanced CreateDefaultMainPage with startup argument handling |
| Various test classes | Updated to inherit from _GalleryUITest and added GalleryPageName properties |
| public void AllScreenIsBlack() | ||
| { | ||
| #if !ANDROID // Display alert not shown in android also this is not a needed one for ensuring this case, so ignored the below steps on Android. | ||
| #if !ANDROID && !MACCATALYST // Display alert is not shown on Android, and it is not required to validate this case, so the following steps are skipped for Android. For Catalyst, the test page loading flow has been modified, making the popup validation unnecessary here as well. |
There was a problem hiding this comment.
[nitpick] The comment should be split into separate lines for better readability and clarity. Consider formatting as a multi-line comment or breaking it into shorter, more focused comments.
| #if !ANDROID && !MACCATALYST // Display alert is not shown on Android, and it is not required to validate this case, so the following steps are skipped for Android. For Catalyst, the test page loading flow has been modified, making the popup validation unnecessary here as well. | |
| // Display alert is not shown on Android, and it is not required to validate this case, | |
| // so the following steps are skipped for Android. | |
| // For Catalyst, the test page loading flow has been modified, | |
| // making the popup validation unnecessary here as well. | |
| #if !ANDROID && !MACCATALYST |
| public SearchBarFeatureTests(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
| override public string GalleryPageName => SearchBarFeatureMatrix; |
There was a problem hiding this comment.
The access modifier 'override' should come after 'public' according to C# coding conventions. It should be 'public override string GalleryPageName'.
| override public string GalleryPageName => SearchBarFeatureMatrix; | |
| public override string GalleryPageName => SearchBarFeatureMatrix; |
| public class ScrollViewFeatureTests : _GalleryUITest | ||
| { | ||
| public const string ScrollViewFeatureMatrix = "ScrollView Feature Matrix"; | ||
| override public string GalleryPageName => ScrollViewFeatureMatrix; |
There was a problem hiding this comment.
The access modifier 'override' should come after 'public' according to C# coding conventions. It should be 'public override string GalleryPageName'.
| override public string GalleryPageName => ScrollViewFeatureMatrix; | |
| public override string GalleryPageName => ScrollViewFeatureMatrix; |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
59f0480 to
0bb18a0
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| /// then by description if no match is found by name. If a match is found, | ||
| /// it invokes the associated PageFactory to create the page. | ||
| /// </remarks> | ||
| public Page TryToGetTestPage(string name) |
There was a problem hiding this comment.
Can try the exact match first:
var exactMatch = TestCases.FirstOrDefault(x =>
string.Equals(x.Description, description, StringComparison.OrdinalIgnoreCase));
if not find it, the current partial match as fallback.
There was a problem hiding this comment.
@jsuarezruiz I have addressed the feedback in the latest commit.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_GalleryUITest.cs
Show resolved
Hide resolved
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
7a5a026 to
3e7258a
Compare
|
/rebase |
3e7258a to
29d8e98
Compare
|
/rebase |
16e932a to
f34cc78
Compare
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 31673Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 31673" |
a80e751 to
8483cb8
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
71d6efb to
ef68d19
Compare
|
/rebase |
6e6efcd to
c465b73
Compare
PureWeen
left a comment
There was a problem hiding this comment.
Amazing!!!
Going to merge as is but I was curious on the tests where you have it switched to CarouselView2 and CollectionView2. Do we need to log those as bugs?
…d of UI navigation (#31673) ### Description of Change #### This PR reopens the work from the closed [#30651](#30651) This pull request introduces functionality to streamline test execution by allowing tests to be launched directly via startup arguments or programmatically. Key changes include adding support for passing test names as environment variables, introducing a `PageFactory` mechanism for dynamic page creation, and enhancing test lifecycle management for specific platforms like Mac Catalyst. Note: This PR is an extension of the PR(#30286) with a proper implementation. #### Test Execution Enhancements: - **Startup Argument Support**: Added logic to retrieve test names from environment variables and dynamically load the corresponding test page in `CreateDefaultMainPage()` (`MauiProgram.cs`). - **Dynamic Page Creation**: Introduced a `PageFactory` property in the `IssueModel` class to enable dynamic test page instantiation (`TestCases.cs`). - **Direct Test Page Retrieval**: Implemented `TryToGetTestPage()` in `TestCaseScreen` to retrieve test pages by description using `PageFactory` (`TestCases.cs`). #### Platform-Specific Test Lifecycle Improvements: - **Mac Catalyst Test Configuration**: Enhanced `_IssuesUITest` to pass test names as startup arguments and manage app launch/close lifecycle specifically for Mac Catalyst (`_IssuesUITest.cs`). [[1]](https://github.com/dotnet/maui/pull/30651/files#diff-6e8c0ea1f2979b5484d14facb1aa5b2ccef3ee748f1606eaf46220ac0936e3edR22-R46) [[2]](https://github.com/dotnet/maui/pull/30651/files#diff-6e8c0ea1f2979b5484d14facb1aa5b2ccef3ee748f1606eaf46220ac0936e3edR58-R61) - ** Appium Options for Mac Catalyst**: Updated `AppiumCatalystApp` to include environment variables in Appium options for test execution (`AppiumCatalystApp.cs`). #### Helper Methods for Test Execution: - **Parameterized App Launch**: Added a method to launch apps with additional parameters, supporting test-specific configurations (`HelperExtensions.cs`). - **Mac-Specific App Closure**: Modified `FixtureOneTimeTearDown()` to handle app closure for Mac Catalyst during test teardown (`UITestBase.cs`). ### Output https://github.com/user-attachments/assets/82fc12ad-b0d3-4bad-901f-0ab6b2bddda1 ### Issues Fixed Fixes #30285
Description of Change
This PR reopens the work from the closed #30651
This pull request introduces functionality to streamline test execution by allowing tests to be launched directly via startup arguments or programmatically. Key changes include adding support for passing test names as environment variables, introducing a
PageFactorymechanism for dynamic page creation, and enhancing test lifecycle management for specific platforms like Mac Catalyst.Note: This PR is an extension of the PR(#30286) with a proper implementation.
Test Execution Enhancements:
Startup Argument Support: Added logic to retrieve test names from environment variables and dynamically load the corresponding test page in
CreateDefaultMainPage()(MauiProgram.cs).Dynamic Page Creation: Introduced a
PageFactoryproperty in theIssueModelclass to enable dynamic test page instantiation (TestCases.cs).Direct Test Page Retrieval: Implemented
TryToGetTestPage()inTestCaseScreento retrieve test pages by description usingPageFactory(TestCases.cs).Platform-Specific Test Lifecycle Improvements:
Mac Catalyst Test Configuration: Enhanced
_IssuesUITestto pass test names as startup arguments and manage app launch/close lifecycle specifically for Mac Catalyst (_IssuesUITest.cs). [1] [2]** Appium Options for Mac Catalyst**: Updated
AppiumCatalystAppto include environment variables in Appium options for test execution (AppiumCatalystApp.cs).Helper Methods for Test Execution:
Parameterized App Launch: Added a method to launch apps with additional parameters, supporting test-specific configurations (
HelperExtensions.cs).Mac-Specific App Closure: Modified
FixtureOneTimeTearDown()to handle app closure for Mac Catalyst during test teardown (UITestBase.cs).Output
467025436-e594828d-93bb-4e41-b583-7d5b4ab2a0b9.mov
Issues Fixed
Fixes #30285