android.support.test.uiautomator.Until Java Examples
The following examples show how to use
android.support.test.uiautomator.Until.
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: MainEndToEndTest.java From Building-Professional-Android-Applications with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #2
Source File: UiHelper.java From AppCrawler with Apache License 2.0 | 6 votes |
public static boolean launchApp(String targetPackage) { FileLog.i(TAG_MAIN, "{Launch} " + targetPackage); UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); String launcherPackage = device.getLauncherPackageName(); if (launcherPackage.compareToIgnoreCase(targetPackage) == 0) { launchHome(); return true; } Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(targetPackage); if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Make sure each launch is a new task context.startActivity(intent); device.wait(Until.hasObject(By.pkg(Config.sTargetPackage).depth(0)), Config.sLaunchTimeout); } else { String err = String.format("(%s) No launchable Activity.\n", targetPackage); Log.e(TAG, err); Bundle bundle = new Bundle(); bundle.putString("ERROR", err); InstrumentationRegistry.getInstrumentation().finish(1, bundle); } return true; }
Example #3
Source File: PermissionsTest.java From espresso-samples with Apache License 2.0 | 6 votes |
@Before public void startMainActivityFromHomeScreen() { // Initialize UiDevice instance device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen device.pressHome(); // Wait for launcher final String launcherPackage = getLauncherPackageName(); MatcherAssert.assertThat(launcherPackage, IsNull.notNullValue()); device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); // Launch the app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager() .getLaunchIntentForPackage(APP_PACKAGE_NAME); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances context.startActivity(intent); // Wait for the app to appear device.wait(Until.hasObject(By.pkg(APP_PACKAGE_NAME).depth(0)), LAUNCH_TIMEOUT); }
Example #4
Source File: UiAutomatorTest.java From android-testing-templates with Apache License 2.0 | 6 votes |
/** * When using UiAutomator you can interact with ui elements outside of your own process. * You can start your application by pressing the home button of the device and launch the * target app through the android launcher. * * <p> * If you only want to launch and test a single {@link Activity} you can use {@link * Instrumentation} directly to only launch the target {@link Activity} * </p> */ @Before public void startBlueprintActivityFromHomeScreen() { // Initialize UiDevice instance mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); // Launch the blueprint app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances context.startActivity(intent); // Wait for the app to appear mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #5
Source File: UiAutomatorTest.java From android-testing-templates with Apache License 2.0 | 6 votes |
@Test public void findViewPerformActionAndCheckAssertion() { // Click on Button with content description final String btnContentDescription = InstrumentationRegistry.getTargetContext() .getString(R.string.content_desc_hello_android_testing); mDevice.findObject(By.desc(btnContentDescription)).click(); // Verify that correct text is displayed final String textViewResId = "text_view_rocks"; UiObject2 androidRocksTextView = mDevice .wait(Until.findObject(By.res(TARGET_PACKAGE, textViewResId)), 500 /* wait 500ms */); assertThat(androidRocksTextView, notNullValue()); final String androidTestingRocksText = InstrumentationRegistry.getTargetContext() .getString(R.string.android_testing_rocks); assertThat(androidRocksTextView.getText(), is(equalTo(androidTestingRocksText))); }
Example #6
Source File: LoginActivityTest.java From twittererer with Apache License 2.0 | 6 votes |
@Before public void startMainActivityFromHomeScreen() { device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen device.pressHome(); // Wait for launcher final String launcherPackage = getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), TIMEOUT); // Launch the app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(APP_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances context.startActivity(intent); // Wait for the app to appear device.wait(Until.hasObject(By.pkg(APP_PACKAGE).depth(0)), TIMEOUT); }
Example #7
Source File: UIAnimatorTest.java From Expert-Android-Programming with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { // Initialize UiDevice instance mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = mDevice.getLauncherPackageName(); Assert.assertThat(launcherPackage, CoreMatchers.notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); // Launch the app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager() .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); // Clear out any previous instances intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); // Wait for the app to appear mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #8
Source File: MainEndToEndTest.java From Building-Professional-Android-Applications with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #9
Source File: MainEndToEndTest.java From Building-Professional-Android-Applications with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #10
Source File: MainEndToEndTest.java From Building-Professional-Android-Applications with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #11
Source File: MainEndToEndTest.java From Building-Professional-Android-Applications with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #12
Source File: MainEndToEndTest.java From Building-Professional-Android-Applications with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #13
Source File: MainEndToEndTest.java From Building-Professional-Android-Applications with MIT License | 6 votes |
@Before public void startMainActivityFromHomeScreen() { mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); mDevice.pressHome(); final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); }
Example #14
Source File: LeanbackActivityIntegrationTest.java From CumulusTV with MIT License | 5 votes |
@Before public void initializeActivity() { Context context = InstrumentationRegistry.getContext(); mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen mDevice.pressHome(); final Intent intent = context.getPackageManager() .getLeanbackLaunchIntentForPackage("com.felkertech.n.cumulustv"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg("com.felkertech.n.cumulustv").depth(0)), 5000); }
Example #15
Source File: PickerIntegrationTest.java From CumulusTV with MIT License | 5 votes |
@Before public void initializeActivity() { mContext = InstrumentationRegistry.getContext(); mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen mDevice.pressHome(); final Intent intent = mContext.getPackageManager() .getLeanbackLaunchIntentForPackage("com.felkertech.n.cumulustv"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); mContext.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg("com.felkertech.n.cumulustv").depth(0)), 5000); }
Example #16
Source File: MyUiAutomatorTest.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Before public void setUp() { // Initialize UiDevice instance mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); // Start from the home screen mDevice.pressHome(); mDevice.wait(Until.hasObject(By.pkg(getLauncherPackageName()).depth(0)), 1000); }
Example #17
Source File: CachingTests.java From PhilHackerNews with MIT License | 5 votes |
private void launchApp(String appPackage) { Context context = getInstrumentation().getContext(); Intent intent = context.getPackageManager() .getLaunchIntentForPackage(appPackage); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); mDevice.wait(Until.hasObject(By.pkg(appPackage).depth(0)), LAUNCH_TIMEOUT); }
Example #18
Source File: AutomatorServiceImpl.java From android-uiautomator-server with MIT License | 5 votes |
/** * Check if view exists. This methods performs a waitForExists(long) with zero timeout. This basically returns immediately whether the view represented by this UiObject exists or not. * * @param obj the ui object. * @return true if the view represented by this UiObject does exist */ @Override public boolean exist(Selector obj) { if (obj.getChildOrSibling().length==0&&obj.toBySelector()!=null) return device.wait(Until.hasObject(obj.toBySelector()),0L); return device.findObject(obj.toUiSelector()).exists(); }
Example #19
Source File: UIAnimatorTest.java From Expert-Android-Programming with MIT License | 5 votes |
@Test public void testChangeText_newActivity() { // Type text and then press the button. mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE, "editTextUserInput")) .setText(STRING_TO_BE_TYPED); mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE, "activityChangeTextBtn")) .click(); // Verify the test is displayed in the Ui UiObject2 changedText = mDevice .wait(Until.findObject(By.res(BASIC_SAMPLE_PACKAGE, "show_text_view")), 500 /* wait 500ms */); assertThat(changedText.getText(), is(equalTo(STRING_TO_BE_TYPED))); }
Example #20
Source File: ItSelectMultiPointsActivity.java From SmoothClicker with MIT License | 5 votes |
/** * Starts the main activity to test from the home screen */ @Before public void startMainActivityFromHomeScreen() { l(this, "@Before startMainActivityFromHomeScreen"); // Initialize UiDevice instance mDevice = UiDevice.getInstance(getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT_MS); // Launch the app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_APP_PATH); // Clear out any previous instances intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); // Wait for the app to appear mDevice.wait(Until.hasObject(By.pkg(PACKAGE_APP_PATH).depth(0)), LAUNCH_TIMEOUT_MS); }
Example #21
Source File: ItSettingsActivity.java From SmoothClicker with MIT License | 5 votes |
/** * Starts the main activity to test from the home screen */ @Before public void startMainActivityFromHomeScreen() { l(this, "@Before startMainActivityFromHomeScreen"); // Initialize UiDevice instance mDevice = UiDevice.getInstance(getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT_MS); // Launch the app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_APP_PATH); // Clear out any previous instances intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); // Wait for the app to appear mDevice.wait(Until.hasObject(By.pkg(PACKAGE_APP_PATH).depth(0)), LAUNCH_TIMEOUT_MS); // Prepare for tests openSettingsScreenFromMenu(); }
Example #22
Source File: ItIntroScreensActivity.java From SmoothClicker with MIT License | 5 votes |
/** * Starts the main activity to test from the home screen */ @Before public void startMainActivityFromHomeScreen() { l(this, "@Before startMainActivityFromHomeScreen"); Context context = InstrumentationRegistry.getContext(); // Initialize UiDevice instance mDevice = UiDevice.getInstance(getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT_MS); // Launch the app final Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_APP_PATH); // Clear out any previous instances intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); // Wait for the app to appear mDevice.wait(Until.hasObject(By.pkg(PACKAGE_APP_PATH).depth(0)), LAUNCH_TIMEOUT_MS); }
Example #23
Source File: ItClickerActivity.java From SmoothClicker with MIT License | 5 votes |
/** * Starts the main activity to test from the home screen */ @Before public void startMainActivityFromHomeScreen() { l(this, "@Before startMainActivityFromHomeScreen"); // Initialize UiDevice instance mDevice = UiDevice.getInstance(getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT_MS); // Launch the app Context context = InstrumentationRegistry.getContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_APP_PATH); // Clear out any previous instances intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); // Wait for the app to appear mDevice.wait(Until.hasObject(By.pkg(PACKAGE_APP_PATH).depth(0)), LAUNCH_TIMEOUT_MS); }
Example #24
Source File: ItStandaloneModeDialog.java From SmoothClicker with MIT License | 5 votes |
/** * Starts the main activity to test from the home screen */ @Before public void startMainActivityFromHomeScreen() { l(this, "@Before startMainActivityFromHomeScreen"); // Initialize UiDevice instance mDevice = UiDevice.getInstance(getInstrumentation()); // Start from the home screen mDevice.pressHome(); // Wait for launcher final String launcherPackage = mDevice.getLauncherPackageName(); assertThat(launcherPackage, notNullValue()); mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT_MS); // Launch the app Context context = InstrumentationRegistry.getTargetContext(); final Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_APP_PATH); // Clear out any previous instances intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); // Wait for the app to appear mDevice.wait(Until.hasObject(By.pkg(PACKAGE_APP_PATH).depth(0)), LAUNCH_TIMEOUT_MS); // Prepare for tests openStandaloneModeDialog(); }
Example #25
Source File: UiHelper.java From AppCrawler with Apache License 2.0 | 5 votes |
public static void launchHome() { FileLog.i(TAG_MAIN, "{Press} Home"); UiDevice uidevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); uidevice.pressHome(); String launcherPackage = uidevice.getLauncherPackageName(); uidevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), Config.sLaunchTimeout); }
Example #26
Source File: BenchmarkTest.java From incubator-weex-playground with Apache License 2.0 | 4 votes |
private UiObject2 loadPageForFPS() { BenchmarkActivity benchmarkActivity = loadWeexPage(); return mUiDevice.wait(Until.findObject(By.desc(BenchmarkActivity.ROOT)), WAIT_TIMEOUT); }
Example #27
Source File: PermissionsTest.java From espresso-samples with Apache License 2.0 | 4 votes |
@Test public void grantLocationPermission() { App.setPermissionsModule(new DefaultPermissionsModule()); device.findObject(By.res(APP_PACKAGE_NAME, "btnRequestLocationPermission")).click(); UiObject2 btnAllow = device.wait(Until.findObject(By.res(INSTALLER_PACKAGE_NAME, "permission_allow_button")), 500); MatcherAssert.assertThat(btnAllow.isEnabled(), Is.is(true)); btnAllow.click(); UiObject2 tvLocationPermissionGranted = device.wait(Until.findObject(By.res(APP_PACKAGE_NAME, "tvLocationPermissionGranted")), 10000); MatcherAssert.assertThat(tvLocationPermissionGranted, IsNull.notNullValue()); }
Example #28
Source File: CachingTests.java From PhilHackerNews with MIT License | 4 votes |
private UiObject2 onAirplaneModeCheckBox() { return mDevice.wait(Until.findObject(By.res("android:id/checkbox")), UI_ELEMENT_TIMEOUT); }
Example #29
Source File: CachingTests.java From PhilHackerNews with MIT License | 4 votes |
private UiObject2 onMoreNetworksButton() { // Verify the test is displayed in the Ui return mDevice.wait(Until.findObject(By.text("More networks")), UI_ELEMENT_TIMEOUT); }
Example #30
Source File: CachingTests.java From PhilHackerNews with MIT License | 4 votes |
private void verifyStoryDataIsVisible() { assertNotNull(mDevice.wait(Until.findObject(By.text("999+")), UI_ELEMENT_TIMEOUT)); }