WebDriver进行屏幕截图
来源:互联网 发布:c语言判断奇偶 编辑:程序博客网 时间:2024/05/16 03:53
例: 打开百度首页 ,进行截图
package com.example.tests;import java.io.File;import org.apache.commons.io.FileUtils;import org.junit.*;import org.openqa.selenium.*;import org.openqa.selenium.ie.InternetExplorerDriver;public class Selenium2 {@Testpublic void testTakesScreenshot() {WebDriver driver = new InternetExplorerDriver();driver.get("http://www.baidu.com");try {File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);FileUtils.copyFile(srcFile,new File("d:\\screenshot.png"));} catch (Exception e) {e.printStackTrace();} driver.close();}}
TakesScreenshot接口提供了getScreenshotAs()方法来捕捉屏幕。上面的例子中,我们指定了OutputType.FILE作为参数传递给getScreenshoAs()方法,告诉它将截取的屏幕以文件形式返回。
如果使用的是RemoteWebDriver() ,则方法应该如下
首先启动selenium java -jar selenium-server-standalone-2.25.0.jar
package com.example.tests;import java.io.File;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import org.apache.commons.io.FileUtils;import org.junit.*;import org.openqa.selenium.*;import org.openqa.selenium.remote.*;public class Selenium2 {@Testpublic void testRemoteWebDriverScreenShot() {//指定使用的浏览器DesiredCapabilities capability = DesiredCapabilities.internetExplorer();WebDriver driver = null;try {driver = new RemoteWebDriver( //我使用localhost来测试new URL("http://localhost:4444/wd/hub"), capability);} catch (MalformedURLException e) {e.printStackTrace();}driver.get("http://www.sina.com.cn");//对远程系统进行截图driver = new Augmenter().augment(driver); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);try {FileUtils.copyFile(scrFile, new File("D:\\screenshot.png"));} catch (IOException e) {e.printStackTrace();}}}
- WebDriver进行屏幕截图
- 对屏幕进行截图
- 利用CImage进行屏幕截图
- 利用CImage进行屏幕截图
- Android上使用SkBitmap 进行屏幕截图
- C#进行屏幕截图简洁代码
- webdriver 截图公用方法
- webdriver 截图公用方法
- WebDriver - 失败截图
- 屏幕截图
- 屏幕截图
- 屏幕截图
- 屏幕截图
- 屏幕截图
- 屏幕截图
- 屏幕截图
- 屏幕截图
- 屏幕截图
- 实用软件介绍
- 百度网盟广告关键词定向展现方式原理
- 函数的声明问题
- 超发的货币在不断地稀释货币应该体现的价值
- VB.net工程师的面试
- WebDriver进行屏幕截图
- ccms bug记录1
- BeautifulSoup
- 在Ubuntu 10.10上安装Ubuntu Tweak的方法
- hdu 1421 搬寝室(DP)
- 如何在django中使用mako模板系统
- [面试] 百度笔经加面经 实例
- Eclipse/CDT(Linux/Mac osx) 极速配置
- android tabhost tab内多个activity的跳转(包括返回)