Getting a screenshot is simple - you just invoke poseForScreenshot()
when you want one :
import static com.github.rtyley.android.screenshot.celebrity.Screenshots.poseForScreenshot;
public void testAppearance() {
startActivitySync(ConfigureMorseActivity.class);
Instrumentation instrumentation = getInstrumentation();
sleep(500); // robotium provides neater ways of waiting for the activity to initialise
poseForScreenshot();
instrumentation.sendStringSync("s");
poseForScreenshot();
instrumentation.sendStringSync("o");
poseForScreenshot();
instrumentation.sendStringSync("s");
poseForScreenshot();
}
The rest of the test is just setting up the activity so it’s ready to have it’s screenshot taken
- ie startActivitySync() and then waiting a short period for the activity to be ready. The screenshots
will be placed in a 'screenshots' folder under your instrumentation test target directory, for example:
morseflash/morseflash-instrumentation/target/screenshots
They’re named sequentially by default (0000.png, 0001.png, etc), but you can set an explicit name
for the shot using poseForScreenshotNamed("foobar")
if you like. In addition, for each android
device used in the tests, an animated-gif will be created showing all screenshots taken.