diff --git a/src/Controls/tests/TestCases.HostApp/MauiProgram.cs b/src/Controls/tests/TestCases.HostApp/MauiProgram.cs index 479a765a29cb..b490a3bb69de 100644 --- a/src/Controls/tests/TestCases.HostApp/MauiProgram.cs +++ b/src/Controls/tests/TestCases.HostApp/MauiProgram.cs @@ -64,6 +64,23 @@ public static Page CreateDefaultMainPage() { Page mainPage = null; OverrideMainPage(ref mainPage); + + // Check for startup test argument from environment variables (passed by test runner) + var testName = System.Environment.GetEnvironmentVariable("test"); + if (!string.IsNullOrEmpty(testName)) + { + App.StartupTestName = testName; + + // Try to navigate directly to the test + var testCaseScreen = new TestCases.TestCaseScreen(); + if (testCaseScreen.TryToNavigateTo(testName)) + { + // If navigation succeeded, the page was already set by the action + // Return a dummy page that will be replaced + return new ContentPage { Title = "Loading Test..." }; + } + } + return mainPage ?? new CoreNavigationPage(); } } @@ -78,6 +95,7 @@ public App() } public static bool PreloadTestCasesIssuesList { get; set; } = true; + public static string StartupTestName { get; set; } protected override void OnAppLinkRequestReceived(Uri uri) { diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs index 22c67e8e7d2e..b4cdf62a2b6f 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs @@ -17,8 +17,24 @@ public abstract class _IssuesUITest : UITest protected const string BackButtonAutomationId = "Navigate up"; #endif +#if MACCATALYST + protected override bool ResetAfterEachTest => true; +#endif + public _IssuesUITest(TestDevice device) : base(device) { } + public override IConfig GetTestConfig() + { + var config = base.GetTestConfig(); + +#if MACCATALYST + // For Catalyst, pass the test name as a startup argument + config.SetTestConfigurationArg("test", Issue); +#endif + + return config; + } + protected override void FixtureSetup() { int retries = 0; @@ -30,7 +46,14 @@ protected override void FixtureSetup() #if ANDROID || MACCATALYST App.ToggleSystemAnimations(false); #endif +#if !MACCATALYST + // For non-Catalyst platforms, navigate via UI NavigateToIssue(Issue); +#else + // For Catalyst, navigation is handled via startup arguments + // Just wait for the test to load + App.WaitForElement("*", timeout: TimeSpan.FromSeconds(10)); +#endif break; } catch (Exception e) diff --git a/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs b/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs index c6552ab90975..bdb4096c246b 100644 --- a/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs +++ b/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs @@ -65,6 +65,12 @@ private static AppiumOptions GetOptions(IConfig config) options.AddAdditionalAppiumOption(IOSMobileCapabilityType.BundleId, appId); } + var args = config.GetProperty>("TestConfigurationArgs"); + options.AddAdditionalAppiumOption(IOSMobileCapabilityType.ProcessArguments, new Dictionary + { + { "env", args! } + }); + options.AddAdditionalAppiumOption("showServerLogs", true); return options; }