Gorets
Gorets

Reputation: 2442

Espresso perform click

I've tried to write simply test using 'espresso'

@RunWith(AndroidJUnit4.class)
@LargeTest
public class EspressoTest {
    @Rule
    public ActivityRule<IntroActivity> mActivityRule = new ActivityRule(IntroActivity.class);

    public EspressoTest() {
        IdlingPolicies.setMasterPolicyTimeout(1000, TimeUnit.SECONDS);
    }

    @Test
    public void testShouldClickEmailButton() {
            onView(withText(R.string.in_email)).perform(click());
    }


}

but I got an error:

PerformException: Error performing 'single click' on view 'with string from resource id: <2131099761>[in.email] value: Login With Email'.

I am trying different frameworks for testing and robotium is the best for me by now, but if somebody can help fix this error I will be very grateful

UPD more detailed log

Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view's area is displayed to the user. Target view: "DSeparatedButton{id=2131427459, res-name=button_login, visibility=VISIBLE, width=622, height=120, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=333.0, text=Login With Email, input-type=0, ime-target=false, has-links=false}"

Also I have a little splash animation

enter image description here

Upvotes: 8

Views: 15727

Answers (2)

sunlover3
sunlover3

Reputation: 2049

onView method is used only for views that are 100% visible on the screen, so Espresso can test them properly. My suggestion is to use onData method to test the view. This should work:

    onData(withText(R.string.in_email)).perform(click());

I can help you more if this will not be the answer you are searching for. Just let me know if this didn't work. Good luck!

Upvotes: 4

yangjiannan
yangjiannan

Reputation: 1

@RunWith(AndroidJUnit4.class)
@LargeTest
public class EspressoTest {
    @Rule
    public ActivityTestRule<IntroActivity> mActivityRule = new ActivityTestRule(IntroActivity.class);



    @Test
    public void testShouldClickEmailButton() {
            mActivityRule.launch(new Intent());
            onView(withText(R.string.in_email)).perform(click());
    }


}

Upvotes: -3

Related Questions