截图:当case failed时保留现场

上一篇 / 下一篇  2012-05-25 17:28:44 / 个人分类:TestNG/Ant/Eclipse/Java

package TEST;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import java.io.IOException;
import org.openqa.selenium.TakesScreenshot;

@Test
public class captureShot {
public void f() {
      WebDriver driver = new FirefoxDriver();
   String baseurl = "http://xin.msn.com/?lang=zh-sg.aspx";
   driver.get(baseurl); 
   try {
   Thread.sleep(5000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
   File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
  
   try {
   FileUtils.copyFile(screenShotFile, new File("D:/test123.png"));
  } catch (IOException e) {
   e.printStackTrace();
  }
   driver.quit();

  }
}


TAG:

 

评分:0

我来说两句

日历

« 2024-05-14  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 74676
  • 日志数: 80
  • 建立时间: 2012-04-12
  • 更新时间: 2013-05-21

RSS订阅

Open Toolbar