Deep snap automation using android endgame

I want to write espresso scripts to test deep binding and don't know where to start. Looking for solutions that will help me get more information, maybe a step-by-step procedure on how to get started.

For example: I’m looking for a scenario where you get a link in gmail, which indicates which user should be directed to the mobile application. How do I start checking something like this with espresso?

Thanks in advance.

+3
android deep-linking espresso
source share
2 answers

Start with an action rule.

@Rule public ActivityTestRule<YourAppMainActivity> mActivityRule = new ActivityTestRule<>(YourAppMainActivity.class, true, false); 

Then you need to parse something uri from the link and return the intention

 String uri = "http://your_deep_link_from_gmail"; private Intent getDeepLinkIntent(String uri){ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)) .setPackage(getTargetContext().getPackageName()); return intent; } 

Then you want the activity rule to trigger the intent

 Intent intent = getDeepLinkIntent(deepLinkUri); mActivityRule.launchActivity(intent); 
+1
source share

Good IntentTestRule is not working properly. So I will try to do this with an ActivityTestRule :

 public ActivityTestRule<MyActivity> activityTestRule = new ActivityTestRule<MyActivity>(MyActivity.class, false, false); 

And then I will write the correct UI Unit Test to be something like this:

 @Test public void testDeeplinkingFilledValue(){ Intent intent = new Intent(InstrumentationRegistry.getInstrumentation() .getTargetContext(), MyActivity.class ); Uri data = new Uri.Builder().appendQueryParameter("clientName", "Client123").build(); intent.setData(data); Intents.init(); activityTestRule.launchActivity(intent); intended(allOf( hasComponent(new ComponentName(getTargetContext(), MyActivity.class)), hasExtras(allOf( hasEntry(equalTo("clientName"), equalTo("Client123")) )))); Intents.release(); } 

With this, you are going to verify that de-engineering with the given request parameter is actually correctly restored by your activity, which processes the intent for deeplinking.

0
source share

All Articles