Taking screen shots during test

106 views
Skip to first unread message

Pigor

unread,
Apr 15, 2010, 2:22:42 PM4/15/10
to Robotium Developers
Just wanted to share how you can take canvas screen shots and save to
sdcard during test, something to add to robotium...

public static String SCREEN_SHOTS_LOCATION="/sdcard/";

public static void takeScreenShot(View view) throws Exception {
takeScreenShot(view, "default");
}

public static void takeScreenShot(View view, String name) throws
Exception {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b = view.getDrawingCache();
FileOutputStream fos = null;
try {
File sddir = new File(SCREEN_SHOTS_LOCATION);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREEN_SHOTS_LOCATION+name+"_"
+ System.currentTimeMillis() + ".jpg");
if (fos != null) {
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
}
} catch (Exception e) {
}
}

//call
takeScreenShot(solo.getViews().get(0), "testname");

Renas Reda

unread,
Apr 15, 2010, 2:30:50 PM4/15/10
to Robotium Developers
Hi Pigor,

Thanks! This looks very interesting! Definetly something we will
include in our next release.

Thanks for sharing.

Sincerely,
Renas

Reply all
Reply to author
Forward
0 new messages