7
votes

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

2
Action will not be performed because the target view does not match one or more of the following constraints did you read through this? - Jared Burrows
@JaredBurrows yes, i see it, i have a slide up button animation, but how can i wait for 1 sec? I tried Thread.sleep(1000); etc. but it not helps - Gorets
Ah, thanks for updating you post. I think you are doing the right thing by using Espresso. Check this out: stackoverflow.com/questions/21417954/espresso-thread-sleep. - Jared Burrows
thx, I'm going to try it now, its really strange case, because I haven't got this problem in robotium, but i got flaky tests and errors like OOM in emulators (not real devices), so I decided migrate to other one - Gorets
Ah it is two different frameworks by different authors. This is good, so when the next person runs into this we can just search for this question :) - Jared Burrows

2 Answers

4
votes

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!

-3
votes
@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());
    }


}