lundi 2 juillet 2018

Espresso doesn't run Activity test with Gif animation

I am trying to test intents in Activity and some button clicks in Fragment (which is in the same activity) with Espresso but the problem is the Fragment contains a custom view with Gif animation in it. The custom view is basically a variation of Movie class to display Gif. The error I get is

Could not launch intent Intent within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time

So it indicates I suppose that Gif causes the main thread to be loaded and the test cannot run. What I tried:

  1. Turn off all tree animation scales in Dev options (tried 2 devices)
  2. Using Ui automator and running shell adb command to turn animation off
  3. Trying to set the view with Gif's visibility to gone during the test

Non of which didn't work. I suppose that this custom view is not considered animation by the platform and doesn't get turned off. I can still see it. And I tried to findViewById and setting visibility to gone. The view is still there when the test is started. I think making view gone is a good workaround so maybe someone knows the way!

My test code:

@RunWith(AndroidJUnit4.class) public class TutorialActivityTest {

    private TutorialActivity tutorialActivity;
    private TutorialFragment tutorialFragment;

    @Rule
    public ActivityTestRule<TutorialActivity> mActivityRule = new ActivityTestRule<>(TutorialActivity.class);

    @Before
    public void setUp() {
        tutorialActivity = mActivityRule.getActivity();
        //tried to set visibility there with fragment.getView().findViewById... And also in the test directly

    @Test
    public void testOpenMainPageIntentFired() {
        Intents.init();
        tutorialActivity.openMainPage();
        intended(hasComponent(MainActivity.class.getName()));
        Intents.release();
    }

Aucun commentaire:

Enregistrer un commentaire