android.support.test.uiautomator.UiWatcher Java Examples

The following examples show how to use android.support.test.uiautomator.UiWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UiWatchers.java    From AppCrawler with Apache License 2.0 4 votes vote down vote up
/**
 * We can use the UiDevice registerWatcher to register a small script to be
 * executed when the framework is waiting for a control to appear. Waiting may
 * be the cause of an unexpected dialog on the screen and it is the time when
 * the framework runs the registered watchers. This is a sample watcher
 * looking for ANR and crashes. it closes it and moves on. You should create
 * your own watchers and handle error logging properly for your type of tests.
 */
public void registerAnrAndCrashWatchers() {
    sDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    sDevice.registerWatcher("ANR", new UiWatcher() {
        @Override
        public boolean checkForCondition() {
            return handleAnr();
        }
    });

    sDevice.registerWatcher("ANR2", new UiWatcher() {
        @Override
        public boolean checkForCondition() {
            return handleAnr2();
        }
    });

    sDevice.registerWatcher("CRASH", new UiWatcher() {
        @Override
        public boolean checkForCondition() {
            return handleCrash();
        }
    });

    sDevice.registerWatcher("CRASH2", new UiWatcher() {
        @Override
        public boolean checkForCondition() {
            return handleCrash2();
        }
    });

    //sDevice.registerWatcher("COMMONDIALOG", new UiWatcher() {
    //    @Override
    //    public boolean checkForCondition() {
    //        return handleCommonDialog();
    //    }
    //});

    Log.i(TAG, "Registed GUI Exception watchers");
}