类android.support.test.uiautomator.UiWatcher源码实例Demo

下面列出了怎么用android.support.test.uiautomator.UiWatcher的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: AppCrawler   文件: UiWatchers.java
/**
 * 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");
}
 
 类所在包
 同包方法