IBM Rational Functional Tester是由IBM推出的针对Java,.Net和Web应用程序的自动化测试工具,拥有功能强大的编辑器并支持多种脚本语言,还集成了ScriptAssure 技术、模式匹配、及数据驱动等高级特性,以增强测试脚本的灵活性。借助这一工具,测试人员可以轻松地录制或编写脚本来进行自动化测试,测试效率得到显著提高,因而受到广大功能测试人员的青睐。
/**
* Create a screenshot pool with limited capability, it only
* stores enough screenshots to create a pseudo-video of appointed length
*
* @param videoLength - length of pseudo-video
* @param snapInterval - interval to scratch screenshots, the unit is second
* @param replayIndefinitely - the video plays once or repeats indefinitely
* @param replaySpeed - play speed of the video,1 means fast,2 is normal,and 3 means slow
*/
public ScreenshotsPool(int videoLength, double snapInterval,
boolean replayIndefinitely, int replaySpeed) {
super();
this.isLimitedBuffer = true;
this.videoLength = videoLength;
this.snapInterval = snapInterval;
this.replayIndefinitely = replayIndefinitely;
//设置有效的回放速度;
if((replaySpeed==1)||(replaySpeed==2)||(replaySpeed==3))
this.replaySpeed = replaySpeed;
//通过伪视频长度videoLength和抓屏频率snapInterval计算出缓冲区的容量
this.bufferCapability = new Double(videoLength/snapInterval).intValue();
//初始化缓冲区
getBufferVec();
}
/**
* Get buffer pool that store screenshots
*
* @return Vector - the only buffer pool to store screenshots
*/
public Vector getBufferVec()
{
if(null==bufferVec)
bufferVec = new Vector(bufferCapability);
return bufferVec;
}
/**
* Push a new screenshot into buffer
* if the buffer is limited and has reached its capability, the oldest
* snapshot would be removed
*/
public void pushScreenshot()
{
//获得当前屏幕的截图对象
BufferedImage image = getCurrentScreen();
if(null==image)
return;
//如果截图缓冲区有固定容量,
if(isLimitedBuffer){
//如果已经到达缓冲区的最大容量,则删去第一副截图
int size = getBufferVec().size();
if(size==bufferCapability)
getBufferVec().remove(0);
}
//将当前截图存入缓冲区
getBufferVec().add(image);
}
/**
* Generate pseudo-video with those buffered screens in pool
*
* Here we will generate animated picture of '.gif' format, and we can
* generate animated picture of other formats likewise.(SVG, PNG, etc.)
*/
public void generatePseudoVideo()
{
int size = this.getBufferVec().size();
if(size<1)
return;
try{
BufferedImage bi = null;
//新建一个AnimatedGifEncoder对象,用来生成动态的GIF文件
AnimatedGifEncoder pseudoVideoGenerator = new AnimatedGifEncoder();
//设置GIF文件是否循环显示各帧
int repeat = replayIndefinitely?0:1;
pseudoVideoGenerator.setRepeat(repeat);
//设置输出位置,以当前时间为文件名
pseudoVideoGenerator.start(outputLocation+getCurrentTime()+pseudoVideoFormat);
//依次将缓冲区内的所有截图按指定间隔加入AnimatedGifEncoder对象
for(int i=0;i