标签:apach 代码实现 print ack file类 img ota putty log
一、截图
1. Firefox浏览器截图
FirefoxDriver firefoxDriver = new FirefoxDriver(); firefoxDriver.getScreenshotAs(OutputType type);
2. Chrome浏览器截图
ChromeDriver chromeDriver = new ChromeDriver(); chromeDriver.getScreenshotAs(OutputType type);
3. IE浏览器的截图
InternetExplorerDriver ieDriver = new InternetExplorerDriver(); ieDriver.getScreenshotAs(OutputType type);
二、代码实现
1.创建浏览器驱动参考:https://www.cnblogs.com/xiaozhaoboke/p/11074562.html
2.浏览器截图实现代码:
package cn.test; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.testng.annotations.Test; import cn.test.BaseCase; public class Screenshots extends BaseCase { @Test public void test() { try { driver.get("http://www.baidu.com");//获取当前系统时间 Date date = new Date(); //定义系统时间输出格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); String strTime = sdf.format(date); File img =null; if(driver instanceof ChromeDriver) { //将driver向下转型chromeDriver ChromeDriver chromeDriver = (ChromeDriver)driver; //调用chromeDriver.getScreenshotAs()方法得到截图文件 img= chromeDriver.getScreenshotAs(OutputType.FILE); }else if(driver instanceof FirefoxDriver){ FirefoxDriver firefoxDriver = (FirefoxDriver)driver; img = firefoxDriver.getScreenshotAs(OutputType.FILE); }else if(driver instanceof InternetExplorerDriver) { InternetExplorerDriver ieDriver = (InternetExplorerDriver)driver; img = ieDriver.getScreenshotAs(OutputType.FILE); } //使用commons.io包提供的FileUtils工具类,直接copy一份保存到指定路径下 //copyFile方法传入的都是File类型 FileUtils.copyFile( img, new File("src/test/resources/"+strTime+"_img.png")); } catch (Exception e) { e.printStackTrace(); } } }
学习后总结,不足之处后续补充,未完待续。。。
标签:apach 代码实现 print ack file类 img ota putty log
原文地址:https://www.cnblogs.com/xiaozhaoboke/p/11139738.html