TA的每日心情 | 无聊 10 小时前 |
---|
签到天数: 528 天 连续签到: 1 天 [LV.9]测试副司令
|
Sikuli框架在出现异常时,没有做出一些好的处理,比如截图,打印日志,还有对程序的回收,我们可以通过java中的方法对Sikuli进行封装一下,实现这些功能,好了,看如下代码
- package com.sikuli;
-
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.awt.Robot;
- import java.awt.Toolkit;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import javax.imageio.ImageIO;
- import org.apache.log4j.LogManager;
- import org.apache.log4j.Logger;
- import org.apache.log4j.xml.DOMConfigurator;
- import org.sikuli.script.Screen;
-
-
- public class SikuliElWait {
-
-
- /****************************************************************
- * 对屏幕进行拍照
- *
- ****************************************************************/
-
- public static void snapShot(String path) throws Exception {
-
- String imaFormat ="png";
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- String fName = path +"eImage/";
-
- BufferedImage screenshot = (new Robot()).createScreenCapture(new
- Rectangle(0, 0, (int) d.getWidth(), (int) d.getHeight()));
-
-
- File folder =new File(fName);
- if (!folder .exists() && !folder .isDirectory()) {
- folder.mkdir();
- }
-
- String name=fName+"err."+imaFormat;
- File f = new File(name);
-
- //将screenshot对象写入图像文件
- ImageIO.write(screenshot, imaFormat, f);
-
- }
-
- /****************************************************************
- * 等待元素出现,如果元素有异常,进行当前页面截图并关闭应用程序
- *
- ****************************************************************/
-
- public static void waitEl(Screen scr,String className,String path,String ima,double time,Process app) throws Exception{
- Logger log = LogManager.getLogger(className);
- DOMConfigurator.configure("log4j.xml");
- try {
- scr.wait(path+ima, time);
- log.info("元素存在");
- } catch (Exception e) {
- SikuliElWait.snapShot(path);
- log.info("元素不存在");
- app.destroy();
- throw(e);
- }
- }
-
- }
复制代码
|
|