Как добавить Снимок экрана в Отчет о протяженности для пройденных тестов в рамках Selenium огурца.
@After(order = 1)
public void after(Scenario scenario) throws IOException {
TransferFiles files = new TransferFiles();
String buildPath;
String finalFile;
if (scenario.isFailed()) {
String screenshotName = scenario.getName().replaceAll(" ", "_") + "_" + String.valueOf(random);
try {
//This takes a screenshot from the driver at save it to the specified location
File sourcePath = (((TakesScreenshot) TestBase.driver).getScreenshotAs(OutputType.FILE));
File fileTempImg = new File("C:\\ScreenShot0011\\001temp001.png");
FileUtils.copyFile(sourcePath, fileTempImg);
InetAddress addr;
addr = InetAddress.getLocalHost();
buildPath = String.valueOf(fileTempImg).replaceAll("C:", addr.getHostName());
finalFile = "//" + buildPath.replaceAll("\\\\", "/");
//finalFile = "\\\\" + buildPath;
files.transferFiles(finalFile, screenshotName, "png");
//This attach the specified screenshot to the test
addScreenCaptureFromPath("path/" + screenshotName + ".png");
fileTempImg.delete();
} catch (Exception e) {
System.out.println("The specified file have not been found on the local machine:-" + e.getMessage());
}
}