/** * Tests the full Activity lifecycle. Guarantees every lifecycle method gets called */ @Test public void testFullLifecycleIncludingConfigurationChange() throws Throwable { final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); // start the activity for the first time final TestActivity activity = startTestActivity(instrumentation); // make sure the attached presenter filled the UI Espresso.onView(withId(R.id.helloworld_text)) .check(matches(allOf(isDisplayed(), withText("Hello World 1")))); Espresso.onView(withId(R.id.fragment_helloworld_text)) .check(matches(allOf(isDisplayed(), withText("Hello World 1")))); // restart the activity rotateOrientation(activity); // assert the activity was bound to the presenter. The presenter should update the UI // correctly Espresso.onView(withId(R.id.helloworld_text)) .check(matches(allOf(isDisplayed(), withText("Hello World 2")))); Espresso.onView(withId(R.id.fragment_helloworld_text)) .check(matches(allOf(isDisplayed(), withText("Hello World 2")))); activity.finish(); }
/** * Setup your test fixture with a fake task id. The {@link SongPlayerActivity} is started with * a particular task id, which is then loaded from the service API. * * <p> * Note that this test runs hermetically and is fully isolated using a fake implementation of * the service API. This is a great way to make your tests more reliable and faster at the same * time, since they are isolated from any outside dependencies. */ @Before public void intentWithStubbedTaskId() { // Given some tasks SongsRepository.destroyInstance(); // Lazily start the Activity from the ActivityTestRule Intent startIntent = new Intent(); mStatisticsActivityTestRule.launchActivity(startIntent); /** * Prepare your test fixture for this test. In this case we register an IdlingResources with * Espresso. IdlingResource resource is a great way to tell Espresso when your app is in an * idle state. This helps Espresso to synchronize your test actions, which makes tests significantly * more reliable. */ Espresso.registerIdlingResources( mStatisticsActivityTestRule.getActivity().getCountingIdlingResource()); }
@Before public void beforeTest() { try { Timber.e("@Before: register idle resource"); idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); onView(withId(android.R.id.content)).check(matches(isDisplayed())); mapboxMap = idlingResource.getMapboxMap(); navigationMapRoute = rule.getActivity().getNavigationMapRoute(); } catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { Timber.e("Idling resource timed out. Couldn't not validate if map is ready."); throw new RuntimeException("Could not start executeNavigationMapRouteTest for " + this.getClass().getSimpleName() + ".\n" + "The ViewHierarchy doesn't contain a view with resource id = R.id.mapView or \n" + "the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n"); } }
@Test public void testLinearFlow() throws Exception { goToPaymentListFragment(AMOUNT, EUR); onView(withText(equalToIgnoringCase("Credit Card"))).perform(scrollTo(), click()); Espresso.pressBack(); // closes the keyboard Espresso.pressBack(); onView(withText(equalToIgnoringCase("iDEAL"))).perform(scrollTo(), click()); Espresso.pressBack(); onView(withText(equalToIgnoringCase("Credit Card"))).perform(scrollTo(), click()); // TODO: move following to a method onView(withId(R.id.adyen_credit_card_no)).perform(clearText(), typeText(CARD_NUMBER), closeSoftKeyboard()); onView(withId(R.id.adyen_credit_card_exp_date)).perform(typeText(CARD_EXP_DATE), closeSoftKeyboard()); onView(withId(R.id.adyen_credit_card_cvc)).perform(typeText(CARD_CVC_CODE), closeSoftKeyboard()); onView(withId(R.id.collectCreditCardData)).perform(click()); checkResultString(Payment.PaymentStatus.AUTHORISED.toString()); }
@Test public void testActionBarTitle() throws Exception { goToPaymentListFragment(AMOUNT, EUR); waitForText("Payment Methods"); onView(withText(equalToIgnoringCase("Credit Card"))).perform(scrollTo(), click()); waitForText("Card Details"); Espresso.pressBack(); Espresso.pressBack(); waitForText("Payment Methods"); onView(withText(equalToIgnoringCase("SEPA Direct Debit"))).perform(scrollTo(), click()); waitForText("Holder Name"); waitForText("SEPA Direct Debit"); Espresso.pressBack(); waitForText("Payment Methods"); waitForText("Payment Methods"); onView(withText(equalToIgnoringCase("iDEAL"))).perform(scrollTo(), click()); waitForText("iDEAL"); Espresso.pressBack(); waitForText("Payment Methods"); }
@Test public void clickTest(){ List<UiObject2> objects = mDevice.findObjects(By.clickable(true)); UiObject2 obj = objects.get(1); Log.d("TAG", obj.getResourceName()); Resources r = getActivityInstance().getResources(); Wrapper wr = helper(obj.getResourceName()); int id = r.getIdentifier(wr.name, wr.defType, wr.defPackage); Log.d("TAG", Integer.toString(id)); Espresso.onView(withId(id)).perform(click()); objects = mDevice.findObjects(By.clickable(true)); obj = objects.get(1); wr = helper(obj.getResourceName()); id = r.getIdentifier(wr.name, wr.defType, wr.defPackage); Espresso.onView(allOf(withId(id), supportsInputMethods() )).perform(typeText("string to be typed")); }
@Override public AppEventOuterClass.Click performMatcherAction(AppEventOuterClass.Click origin, Matcher<View> matcher) { if(origin.getUiid().getNameid().equals("ALLOW PERMISSION")){ PermissionGranter.allowPermissionsIfNeeded(); return origin; } try{ AmbiguousCounter.resetCounter(); Espresso.onView(new AmbiguousCounter(allOf(matcher, isDisplayed()))).perform(click()); } catch (AmbiguousViewMatcherException avme) { avme.printStackTrace(); int counter = AmbiguousCounter.getCounter(); AmbiguousCounter.resetCounter(); Random seed = new Random(System.currentTimeMillis()); int randIdx = seed.nextInt(counter); Espresso.onView(MatchWithIndex.withIndex(matcher, randIdx)).perform(click()); } return origin; }
@Override protected void before() throws Throwable { IdlingResourceScheduler ioIdlingScheduler = Rx2Idler.wrap(Schedulers.io(), "RxJava2 Io Idling Scheduler"); IdlingResourceScheduler computationIdlingScheduler = Rx2Idler.wrap(Schedulers.io(), "RxJava2 Computation Idling Scheduler"); IdlingResourceScheduler newThreadIdlingScheduler = Rx2Idler.wrap(Schedulers.io(), "RxJava2 New Thread Idling Scheduler"); Espresso.registerIdlingResources( ioIdlingScheduler, computationIdlingScheduler, newThreadIdlingScheduler ); RxJavaPlugins.setIoSchedulerHandler(scheduler1 -> ioIdlingScheduler); RxJavaPlugins.setInitComputationSchedulerHandler(scheduler1 -> computationIdlingScheduler); RxJavaPlugins.setComputationSchedulerHandler(scheduler1 -> computationIdlingScheduler); RxJavaPlugins.setNewThreadSchedulerHandler(scheduler1 -> newThreadIdlingScheduler); }
@Test @SuppressWarnings("ConstantConditions") public void signInFailure_ShowsErrorMessage() throws Exception { FirebaseAuth.getInstance().signOut(); FakeAuthConnector.setFakeSuccess(false); createActivity(); // error message should be showing: Espresso.onView(withId(R.id.progressBar)).check(matches(not(isDisplayed()))); Espresso.onView(withId(R.id.textMessage)).check(matches(isDisplayed())); Espresso.onView(withId(R.id.buttonContinue)).check(matches(isDisplayed())); // double check that the home screen is not shown: Espresso.onView(withId(R.id.recyclerContent)).check(doesNotExist()); }
@Before public void beforeTest() { try { Timber.e("@Before: register idle resource"); idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); onView(withId(android.R.id.content)).check(matches(isDisplayed())); mapboxMap = idlingResource.getMapboxMap(); trafficPlugin = rule.getActivity().getTrafficPlugin(); } catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { Timber.e("Idling resource timed out. Couldn't not validate if map is ready."); throw new RuntimeException("Could not start executeTrafficTest for " + this.getClass().getSimpleName() + ".\n" + "The ViewHierarchy doesn't contain a view with resource id = R.id.mapView or \n" + "the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n"); } }
@Before public void beforeTest() { try { Timber.e("@Before: register idle resource"); idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); onView(withId(android.R.id.content)).check(matches(isDisplayed())); mapboxMap = idlingResource.getMapboxMap(); locationLayerPlugin = rule.getActivity().getLocationLayerPlugin(); } catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { Timber.e("Idling resource timed out. Couldn't not validate if map is ready."); throw new RuntimeException("Could not start executeLocationLayerTest for " + this.getClass().getSimpleName() + ".\n The ViewHierarchy doesn't contain a view with resource id =" + "R.id.mapView or \n the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n"); } }
@Before public void setUp() throws Exception { instrumentation = InstrumentationRegistry.getInstrumentation(); activity = activityTestRule.launchActivity(new Intent()); countingResource = new CountingIdlingResource("MyRequest"); UrlRequest.setFactory(new UrlRequest.RequestFactory() { @NonNull @Override public UrlRequest makeRequest(URL url, UrlRequest.Listener listener) { return new UrlRequest(url, listener) { @Override public void run() { countingResource.increment(); super.run(); countingResource.decrement(); } }; } }); Espresso.registerIdlingResources(countingResource); }
private static ViewInteraction[] getButtonInteractions() { ViewInteraction[] buttonsInteractions = new ViewInteraction[10]; // We cannot rely on the withDigit() matcher to retrieve these because, // after performing a click on a button, the time display will update to // take on that button's digit text, and so withDigit() will return a matcher // that matches multiple views with that digit text: the button // itself and the time display. This will prevent us from performing // validation on the same ViewInteractions later. buttonsInteractions[0] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text10)); buttonsInteractions[1] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text0)); buttonsInteractions[2] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text1)); buttonsInteractions[3] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text2)); buttonsInteractions[4] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text3)); buttonsInteractions[5] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text4)); buttonsInteractions[6] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text5)); buttonsInteractions[7] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text6)); buttonsInteractions[8] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text7)); buttonsInteractions[9] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text8)); return buttonsInteractions; }
@Test public void checkToolbar() throws Exception { //Test with the string title mTestActivity.runOnUiThread(() -> mTestActivity.setToolbar(R.id.toolbar, ACTIVITY_TITLE, true)); CustomMatchers.matchToolbarTitle(ACTIVITY_TITLE).check(matches(isDisplayed())); Espresso.onView(withContentDescription("Navigate up")).check(matches(isDisplayed())); //Test with the string resource title mTestActivity.runOnUiThread(() -> mTestActivity.setToolbar(R.id.toolbar, R.string.app_name, true)); CustomMatchers.matchToolbarTitle(mTestActivity.getString(R.string.app_name)).check(matches(isDisplayed())); Espresso.onView(withContentDescription("Navigate up")).check(matches(isDisplayed())); //Hide home button mTestActivity.runOnUiThread(() -> mTestActivity.setToolbar(R.id.toolbar, ACTIVITY_TITLE, false)); try { Espresso.onView(withContentDescription("Navigate up")).perform(click()); Assert.fail(); } catch (NoMatchingViewException e) { //Pass } }
@Before public void init() { if (CameraUtils.isCameraAvailable(InstrumentationRegistry.getTargetContext())) { mCameraFragmentTestRule.launchActivity(null); } else { try { mCameraFragmentTestRule.launchActivity(null); fail("Should not initialize this ImageClassifierFragment if camera not there."); } catch (IllegalArgumentException e) { //Success } } //Wait for 1200 ms. //Wait for the camera to get stable Delay.startDelay(1200); Delay.stopDelay(); Espresso.onView(withId(R.id.container)); mImageClassifierFragment = mCameraFragmentTestRule.getFragment(); }
@Override protected void starting(Description description) { Espresso.registerIdlingResources(new IdlingResource() { @Override public String getName() { return "architecture components idling resource"; } @Override public boolean isIdleNow() { return TaskExecutorWithIdlingResourceRule.this.isIdle(); } @Override public void registerIdleTransitionCallback(ResourceCallback callback) { callbacks.add(callback); } }); super.starting(description); }
public void fooAllOf() { Espresso.onView(AllOf.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(AllOf.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(AllOf.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(AllOf.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click()); Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click()); Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click()); Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click()); Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click()); }
public void fooMatchers() { Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click()); Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click()); Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click()); Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click()); Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click()); }
public void fooCoreMatchers() { Espresso.onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(CoreMatchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click()); Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click()); Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click()); Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click()); Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click()); Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click()); }
protected void performStartAdventure() { ViewInteraction button = onView(allOf(withText(getString(R.string.create_new_adventure)), isDisplayed())); button.perform(click()); //Clicks over the proper book using the property order of the GamebookEnum DataInteraction textView = onData(anything()) .inAdapterView(allOf(withId(R.id.gamebookListView), childAtPosition( withClassName(is("android.widget.RelativeLayout")), 0))) .atPosition(getGamebook().getOrder() - 1); textView.perform(click()); button = onView(allOf(withText(getString(R.string.create_new_adventure)), isDisplayed())); button.perform(click()); Espresso.closeSoftKeyboard(); }
@Test public void addImage() { Intent resultData = new Intent(); Bitmap icon = BitmapFactory.decodeResource(getInstrumentation().getContext().getResources(), R.drawable.mock_camera_image); resultData.putExtra("data", icon); Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData); intending(not(isInternal())).respondWith(result); Espresso.closeSoftKeyboard(); onView(withId(R.id.imageOpacityOverlay)).perform(click()); onView(withId(R.id.imageOpacityOverlay)).check(matches(not(isDisplayed()))); onView(withId(R.id.imageDelete)).perform(click()); onView(withId(R.id.imageOpacityOverlay)).check(matches(isDisplayed())); }
@Test public void challengePressBackAndQuit() { onView(withId(R.id.search)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.empty_layout), UI_TEST_TIMEOUT)); onView(isAssignableFrom(EditText.class)).perform(typeText("R"), pressKey(KeyEvent.KEYCODE_ENTER)); tryIsDisplayed(withText("Runnest IHL"), UI_TEST_TIMEOUT); onView(withText("Runnest IHL")).perform(click()); //Create challenge onView(isRoot()).perform(waitForMatch(withId(R.id.main_layout), UI_TEST_TIMEOUT)); onView(withText(R.string.challenge)).perform(click()); tryIsDisplayed(withId(R.id.define_challenge), UI_TEST_TIMEOUT); onView(withId(R.id.customize_positive_btn)).perform(click()); //Wait Espresso.pressBack(); tryIsDisplayed(withId(android.R.id.button1), UI_TEST_TIMEOUT); onView(withText(R.string.quit)).perform(click()); }
@Test public void testOrientationChangeOnPaymentMethodList() throws Exception { goToPaymentListFragment(AMOUNT, EUR); EspressoTestUtils.rotateScreen(); onView(withText(equalToIgnoringCase("Credit Card"))).perform(scrollTo(), click()); waitForView(R.id.adyen_credit_card_no); Espresso.pressBack(); // closes the keyboard Espresso.pressBack(); EspressoTestUtils.rotateScreen(); onView(withText(equalToIgnoringCase("Credit Card"))).perform(scrollTo(), click()); waitForView(R.id.adyen_credit_card_no); Espresso.pressBack(); cancelCreditCardPayment(); }
private void cancelCreditCardPayment() throws Exception { Espresso.pressBack(); EspressoTestUtils.waitForView(R.id.activity_payment_method_selection); Espresso.pressBack(); EspressoTestUtils.waitForView(R.id.verificationTextView); try { // Actually this should not be required. However without pressing back one last time; the // activity cannot be started in the next test. To avoid it; we kill the PaymentResultActivity as well. Espresso.pressBack(); } catch (final NoActivityResumedException expected) { // expected } }
@Before public void registerIdlingResource() { instrumentationCtx = InstrumentationRegistry.getContext(); mIdlingResource = mActivityTestRule.getActivity().getIdlingResource(); // To prove that the test fails, omit this call: Espresso.registerIdlingResources(mIdlingResource); }
@Override public AppEventOuterClass.Swipe performWildCardTargetAction(AppEventOuterClass.Swipe origin, WildCardTarget target) { ViewAction swipe = swipeActions.get(origin.getPos().getOrientType()); Espresso.onView(target.uiMatcher).perform(swipe); AppEventOuterClass.Swipe.Builder builder = AppEventOuterClass.Swipe.newBuilder(); builder.setUiid(AppEventOuterClass.UIID.newBuilder().setIdType(AppEventOuterClass.UIID.UIIDType.NAME_ID) .setNameid(MatcherManager.describeMatcherAsDisplay(target.uiObj))).setPos(origin.getPos()); return builder.build(); }
@Before public void registerIdlingResource() { List<View> viewList = Arrays.asList( mActivityRule.getActivity() .findViewById(R.id.mainThreadEventFromMainThread), mActivityRule.getActivity() .findViewById(R.id.iOThreadEventFromMainThread), mActivityRule.getActivity() .findViewById(R.id.computationThreadEventFromMainThread), mActivityRule.getActivity() .findViewById(R.id.executorThreadEventFromMainThread), mActivityRule.getActivity() .findViewById(R.id.newThreadEventFromMainThread), mActivityRule.getActivity() .findViewById(R.id.postingThreadEventFromMainThread), mActivityRule.getActivity() .findViewById(R.id.trampolineThreadEventFromMainThread), mActivityRule.getActivity() .findViewById(R.id.mainThreadEventFromBgThread), mActivityRule.getActivity() .findViewById(R.id.iOThreadEventFromBgThread), mActivityRule.getActivity() .findViewById(R.id.computationThreadEventFromBgThread), mActivityRule.getActivity() .findViewById(R.id.executorThreadEventFromBgThread), mActivityRule.getActivity() .findViewById(R.id.newThreadEventFromBgThread), mActivityRule.getActivity() .findViewById(R.id.postingThreadEventFromBgThread), mActivityRule.getActivity() .findViewById(R.id.trampolineThreadEventFromBgThread) ); mIdlingResource = new ViewIdlingResource(viewList); Espresso.registerIdlingResources(mIdlingResource); }
public Act performWildCardAction(Act origin) { Espresso.onView(isRoot()).perform( new ChimpStagingAction() ); chimpDriver.preemptiveTraceReport(); try { ArrayList<UiObject2> uiObject2s = wildCardManager.retrieveUiObject2s(wildCardSelector, wildCardChildSelector, 10); ArrayList<WildCardTarget> matchers = MatcherManager.getViewMatchers(uiObject2s, userDefinedMatcher); while(matchers.size() > 0) { Log.i(tag("wildcard"), Integer.toString(matchers.size())); WildCardTarget target = wildCardManager.popOne(matchers); try { Log.i(tag("wildcard"), "Attempting to perform action on UiObject"); Act result = performWildCardTargetAction(origin, target); return result; } catch (AmbiguousViewMatcherException avme){ Log.e(tag("wildcard"), avme.toString()); } catch (NoMatchingViewException nmve){ Log.e(tag("wildcard"), nmve.toString()); } catch (PerformException pe){ Log.e(tag("wildcard"), pe.toString()); } } } catch (Exception ee) { Log.e(tag("wildcard"), "Error occurred at wild card top-level"); ee.printStackTrace(); } Log.e(tag("wildcard"), "Exhausted all wild card options."); return null; }
@Override public AppEventOuterClass.Click performWildCardTargetAction(AppEventOuterClass.Click origin, WildCardTarget target) { AppEventOuterClass.Click.Builder builder = AppEventOuterClass.Click.newBuilder(); builder.setUiid(AppEventOuterClass.UIID.newBuilder().setIdType(AppEventOuterClass.UIID.UIIDType.NAME_ID) .setNameid(MatcherManager.describeMatcherAsDisplay(target.uiObj))); Espresso.onView(target.uiMatcher).perform(click()); return builder.build(); }
@Override public AppEventOuterClass.LongClick performWildCardTargetAction(AppEventOuterClass.LongClick origin, WildCardTarget target) { Espresso.onView(target.uiMatcher).perform(longClick()); AppEventOuterClass.LongClick.Builder builder = AppEventOuterClass.LongClick.newBuilder(); builder.setUiid(AppEventOuterClass.UIID.newBuilder().setIdType(AppEventOuterClass.UIID.UIIDType.NAME_ID) .setNameid(MatcherManager.describeMatcherAsDisplay(target.uiObj))); return builder.build(); }
@Test public void verifyResponsesForEndpoints() { int endpointCount = 0; Map<String, BarricadeResponseSet> hashMap = barricade.getConfig(); for (String endpoint : hashMap.keySet()) { int responseCount = 0; onView(withId(R.id.endpoint_rv)).perform(RecyclerViewActions.actionOnItemAtPosition(endpointCount, click())); for (BarricadeResponse response : hashMap.get(endpoint).responses) { onView(withRecyclerView(com.mutualmobile.barricade.R.id.endpoint_responses_rv).atPosition(responseCount)).check( matches(hasDescendant(withText(response.responseFileName)))); responseCount++; } Espresso.pressBack(); } }
@Test public void testCustomTabUI() throws Exception { try { startWebServer(); // Launch activity with custom tabs intent activityTestRule.launchActivity(createCustomTabIntent()); // Wait for website to load onWebView() .withElement(findElement(Locator.ID, TEST_PAGE_HEADER_ID)) .check(webMatches(getText(), equalTo(TEST_PAGE_HEADER_TEXT))); // Verify action button is visible onView(withContentDescription(ACTION_BUTTON_DESCRIPTION)) .check(matches(isDisplayed())); // Open menu onView(withId(R.id.menuView)) .perform(click()); // Verify share action is visible onView(withId(R.id.share)) .check(matches(isDisplayed())); // Verify custom menu item is visible onView(withText(MENU_ITEM_LABEL)) .check(matches(isDisplayed())); // Close the menu again Espresso.pressBack(); // Verify close button is visible - Click it to close custom tab. onView(withId(R.id.customtab_close)) .check(matches(isDisplayed())) .perform(click()); } finally { stopWebServer(); } }
@Test public void signInNewUserSuccess_ShowsHomeScreen() throws Exception { FirebaseAuth.getInstance().signOut(); FakeAuthConnector.setFakeSuccess(true); createActivity(); // sign in screen should be closed: Espresso.onView(withId(R.id.buttonContinue)).check(doesNotExist()); // home screen should be opened: Espresso.onView(withId(R.id.recyclerContent)).check(matches(isDisplayed())); }
@Test public void shouldUpdateLocale_WhenResumed_IfLocaleHasBeenChanged() throws Exception { sampleScreen .launch() .changeLocale(LOCALE_ES_ES) .openNewScreen() .changeLocale(LOCALE_EN_EN); Espresso.pressBack(); sampleScreen.verifyLocaleChanged(LOCALE_EN_EN); }
@BeforeClass public static void setUp() throws Exception { RxIdlingResource rxIdlingResource = new RxIdlingResource(); Espresso.registerIdlingResources(rxIdlingResource); RxJavaPlugins.setScheduleHandler(rxIdlingResource); }