How to verify redirection to Google Play Store

0
0

Using Robotium, how do I check the redirection to Google Play Store?

Steps:

  1. Click on a link from a listview from the test app.
  2. Verify it redirects to Google Play Store.

I noticed that while Google Play Store is open, my test app is actually open underneath also. (I printed out all the views)

Therefore, I cannot do “assert xyz view from test app does NOT exist”.

How do I check the redirection to Google Play?

  • You must to post comments
0
0

Is it possible? sort of, unfortunately robotium makes it very hard to do so easily, this is because of the way that robotium tracks what the current activity is, if you was using straight instrumentation it would be as easy as having an intent filter set up before you click the view/perform action that launches the play store, then you can assert that your filter has in fact been hit (which proves that the google play store would in fact be launched if you did not have the filter).

As you are using robotium though, you cannot do this so easily as robotium has already got an intent filter up that matches everything so this means you are going to have to do some horribleness with reflection.

What you will need to do is:

Get Hold of the private member of the instrumentation class called mActivityMonitors, in this list of activity monitors you will find there is one inside of it, this will be robotiums activity monitor, save this somewhere then remove it from the list.

You will then need to add your own it will look something like to test googleplay launches (i suggest reading about Intent filters on the android api documents site)

Instrumentation inst = getInstrumentation();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_View);
ActivityMonitor monitor = inst.addMonitor(intentFilter, null, true); //true is imporant it blocks the activity from launching so that your test can continue.
assertEquals(0, monitor.getHits());
//do action that fires activity
assertEquals(1, monitor.getHits());
inst.removeMonitor(monitor);

You will now need to readd the activity monitor you removed earlier so that robotium continues to work as expected. I am not on a machine that i can actually test this all on but i have used this technique before.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website