8

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

Gorets
  • 2,434
  • 5
  • 27
  • 45
  • `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 Jul 14 '15 at 14:12
  • @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 Jul 14 '15 at 14:18
  • Ah, thanks for updating you post. I think you are doing the right thing by using Espresso. Check this out: http://stackoverflow.com/questions/21417954/espresso-thread-sleep. – Jared Burrows Jul 14 '15 at 14:25
  • 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 Jul 14 '15 at 14:32
  • 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 Jul 14 '15 at 14:32
  • so result is bad, because actually button is on the view and we don't need wait. And more details about animation: I haven't do any transformations with button just splash screen over button hides with 1 sec animation – Gorets Jul 14 '15 at 14:45
  • Hi @Gorets, if you were to provide a little of the code for the `IntroActivity`, that'd help. Otherwise, there's a lot of guesswork. You're getting answers that include best practices, but not necessarily solutions. We'd have to know how you built the View in question. All we know right now is that your matcher is failing. – OYRM Feb 24 '16 at 16:56
  • To wait for the Test case or dealy execution of test case use this one. SystemClock.sleep(2000); ///2 seconds – Nikunjkumar Kapupara Dec 26 '17 at 09:17

2 Answers2

4

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!

sunlover3
  • 1,999
  • 1
  • 20
  • 25
  • Tried but didnt work, it fails for me when I run it on a physical samsung s7 device inside firebase, if I see the result video, part of the screen is black, looks like it was resized for the video. – Daniel Gomez Rico Oct 25 '17 at 15:26
-3
@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());
    }


}