Espresso Screen Capture

I use Espresso to test my interface in my project. I want to take a screenshot for each operation (Screen). I am using ScreenShooter from GoogleCloudTestLab to take screenshots.

   ScreenShotter.takeScreenshot("main_screen_2", getActivity());

But this is only a screen shot of the 1st action, which I defined in my ActivityTestRule. How can I shoot another activity screen in the same test file.

+4
source share
2 answers

My understanding is that the ActivityTestRule is designed to test only one action in the test folder, so getActivity () will only return the activity that you specified in the ActivityTestRule.

, :

View screenView = activity.getWindow().getDecorView().getRootView(); screenView.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache()); screenView.setDrawingCacheEnabled(false);

( - , .)

, takecreenshot, . , ?

, , .

. Firebase Test Lab, ( ), /sdcard/screenshots, .

+2

, , . , , () :

/**
 * A helper method to get the currently running activity under test when a test run spans across multiple
 * activities. The {@link android.support.test.rule.ActivityTestRule} only returns the initial activity that
 * was started.
 */
public static final Activity getCurrentActivity(Instrumentation instrumentation)
{
    final Activity[] currentActivity = new Activity[1];
    instrumentation.runOnMainSync(new Runnable()
    {
        public void run()
        {
            Collection<Activity> resumedActivities =
                ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext())
            {
                currentActivity[0] = resumedActivities.iterator().next();
            }
        }
    });
    return currentActivity[0];
}

getInstrumentation() , .

+1

All Articles