我正在使用黄瓜范围报告来生成测试执行的报告。 我使用Cucumber + Selenium + Junit框架,而端到端的测试用例必须与chrome和IE浏览器交互才能完成EtoE流程。 示例场景如下
Given Login to abc url in IE browser
And Perform abc task
Then Login to xyz url in Chrome browser
And Perform xyz task
When Login to abc url in IE browser
Then validate the final result
要生成屏幕截图并附加到范围报告中,我添加了以下代码。 “驱动程序”用于IE驱动程序,“驱动程序Chrome”用于Chrome驱动程序。
@After(order = 1)
public void afterScenario(Scenario scenario) {
if (scenario.isFailed()) {
String screenshotName = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()).replace(":", "_")+"_"+scenario.getName().substring(0, 40).replaceAll(" ", "_");
try {
File sourcePath = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File destinationPath = new File(reportPath+ screenshotName + ".png");
Files.copy(sourcePath, destinationPath);
Reporter.addScreenCaptureFromPath(destinationPath.toString());
Reporter.addStepLog("Exception screenshot " +destinationPath.toString());
if(driverChrome!=null)
{
sourcePath=((TakesScreenshot) driverChrome).getScreenshotAs(OutputType.FILE);
destinationPath = new File(reportPath+ screenshotName + "_chrome.png");
Files.copy(sourcePath, destinationPath);
Reporter.addScreenCaptureFromPath(destinationPath.toString());
Reporter.addStepLog("Exception screenshot " +destinationPath.toString());
}
} catch (IOException e) {
LOGGER.error("Exception occured in afterscenario method "+e.getMessage());
}
}
}
上面的代码正在捕获IE和Chrome浏览器的屏幕截图。 目前,它同时包含IE和Chrome浏览器。但是我想在范围报告中附加活动浏览器的屏幕截图。 有人可以帮我实现这一目标