Issue
I'm trying to check whether the phone dialer opens with the correct phone number through Espresso but not really able to do it so far. I've tried:
Intents.init();
Intent stubIntent = new Intent();
Instrumentation.ActivityResult stubResult = new Instrumentation.ActivityResult(Activity.RESULT_OK, stubIntent);
intending(hasAction(Intent.ACTION_DIAL)).respondWith(stubResult);
intended(Matchers.allOf(hasAction(Intent.ACTION_DIAL), hasData(Uri.parse("+3531234567"))));
And also
Intents.init();
intended(allOf(hasAction(Intent.ACTION_DIAL), hasData(Uri.parse("+3531234567"))));
The dialer is being triggered through an autoLink on the TextView on my XML if that helps in any way?
android:autoLink="all"
and that's the dialer opened by Espresso
Thanks very much.
Solution
It really doesn't seem to work with the autoLink and based on @Aaron's great help that's what worked for me.
1 - Remove autoLink from TextView
2 - Trigger the intent normally through an OnClickListener as
tvCallNumber.setText(phone); // phone = +3531234567
tvCallNumber.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phone));
startActivity(intent);
}
});
3 - Make sure the phone number is prefixed with "tel:"
4 - Have the right order for the test actions
Intents.init();
Intent stubIntent = new Intent();
Instrumentation.ActivityResult stubResult = new Instrumentation.ActivityResult(Activity.RESULT_OK, stubIntent);
intending(hasAction(Intent.ACTION_DIAL)).respondWith(stubResult);
onView(withId(R.id.tv_call_number)).perform(click());
intended(Matchers.allOf(hasAction(Intent.ACTION_DIAL), hasData(Uri.parse("tel:+3531234567"))));
Answered By - Francislainy Campos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.