Skip to content

feat(android): Allow custom timeout for terminate_application #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants