如何为Selenium或Java中的软件断言拍摄屏幕截图 [英] How to take a screenshot for Soft Assert in Selenium or Java
本文介绍了如何为Selenium或Java中的软件断言拍摄屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图为使用软断言失败的测试用例截取屏幕截图.我正在使用softAssertion来检查特定步骤失败时,它在报告中显示了失败的步骤,但继续执行. tescase在Assert..plz软帮助中失败时的屏幕截图?
Iam trying to take a screenshot for a testcase which fails using soft Assertion.I am using softAssertion for when a particular step fails it shows the failed step in the report but continues the execution.So in such case how can I take a screenshot whenever the tescase fails in soft Assert..plz help ?
推荐答案
在 executeAssert 的catch块中,调用需要截屏的方法或在其中实现代码.
In the catch block of executeAssert either call a method that takes screenshot or implement the code there.
@Override
public void executeAssert(IAssert a) {
try {
a.doAssert();
} catch (AssertionError ex) {
onAssertFailure(a, ex);
takeScreenshot();
m_errors.put(ex, a);
}
}
private void takeScreenshot() {
WebDriver augmentedDriver = new Augmenter().augment(driver);
try {
if (driver != null
&& ((RemoteWebDriver) driver).getSessionId() != null) {
File scrFile = ((TakesScreenshot) augmentedDriver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(("./test-output/archive/"
+ "screenshots/" + "_" + ".png")));
}
} catch (Exception e) {
e.printStackTrace();
}
}
这篇关于如何为Selenium或Java中的软件断言拍摄屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文