Skip to content

Instantly share code, notes, and snippets.

@RicardoBelchior
Last active February 25, 2020 18:39
Show Gist options
  • Save RicardoBelchior/484fd2e30ebedd7fafa6d07a7607308c to your computer and use it in GitHub Desktop.
Save RicardoBelchior/484fd2e30ebedd7fafa6d07a7607308c to your computer and use it in GitHub Desktop.
ScreenshotsAutomator sample
@RunWith(AndroidJUnit4.class)
public class ScreenshotsAutomator {
@BeforeClass
public static void setUpOnce() {
EspressoTestSetup.injectScreenshotsData(...);
// Tell AndroidX to process each screenshot with our 'processor'
// See https://github.com/android/android-test/blob/master/runner/android_junit_runner/java/androidx/test/runner/screenshot/BasicScreenCaptureProcessor.java
Screenshot.setScreenshotProcessors(
Collections.singleton(new ScreenshotToSdCardProcessor(getAppContext())));
}
@Test
public void article_portrait() throws Exception {
// You can also set a desired orientation or theme for
// different screenshots for portrait/landscape/light/dark mode
// Open the activity
articleRule = new ActivityTestRule<>(ArticleActivity.class, true, false);
articleRule.launchActivity(ArticleActivity.buildIntent(getAppContext(), articleId));
// Take screenshot using AndroidX Screenshot API
Screenshot.capture()
.setFormat(Bitmap.CompressFormat.PNG)
.setName(createScreenshotName())
.process();
articleRule.getActivity().finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment