Java Code Examples for android.support.test.uiautomator.UiDevice.wait()

The following are Jave code examples for showing how to use wait() of the android.support.test.uiautomator.UiDevice class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: notification-adapter   File: NotificationAdapterTest.java   Source Code and License Vote up 5 votes
@Test
public void testNotificationAdapter() {
    final String NOTIFICATION_TEXT = "adapter-text";
    final String NOTIFICATION_TITLE = "adapter-title";
    final long TIMEOUT = 5000;

    Context appContext = InstrumentationRegistry.getTargetContext();

    RemoteViews contentView = new RemoteViews("cn.dreamtobe.toolset.test", R.layout.custom_layout);
    contentView.setTextViewText(R.id.title, NOTIFICATION_TITLE);
    contentView.setTextViewText(R.id.text, NOTIFICATION_TEXT);

    // Fix the Notification-Style problem ---------------
    // Set the default title style color to title view.
    contentView.setTextColor(R.id.title, NotificationAdapter.getTitleColor(appContext));
    // Set the default title style size to title view
    contentView.setTextViewTextSize(R.id.title, COMPLEX_UNIT_PX, NotificationAdapter.getTitleSize(appContext));
    // Set the default text style color to text view
    contentView.setTextColor(R.id.text, NotificationAdapter.getTextColor(appContext));
    // Set the default text style size to text view
    contentView.setTextViewTextSize(R.id.text, COMPLEX_UNIT_PX, NotificationAdapter.getTextSize(appContext));
    // End fix the Notification-Style problem ---------------

    Notification notification = new Notification();
    notification.icon = R.drawable.ic_launcher;
    notification.contentView = contentView;

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    NotificationManager notifyMgr =
            (NotificationManager) appContext.getSystemService(NOTIFICATION_SERVICE);
    notifyMgr.notify(1, notification);

    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    device.openNotification();
    device.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)), TIMEOUT);
}
 
Example 2
Project: ChimpCheck   File: EspressoChimpDriver.java   Source Code and License Vote up 4 votes
@Override
protected void launchResume() {
    Log.i(runner.chimpTag("[email protected]"), "Resume");

    String packageName = runner.getAppPackageName();
    int launchTimeout = 5000;


    sleep(500);

    UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager()
            .getLaunchIntentForPackage(packageName);
    context.startActivity(intent);

    mDevice.wait(Until.hasObject(By.pkg(packageName).depth(0)), launchTimeout);

}
 
Example 3
Project: android_packages_apps_tv   File: UiDeviceAsserts.java   Source Code and License Vote up 4 votes
private static boolean waitForCondition(UiDevice uiDevice,
        SearchCondition<Boolean> searchCondition, long timeout) {
    long adjustedTimeout = timeout + Math.max(Constants.MIN_EXTRA_TIMEOUT,
            (long) (timeout * Constants.EXTRA_TIMEOUT_PERCENT));
    return uiDevice.wait(searchCondition, adjustedTimeout);
}