Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 27, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Problem

The Catalyst Test Runner was using brittle UI navigation to reach specific tests:

private void NavigateToIssue(string issue)
{
    App.WaitForElement("GoToTestButton", issue);
    App.EnterText("SearchBar", issue);
    App.WaitForElement("GoToTestButton");
    App.Tap("GoToTestButton");
}

This approach had several issues:

  • Timing dependencies - UI elements needed to be ready before interaction
  • Reliability concerns - Keyboard navigation could fail due to focus/timing issues
  • Performance overhead - Every test required UI navigation before actual testing
  • Inconsistency - iOS already supported startup arguments, but Catalyst didn't

Solution

Implemented startup argument support for Catalyst Test Runner to pass the test name directly at app launch, eliminating UI navigation entirely.

Changes Made

1. Added ProcessArguments support to AppiumCatalystApp

// Now matches iOS implementation
var args = config.GetProperty<Dictionary<string, string>>("TestConfigurationArgs");
options.AddAdditionalAppiumOption(IOSMobileCapabilityType.ProcessArguments, new Dictionary<string, object>
{
    { "env", args! }
});

2. Enhanced test host app to read startup arguments

// Direct navigation from environment variable
var testName = System.Environment.GetEnvironmentVariable("test");
if (!string.IsNullOrEmpty(testName))
{
    var testCaseScreen = new TestCases.TestCaseScreen();
    if (testCaseScreen.TryToNavigateTo(testName))
    {
        // Skip UI navigation completely!
    }
}

3. Updated _IssuesUITest for Catalyst-specific behavior

#if MACCATALYST
protected override bool ResetAfterEachTest => true;  // Reset at test start with args
#endif

public override IConfig GetTestConfig()
{
    var config = base.GetTestConfig();
#if MACCATALYST
    config.SetTestConfigurationArg("test", Issue);  // Pass test name as startup arg
#endif
    return config;
}

Flow Comparison

Before (UI Navigation):

App starts → Wait for UI → SearchBar.EnterText("Issue1931") → Tap("GoToTestButton") → Test runs → Reset in TestTearDown

After (Startup Arguments):

Test starts → App resets with test=Issue1931 env var → Direct navigation → Test runs

Benefits

🚀 Performance: Eliminates UI navigation overhead for every test
🛡️ Reliability: Removes timing-dependent keyboard interactions
🔄 Consistency: Aligns Catalyst with iOS ProcessArguments approach
🔧 Maintainability: Cleaner test lifecycle with reset-at-start pattern
📱 Backward Compatible: Only affects Mac Catalyst, other platforms unchanged

Testing

Validated the complete flow with unit tests covering:

  • Configuration argument passing works correctly
  • Environment variable reading functions properly
  • Test lifecycle behavior is correct for Catalyst
  • All components compile and format correctly

Fixes #30285.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 27, 2025 18:56
Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Copilot AI changed the title [WIP] [Testing] Rework the Catalyst Test Runner so that it will pass in the next test as a startup argument vs navigating by keyboard [Testing] Rework Catalyst Test Runner to use startup arguments instead of UI navigation Jun 27, 2025
Copilot AI requested a review from PureWeen June 27, 2025 19:03
@PureWeen
Copy link
Member

@copilot

@PureWeen PureWeen closed this Jul 22, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Testing] Rework the Catalyst Test Runner so that it will pass in the next test as a startup argument vs navigating by keyboard

2 participants