Issue
I am trying to test a click on a button that sends the user to the Phone activity... Like this:
public void callNumber(String number){
Uri numberUri = Uri.parse("tel:"+number);
Intent callIntent = new Intent(Intent.ACTION_DIAL, numberUri);
startActivity(callIntent);
}
Well... but when I run this test:
@Rule
public IntentsTestRule<HelpView> mActivityRule = new IntentsTestRule<>(HelpView.class, true, true);
@ClassRule
static public DeviceAnimationTestRule deviceAnimationTestRule = new DeviceAnimationTestRule();
@Test
public void clickDialButtonTest(){
onView(withId(R.id.help_viewpager)).perform(swipeLeft());
onView(withId(R.id.help_viewpager)).perform(swipeLeft());
onView(withId(R.id.phone_call_btn)).perform(click());
intended(allOf(hasAction(Intent.ACTION_DIAL)));
}
I get this:
Wanted to match 1 intents. Actually matched 0 intents.
Edit:
Actually, what happens is that Espresso doesn't wait for the switch in the ViewPager to complete. So when the button is clicked, nothing is happening. I can fix the problem with this:
@Test
public void clickOnMapButtonTest() {
onView(withId(R.id.help_viewpager)).perform(swipeLeft());
onView(withId(R.id.help_viewpager)).perform(swipeLeft());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
Assert.fail();
}
onView(withId(R.id.phone_call_btn)).perform(click());
intended(allOf(hasAction(Intent.ACTION_DIAL), toPackage("com.android.dialer")));
}
But this looks a bit wrong... Maybe there's a better way. Does any one has a better option?
Any help is appreciated!
Solution
You're probably using ActivityTestRule
instead of IntentsTestRule
.
Edit:
You shouldn't use Thread.sleep(2000)
... The Espresso way of "waiting" is using IdlingResource
. Here's a simple explanation of you can follow.
Answered By - Bartek Lipinski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.