selenium-java,UI自动化截图方法
2017-09-13 17:43
344 查看
截图方法:
使用示例:
import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; public class Aiding_Method { /* * 参数 * String screenPath:文件路径 * 例:D:\\图片\\新增-上传-返回.jpg * WebDriver driver:测试类定义的driver对象 */ public void takeScreenshot(String screenPath, WebDriver driver) { try { File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);//OutputType.FILE--截幕保存为图片 FileUtils.copyFile(scrFile, new File(screenPath));//把图片保存到指定路径 } catch (IOException e) { System.out.println("截图出现错误"); } } }
使用示例:
public class Test { private WebDriver driver; @Before public void setUp() throws Exception { element_operation = new Element_operation(); System.setProperty("webdriver.chrome.driver","D:\\Configuration\\chromedriver.exe");//谷歌浏览器路径 driver = new ChromeDriver(); driver.manage().window().maximize();//最大化浏览器 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("http://www.baidu.com"); } @After public void tearDown() throws Exception { try { Thread.sleep(1000); } catch (Exception e) { // TODO: handle exception } driver.quit(); } @Test public void test1() throws ParseException{ Aiding_Method aiding_Method = new Aiding_Method(); aiding_Method.takeScreenshot("C:\\Users\\Administrator\\Desktop\\1.jpg", driver); } }
相关文章推荐
- mac java+selenium 实现UI自动化1_琉璃
- mac java+selenium 实现UI自动化2_琉璃
- selenium-java,解决一些加了显性等待和隐性等待都不好使的情况,以及给UI自动化加上暂停功能
- java+selenium实现自动化打开页面的方法
- Java+ selenium+maven截图方法TakeScreenshot
- Java+Selenium3方法篇30-Selenium中截图方法-TakeScreenshot
- 2011/06/13 android使用html做UI的方法---js与java的相互调用
- 如何搭建Selenium-Grid2环境(Java)(自动化测试技术)
- java 利用java运行时的方法得到当前屏幕截图的方法(转)
- selenium+java+testNG+pageObject深入理解自动化测试框架
- 使用自动化测试框架selenium,批量的进行截图
- Python写自动化之一种截图方法
- Selenium2学习-035-WebUI自动化实战实例-033-页面快照截图应用之三 -- 区域截图(专业版)
- 使用 Selenium Grid2 来提高全球化测试中自动化截图的执行效率
- selenium+java+testNG+pageObject深入理解自动化测试框架
- Selenium2学习-025-WebUI自动化实战实例-023-页面快照截图应用之一 -- 常规截图(全页面)
- Selenium2学习-033-WebUI自动化实战实例-031-页面快照截图应用之二 -- 区域截图
- java封装selenium2常用方法
- Selenium+常用的方法(Java)
- JDT:详解JavaUI.createTypeDialog方法