- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只想在意外异常时捕获屏幕截图。
最佳答案
注意。-此答案可能已过时。答案基于 Selenium 2.15
使用 TestWatcher有没有技巧(单元测试必须在 BaseTest
之后扩展):
public abstract class BaseTest {
// ...
protected WebDriver driver;
@Rule
public TestRule testWatcher = new TestWatcher() {
@Override
public void starting(Description desc) {
LOG.info("Launching browser...");
driver = Utils.getFirefoxDriver();
}
@Override
public void finished(Description desc) {
LOG.info("Quitting driver...");
driver.quit();
}
@Override
public void failed(Throwable e, Description d) {
LOG.debug("Creating screenshot...");
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(
OutputType.FILE);
String scrFilename = "Screenshot.png";
File outputFile = new File(SCREEN_SHOTS_RESULTS_PATH, scrFilename);
LOG.info(scrFilename + " screenshot created.");
try {
org.apache.commons.io.FileUtils.copyFile(scrFile, outputFile);
} catch (IOException ioe) {
LOG.error("Error copying screenshot after exception.", ioe);
}
}
};
}
Utils.getFirefoxDriver()
返回定制的
WebDriver
.类似的东西:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class Utils {
// ...
public static WebDriver getFirefoxDriver() {
FirefoxProfile firefoxProfile = new FirefoxProfile();
// Profile customization. For example:
// firefoxProfile.addExtension("firebug-1.8.4-fx.xpi");
// firefoxProfile.setPreference("extensions.firebug.currentVersion","1.8.4");
FirefoxBinary firefox = new FirefoxBinary();
// Firefox customization. For example:
// firefox.setEnvironmentProperty("DISPLAY", display);
WebDriver driver = new FirefoxDriver(firefox, firefoxProfile);
// WebDriver customizations. For example:
// driver.manage().timeouts().implicitlyWait(SHORT_TIMEOUT_S, TimeUnit.SECONDS);
return driver;
}
}
关于exception-handling - Selenium 2 和 JUnit4 : How to capture screenshot on exception?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6520974/
使用我的 huawei honor 10 (android 8.1) 当我尝试从 android 设备监视器截取屏幕截图时出现此错误: [2018-09-18 08:44:24 - Screensho
一周以来我一直在学习 Nutch(版本 Nutch-1.14),并且在本地模式以及 Hadoop-2.7.2(伪分布式模式)下工作正常。今天我在 nutch-site.xml 中遇到了“take.sc
我有下面的代码来使用 Shutterbug 捕获屏幕截图。但它会创建该文件夹并将屏幕截图存储在该文件夹中。有人可以帮我找出问题吗?理想情况下,我想将所有屏幕截图保存在一个文件夹中。 public cl
下面是包含“protractor-jasmine2-screenshot-reporter”和“jasmine-reporter”的配置文件 它单独工作正常,但如果我结合使用 protractor-j
我想知道是否有一种快速算法可以检测在两个连续屏幕截图之间移动的部分。该算法应该采用两张图像并输出一个图像中的一组(矩形)区域和一个描述匹配区域在另一张图像中的位置的向量。 我想将它用于为屏幕捕获而简化
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 1年前关闭。 Improve thi
我希望能够创建给定网站的屏幕截图,但该网站可能比在屏幕上所能看到的要大。有没有办法做到这一点? 目标是在 WinForms 应用程序中使用 C# 中的 .NET 执行此操作。 最佳答案 有一些工具。
如何截取访问者的页面屏幕截图?就像 Gmail 错误填充器一样。 http://i.imgur.com/GAMZV.png 最佳答案 我认为这是一种方式:http://html2canvas.hert
我正在寻找一种方法,让技术不熟练的用户可以轻松地向我提交浏览器的屏幕截图,以帮助调试 Web 应用程序问题。 Web 应用程序内的所有页面上都会有一个按钮,他们可以用来报告问题,我想提交一个屏幕截图(
我想捕获监视器或窗口的屏幕截图,最好使用 AutoIt(我愿意使用任何方便的方法)。由于程序要整夜运行,因此该方法需要能够在工作站锁定时运行。 我不能简单地输入代码来解锁工作站,因为它会带来安全风险。
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我在下面使用这段代码,但生成的图像已损坏。我认为可能是因为渲染选项。有人知道发生了什么事吗? package webpageprinter; import java.net.URL; import j
我越来越多地看到带有动画 gif 的 apis 或插件页面,例如 atom 包似乎做了很多。 见 https://atom.io/packages/terminal-status或 https://a
我正在尝试截取在 lcdtv 上播放的 roku 应用程序的屏幕截图。 将您的 Roku 置于开发者模式。确认您的 Roku 的 IP 地址。 Side load your app to the Ro
我想使用DirectX 10逐帧渲染视频。这些帧稍后将由其他一些工具(例如mencoder或ffmpeg)进行处理。 使用D3DXSaveSurfaceToFile在DX9中这样做没有问题。 现在,在
我目前正在编写一个在游戏客户端内部运行的脚本,并且我想向我的脚本添加屏幕截图功能。我现在正在使用机器人,但我希望能够截取客户端的屏幕截图,即使它被最小化。有什么办法可以做到这一点吗?如果是这样,怎么办
没有。不按 PRT 屏幕。但这就是我想要的。我需要知道它是否可以完成以及通过什么方式完成:D 好吧,我有一个运行并显示行走的人的 Java 小程序。我需要它,所以当我访问一个脚本(使用某种网络脚本语言
我正在尝试允许用户捕获我的目标元素(段落)的屏幕截图网页,然后在 div(而非 Canvas )上显示捕获的屏幕截图,他们可以在其中下载屏幕截图。 这是我正在努力完成的视觉效果:http://i.im
我目前正在制作一款全屏游戏,我希望能够截取一些屏幕截图。我发现了这个小代码片段: BufferedImage image = new Robot().createScreenCapture(new R
我有一个网页的 URL,我想在后台截取该网页的“屏幕截图”,例如。在服务中,不向用户显示 UI。 我尝试在我的服务中创建一个 WebView,然后使用 capturePicture() 方法在页面加载
我是一名优秀的程序员,十分优秀!