本篇主要从以下几个方面来总结一下WebDriver 与文件系统的操作
一 屏幕截图操作:
接口函数:takesScreenshot
功能:在运行测试用例的规程中,需要验证某个元素的状态或者显示的数值时,可以将屏幕截取下来进行对比,或者在异常或者错误发生的时候将屏幕截取并保存起来,供后续分析和调试所用。
采用Firefox Driver进行讲解
import *;
public class testTakesScreenshot{
WebDriver driver = new FirefoxDriver();
@Before
public void setUp() throws Exception{
driver.get("http://www.baidu.com");
}
@Test
public void testTakesScreenShot() throws Exception{
File srcFile= ((takesScreenshot.)driver).getScreenshotAs(OutputType,File);
FileUtils.copyFile(srcFile,new File("/selenium 2/screenshot.png"));
}
@After