当前位置: 首页>>代码示例>>Java>>正文


Java Espresso类代码示例

本文整理汇总了Java中android.support.test.espresso.Espresso的典型用法代码示例。如果您正苦于以下问题:Java Espresso类的具体用法?Java Espresso怎么用?Java Espresso使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Espresso类属于android.support.test.espresso包,在下文中一共展示了Espresso类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFullLifecycleIncludingConfigurationChange

import android.support.test.espresso.Espresso; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:TiPluginTest.java

示例2: intentWithStubbedTaskId

import android.support.test.espresso.Espresso; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:Captwalloper,项目名称:NUI_Project,代码行数:27,代码来源:StatisticsScreenTest.java

示例3: beforeTest

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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");
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:18,代码来源:NavigationMapRouteTest.java

示例4: testLinearFlow

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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());
}
 
开发者ID:Adyen,项目名称:adyen-android,代码行数:20,代码来源:PaymentAppTest.java

示例5: testActionBarTitle

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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");
}
 
开发者ID:Adyen,项目名称:adyen-android,代码行数:21,代码来源:PaymentAppTest.java

示例6: clickTest

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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"));

}
 
开发者ID:cuplv,项目名称:ChimpCheck,代码行数:19,代码来源:ExampleInstrumentedTest.java

示例7: performMatcherAction

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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;
}
 
开发者ID:cuplv,项目名称:ChimpCheck,代码行数:21,代码来源:ClickPerformer.java

示例8: launchQualifiesEvent

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@Override
protected EventTraceOuterClass.Qualifies launchQualifiesEvent(EventTraceOuterClass.Qualifies qualifies)
        throws MalformedBuiltinPredicateException, ReflectionPredicateException, PropertyViolatedException, NoViewEnabledException {
    Log.i(runner.chimpTag("[email protected]"), qualifies.toString());

    Espresso.onView(isRoot()).perform( new ChimpStagingAction() );

    PropResult res = check( qualifies.getCondition() );

    if (res.success) {
        for (EventTraceOuterClass.UIEvent uiEvent : qualifies.getTrace().getEventsList()) {
            executeEvent( uiEvent );
        }
    } else {
        Log.i(runner.chimpTag("[email protected]"),"Condition failed: " + qualifies.getCondition().toString());
    }

    return qualifies;
}
 
开发者ID:cuplv,项目名称:ChimpCheck,代码行数:20,代码来源:EspressoChimpDriver.java

示例9: before

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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);
}
 
开发者ID:ecarrara-araujo,项目名称:yabaking,代码行数:19,代码来源:Rx2IdlingSchedulerRule.java

示例10: signInFailure_ShowsErrorMessage

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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());
}
 
开发者ID:Frank1234,项目名称:FireBaseTest,代码行数:18,代码来源:SignInScreenTest.java

示例11: beforeTest

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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");
  }
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:17,代码来源:TrafficPluginTest.java

示例12: beforeTest

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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");
  }
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:17,代码来源:LocationLayerTest.java

示例13: setUp

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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);
}
 
开发者ID:UTN-FRBA-Mobile,项目名称:Clases-2017c1,代码行数:22,代码来源:SelectPictureActivityTest.java

示例14: getButtonInteractions

import android.support.test.espresso.Espresso; //导入依赖的package包/类
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;
}
 
开发者ID:philliphsu,项目名称:NumberPadTimePicker,代码行数:21,代码来源:NumberPadTimePickerDialogTest.java

示例15: checkToolbar

import android.support.test.espresso.Espresso; //导入依赖的package包/类
@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
    }
}
 
开发者ID:kevalpatel2106,项目名称:smart-lens,代码行数:22,代码来源:BaseActivityTest.java


注:本文中的android.support.test.espresso.Espresso类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。