public void testLoadUserHappyCaseViews() { onView(withId(R.id.rl_retry)).check(matches(not(isDisplayed()))); onView(withId(R.id.rl_progress)).check(matches(not(isDisplayed()))); onView(withId(R.id.tv_fullname)).check(matches(isDisplayed())); onView(withId(R.id.tv_email)).check(matches(isDisplayed())); onView(withId(R.id.tv_description)).check(matches(isDisplayed())); }
@Test public void clickAsyncWork() { onView(withId(R.id.async_work)).perform(click()); }
@Test public void testFlash() { onView(withId(R.id.camera)) .check(new ViewAssertion() { @Override public void check(View view, NoMatchingViewException noViewFoundException) { CameraView cameraView = (CameraView) view; assertThat(cameraView.getFlash(), is(CameraView.FLASH_AUTO)); cameraView.setFlash(CameraView.FLASH_TORCH); assertThat(cameraView.getFlash(), is(CameraView.FLASH_TORCH)); } }); }
private int testOrientation() { int orientation=getOrientation(); if (orientation==Configuration.ORIENTATION_LANDSCAPE) { onView(withId(R.id.content)) .check(new OrientationAssertion(LinearLayout.HORIZONTAL)); } else { onView(withId(R.id.content)) .check(new OrientationAssertion(LinearLayout.VERTICAL)); } return(orientation); }
@Test public void asyncButtonHasStartText() { onView(withId(R.id.async_work)).check(matches(withText(R.string.start_async_work))); } }
@Test public void listCount() { onView(withId(android.R.id.list)) .check(new AdapterCountAssertion(25)); }
@Test public void unreliableAsyncTest() { onView(withId(android.R.id.list)) .check(new AdapterCountAssertion(100)); }
@Test public void stubPick() { Instrumentation.ActivityResult result= new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent(null, ContactsContract.Contacts.CONTENT_URI)); intending(hasAction(Intent.ACTION_PICK)).respondWith(result); onView(withId(R.id.pick)).perform(click()); intended(allOf( hasAction(Intent.ACTION_PICK), hasData(ContactsContract.Contacts.CONTENT_URI))); onView(withId(R.id.view)).check(matches(isEnabled())); }
@Test public void canceledPick() { Instrumentation.ActivityResult result= new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, null); intending(hasAction(Intent.ACTION_PICK)).respondWith(result); onView(withId(R.id.pick)).perform(click()); intended(allOf( hasAction(Intent.ACTION_PICK), hasData(ContactsContract.Contacts.CONTENT_URI))); onView(withId(R.id.view)).check(matches(not(isEnabled()))); }
@Test public void tinypinyin_should_work(){ onView(withId(R.id.mTvText)).check(matches(withText("ZHONGGUOCHONGQING"))); } }
@Test @FlakyTest public void preview_isShowing() throws Exception { onView(withId(R.id.camera)) .perform(waitFor(1000)) .check(showingPreview()); }
@Test public void sanityTest() { onView(withId(R.id.clear)).perform(click()); onView(withId(R.id.add)).perform(click()); onView(withId(R.id.edit)).perform(clearText(), typeText(FIRST_TEXT)); onView(withText(R.string.add)).inRoot(isDialog()).perform(click()); onView(withId(R.id.add)).perform(click()); onView(withId(R.id.edit)).perform(clearText(), typeText(SECOND_TEXT)); onView(withText(R.string.add)).inRoot(isDialog()).perform(click()); onView(withText(COL_FIRST_TEXT)).perform(click()); onView(withId(R.id.edit)).perform(clearText(), typeText(THIRD_TEXT)); onView(withText(R.string.edit)).inRoot(isDialog()).perform(click()); onView(withText(COL_SECOND_TEXT)).perform(longClick()); onView(withId(R.id.clear)).perform(click()); } }
@Test public void recreate() { stubPick(); InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { main.getActivity().recreate(); } }); onView(withId(R.id.view)).check(matches(isEnabled())); }
@Test public void scrollToBottom() { onData(anything()) .inAdapterView(withId(android.R.id.list)) .atPosition(24) .check(matches(withText("purus"))); }
@Test public void keyEvents() { onView(withId(android.R.id.list)) .perform(pressKey(KeyEvent.KEYCODE_DPAD_DOWN), pressKey(KeyEvent.KEYCODE_DPAD_DOWN), pressKey(KeyEvent.KEYCODE_DPAD_DOWN), pressKey(KeyEvent.KEYCODE_DPAD_DOWN)) .check(new ListSelectionAssertion(3)); }
@Test public void testAspectRatio() { final CameraView cameraView = (CameraView) rule.getActivity().findViewById(R.id.camera); final Set<AspectRatio> ratios = cameraView.getSupportedAspectRatios(); for (AspectRatio ratio : ratios) { onView(withId(R.id.camera)) .perform(setAspectRatio(ratio)) .check(matches(hasAspectRatio(ratio))); } }
@Test public void til() { onView(withTILHint("URL")) .perform(typeText(URL), closeSoftKeyboard()); Instrumentation.ActivityResult result= new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, null); intending(hasAction(Intent.ACTION_VIEW)).respondWith(result); onView(withId(R.id.browse)).perform(click()); intended(allOf(hasAction(Intent.ACTION_VIEW), hasData(URL))); }
@Test public void moreReliableAsyncTest() { IdlingResource idleWild= OkHttp3IdlingResource.create("okhttp3", main.getActivity().getOkHttpClient()); IdlingRegistry.getInstance().register(idleWild); try { onView(withId(android.R.id.list)) .check(new AdapterCountAssertion(100)); } finally { IdlingRegistry.getInstance().unregister(idleWild); } }