Skip to content

Conversation

@bipinsengar
Copy link

Description
This PR addresses an issue where the terminate_application method for the UIAutomator 2 driver could fail due to a hardcoded 500ms timeout. This change introduces a configurable timeout parameter, giving users the flexibility to specify a longer duration for application termination.

Motivation and Context
The fixed internal timeout of 500ms was often insufficient for applications that perform cleanup tasks upon closing, or for tests running on slower hardware or simulators. This could lead to premature timeouts and result in flaky, unreliable tests.

By allowing users to set a custom timeout, we can significantly improve the stability of tests that rely on this functionality. This change directly resolves the problem described in issue #14818.

Implementation Details
The terminate_application method now accepts an optional timeout argument, specified in milliseconds.

To maintain backward compatibility and avoid breaking existing tests, the method defaults to the original 500ms timeout if no value is provided.

The underlying logic has been updated to pass this timeout value to the application termination process.

How to Use
Here is an example of how to use the new timeout parameter in a Python test script:

Default behavior (500ms timeout)

driver.terminate_app('com.example.my-app')

Custom timeout (e.g., 3 seconds)

driver.terminate_app('com.example.my-app', timeout=3000)

Related Issue
Closes: #14818

feat(android): Add configurable timeout to terminate_application

Previously, the terminate_application method had a hardcoded 500ms timeout. This could lead to failures on slower devices or under heavy load where the application could not terminate within the allotted time.

This change introduces a timeout parameter to the terminate_application method, allowing users to specify a custom duration in milliseconds. If no timeout is provided, it defaults to the original 500ms to maintain backward compatibility.

This provides more flexibility and prevents unnecessary test failures due to rigid timeout constraints.

Fixes: appium/appium#14818
@emanlove emanlove self-requested a review June 7, 2025 11:52
@emanlove emanlove added this to the v4 milestone Jul 25, 2025
@emanlove emanlove added future Issue or pull request for future release and removed need_attention labels Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

future Issue or pull request for future release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants