Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 8, 2025

This PR addresses an issue where UIAutomation processes continue running on macOS after tests finish, which is particularly problematic when the test agent is not recreated between runs.

Problem

The issue stems from the appium-mac2-driver not properly cleaning up UIAutomation processes when the driver session ends. While the base AppiumApp.Dispose() method calls _driver?.Dispose(), this is insufficient for macOS as it leaves UIAutomation processes running in the background.

Solution

Added platform-specific cleanup for macOS by:

  1. Made AppiumApp.Dispose() virtual to allow platform-specific overrides
  2. Added AppiumCatalystApp.Dispose() override that performs explicit cleanup:
    • Terminates the app using macos: terminateApp script (consistent with existing patterns in AppiumLifecycleActions)
    • Explicitly quits the driver session using _driver.Quit()
    • Includes proper error handling that gracefully continues if the app/session is already closed
    • Ensures base.Dispose() is always called in a finally block

Implementation Details

The implementation follows existing codebase patterns:

  • Uses the same macos: terminateApp script pattern as AppiumLifecycleActions.CloseApp()
  • Uses empty catch blocks for exception handling, consistent with other lifecycle operations
  • Only affects macOS/Catalyst platform - other platforms remain unchanged

Testing

Created comprehensive test scenarios that validate the disposal logic works correctly in all conditions:

  • Normal disposal with successful app termination and driver quit
  • Graceful handling when app termination script fails
  • Graceful handling when driver quit fails
  • Proper fallback when no AppId is configured

Fixes #23.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] On MacOS UIAutomation doesn't end Fix UIAutomation not ending properly on macOS Aug 8, 2025
@Copilot Copilot AI requested a review from jfversluis August 8, 2025 14:58
Copilot finished work on behalf of jfversluis August 8, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On MacOS UIAutomation doesn't end
2 participants