Last active
February 25, 2020 18:39
-
-
Save RicardoBelchior/484fd2e30ebedd7fafa6d07a7607308c to your computer and use it in GitHub Desktop.
ScreenshotsAutomator sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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