|
不晓得对大家有没有用.
selenium.captureEntirePageScreenshot(arg0, arg1)这个方法是把图片截到了运行sever的那台机器上了,当我们用例和sever不是一台机器的时候就不太方便,所以我们需要用captureEntirePageScreenshotToString(arg0)将图片变为Base64的字符串在转化成图片,存到我们的本地,这样可以将报告和图片生成在一起.下面是转换图片的代码
private static char[] encodes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
.toCharArray();
private static byte[] decodes = new byte[256];
static {
for (int i = 0; i < encodes.length; i++) {
decodes[encodes] = (byte) i;
}
}
public static byte[] decodeBase64(char[] data) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length);
int pos = 0, val = 0;
for (int i = 0; i < data.length; i++) {
val = (val << 6) | decodes[data];
pos += 6;
while (pos > 7) {
baos.write(val >> (pos -= 8));
val &= ((1 << pos) - 1);
}
}
return baos.toByteArray();
}
public static void saveErrImage(String pngString, String fileName) {
try {
File png = new File(fileName);
FileOutputStream fos = new FileOutputStream(png);
fos.write(_FrameUtil.decodeBase64(pngString.toCharArray()));
fos.flush();
fos.close();
} catch (Exception e) {
}
}
[ 本帖最后由 wugecat 于 2010-5-18 09:50 编辑 ] |
|