feat(android): Allow custom timeout for terminate_application #448
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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