|
robotium的讨论组里有个话题是提到截图的 需要翻墙才能访问
http://groups.google.com/group/r ... d/b971d5f27edb0a86#
将需要截屏的图像保存在sd卡上,在编写testcase时调用 takeScreenShot()方法就能完成指定的截屏
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"); |
|