dimanche 11 août 2019

How to test launching new Activity with Espresso via OnClick action?

I have a RecyclerView in my Fragment and by clicking on each item an activity (SampleActivity) have to launch.

I wrote some UI test for this behavior like this:

 @Test
    public void listRecyclerView_ClickOnTapligh() {

        Espresso.registerIdlingResources(simpleListFragment.idlingResource);

        onView(withId(R.id.root_list))
          .perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));

        Intents.init();
        intended(hasComponent(SampleActivity.class.getName()));
        Intents.release();
    }

But I'm getting this error :

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.

IntentMatcher: has component: has component with: class name: is "com.sample.sdk.android.view.SamppleActivity" package name: an instance of java.lang.String short class name: an instance of java.lang.String

I also tried this

intended(hasComponent(new ComponentName(getTargetContext(), TaplighActivity.class)));

But I had the same error.

Aucun commentaire:

Enregistrer un commentaire