截图:当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: