When using withAssertion, be aware that the total time to failure may increase because Ultron may execute the operation and the assertion block multiple times to verify the failure.
To prevent tests from hanging, you can control timeouts at two levels:
- Assertion Timeout: Use
withTimeout(long) inside the assertion block to restrict how long a specific check (like isDisplayed()) should wait. - Operation Timeout: Use
withTimeout(long) on the main object to extend the timeout of the primary operation being performed.
You can combine both to have a long-running operation with a strict, short-lived assertion check.
// Restrict the assertion check to 3 seconds
button.withAssertion {
title.withTimeout(3_000L).isDisplayed()
}.click()
// Extend the main operation to 10 seconds, but keep the assertion check at 2 seconds
button.withTimeout(10_000L).withAssertion {
title.withTimeout(2_000L).isDisplayed()
}.click()