Stay organized with collections
Save and categorize content based on your preferences.
UiWatcher
public
interface
UiWatcher
android.support.test.uiautomator.UiWatcher
See registerWatcher(String, UiWatcher) on how to register a
a condition watcher to be called by the automation library. The automation library will
invoke checkForCondition() only when a regular API call is in retry mode because it is unable
to locate its selector yet. Only during this time, the watchers are invoked to check if there is
something else unexpected on the screen.
Custom handler that is automatically called when the testing framework is unable to
find a match using the UiSelector
When the framework is in the process of matching a UiSelector and it
is unable to match any widget based on the specified criteria in the selector,
the framework will perform retries for a predetermined time, waiting for the display
to update and show the desired widget.
Public methods
checkForCondition
boolean checkForCondition ()
Custom handler that is automatically called when the testing framework is unable to
find a match using the UiSelector
When the framework is in the process of matching a UiSelector and it
is unable to match any widget based on the specified criteria in the selector,
the framework will perform retries for a predetermined time, waiting for the display
to update and show the desired widget. While the framework is in this state, it will call
registered watchers' checkForCondition(). This gives the registered watchers a chance
to take a look at the display and see if there is a recognized condition that can be
handled and in doing so allowing the current test to continue.
An example usage would be to look for dialogs popped due to other background
processes requesting user attention and have nothing to do with the application
currently under test.
Returns
boolean
true to indicate a matched condition or false for nothing was matched
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# UiWatcher\n=========\n\n| This package is part of the Android [support library](/topic/libraries/support-library) which is no longer maintained. The support library has been superseded by [AndroidX](/jetpack/androidx) which is part of [Jetpack](/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](/jetpack/androidx/migrate) existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library [class\n| mappings](/jetpack/androidx/migrate/class-mappings).\n\n\n`\npublic\n\n\ninterface\nUiWatcher\n`\n\n\n`\n\n\n`\n\n|--------------------------------------------|\n| android.support.test.uiautomator.UiWatcher |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nSee [registerWatcher(String, UiWatcher)](/reference/android/support/test/uiautomator/UiDevice#registerWatcher(java.lang.String, android.support.test.uiautomator.UiWatcher)) on how to register a\na condition watcher to be called by the automation library. The automation library will\ninvoke checkForCondition() only when a regular API call is in retry mode because it is unable\nto locate its selector yet. Only during this time, the watchers are invoked to check if there is\nsomething else unexpected on the screen.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract boolean` | ` `[checkForCondition](/reference/android/support/test/uiautomator/UiWatcher#checkForCondition())`() ` Custom handler that is automatically called when the testing framework is unable to find a match using the [UiSelector](/reference/android/support/test/uiautomator/UiSelector) When the framework is in the process of matching a [UiSelector](/reference/android/support/test/uiautomator/UiSelector) and it is unable to match any widget based on the specified criteria in the selector, the framework will perform retries for a predetermined time, waiting for the display to update and show the desired widget. |\n\nPublic methods\n--------------\n\n### checkForCondition\n\n```\nboolean checkForCondition ()\n```\n\nCustom handler that is automatically called when the testing framework is unable to\nfind a match using the [UiSelector](/reference/android/support/test/uiautomator/UiSelector)\n\nWhen the framework is in the process of matching a [UiSelector](/reference/android/support/test/uiautomator/UiSelector) and it\nis unable to match any widget based on the specified criteria in the selector,\nthe framework will perform retries for a predetermined time, waiting for the display\nto update and show the desired widget. While the framework is in this state, it will call\nregistered watchers' checkForCondition(). This gives the registered watchers a chance\nto take a look at the display and see if there is a recognized condition that can be\nhandled and in doing so allowing the current test to continue.\n\nAn example usage would be to look for dialogs popped due to other background\nprocesses requesting user attention and have nothing to do with the application\ncurrently under test.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|------------------------------------------------------------------------------|\n| `boolean` | true to indicate a matched condition or false for nothing was matched \u003cbr /\u003e |\n\n-\n\n Interfaces\n ----------\n\n - [IAutomationSupport](/reference/android/support/test/uiautomator/IAutomationSupport)\n - [UiWatcher](/reference/android/support/test/uiautomator/UiWatcher)\n-\n\n Classes\n -------\n\n - [By](/reference/android/support/test/uiautomator/By)\n - [BySelector](/reference/android/support/test/uiautomator/BySelector)\n - [Configurator](/reference/android/support/test/uiautomator/Configurator)\n - [EventCondition](/reference/android/support/test/uiautomator/EventCondition)\n - [SearchCondition](/reference/android/support/test/uiautomator/SearchCondition)\n - [UiAutomatorInstrumentationTestRunner](/reference/android/support/test/uiautomator/UiAutomatorInstrumentationTestRunner)\n - [UiAutomatorTestCase](/reference/android/support/test/uiautomator/UiAutomatorTestCase)\n - [UiCollection](/reference/android/support/test/uiautomator/UiCollection)\n - [UiDevice](/reference/android/support/test/uiautomator/UiDevice)\n - [UiObject](/reference/android/support/test/uiautomator/UiObject)\n - [UiObject2](/reference/android/support/test/uiautomator/UiObject2)\n - [UiObject2Condition](/reference/android/support/test/uiautomator/UiObject2Condition)\n - [UiScrollable](/reference/android/support/test/uiautomator/UiScrollable)\n - [UiSelector](/reference/android/support/test/uiautomator/UiSelector)\n - [Until](/reference/android/support/test/uiautomator/Until)\n-\n\n Enums\n -----\n\n - [Direction](/reference/android/support/test/uiautomator/Direction)\n-\n\n Exceptions\n ----------\n\n - [StaleObjectException](/reference/android/support/test/uiautomator/StaleObjectException)\n - [UiObjectNotFoundException](/reference/android/support/test/uiautomator/UiObjectNotFoundException)"]]