What is the correct mechanism to deal with Interstitial Ad during Espresso Tests?
There is Interstitial Ad between two activities and I want to write an Espresso Test spanning both activities.
Is there any way to close the Interstitial Ad during Espresso test to continue testing second Activity?
IMO, the correct solution is to setup your tests so they don't need to span multiple activities.
Tests should be focused and isolated. You don't need to span Activities to assert behavior because there is a logical separation at the transition point. So instead of writing a test that says "doing x in Activity A should open Activity B in state y, and doing z in Activity B should do this or that", you write multiple tests:
1) "doing x in Activity A should launch an intent to open Activity B" (you don't care about the UI state or your ad), which you can easily verify with the Intents API.
2) "launching Activity B with a given Intent (which is what you expect from the transition from A to B) should initialize it to state y", which you can easily set up by passing an Intent to your activity rule and using matchers on the UI.
3) "doing z in Activity B when started with state y should do this or that", which you can easily verify by starting the activity as in (2).
Hope that helps.