Home > Software engineering >  ScreenShot Not showing in testNg Report plugin
ScreenShot Not showing in testNg Report plugin

Time:11-25

I have an issue where the screenshots that i take dont show in the TestNg Report Plugin i am pretty sure that the probleme is the path i am giving them but i dont know what other path i can give is there a solution ?

My screenshot taking code :

public void ScreenShot() {
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH_mm_ss");
    LocalDateTime now = LocalDateTime.now();
    String destDir = System.getProperty("user.dir")   "/"   "test-output/ScreenShots";
    String FileName = "SoftAssertScreenshot_"   dtf.format(now)   ".png";
    String DestFile = destDir   "/"   FileName;
    Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
    BufferedImage image = screenshot.getImage(); 
    try {
        ImageIO.write(image, "PNG", new File(DestFile));
        System.out.println("test");
    } catch (IOException e) {
        e.printStackTrace();
    }
    Reporter.log("</br><font color='#73a9d0'>***************Screen Of the error****************</font>");
    Reporter.log("</br><img id='ErrorResult' src='"   DestFile   "' style='width:600px'/>");
}

What shows in testng report : [![Image of testng result][1]][1]

Html in testng :

<img id="ErrorResult" src="C:\Users\user\eclipse-workspace\07zr-aut\Demo_Automatisation/test-output/ScreenShots/SoftAssertScreenshot_2021-11-24 08_50_12.png" style="width:600px">

Thanks for the help ! [1]: enter image description here

HTML:

<img id="ErrorResult" src="C:\Users\Nandan\EclipseWorkspace\Selenium3_SO/Data/SO.png" style="width:600px">

There is nothing wrong with your Reporter.log code. Please try the below,

  • Check is the image really exists in location C:\Users\user\eclipse-workspace\07zr-aut\Demo_Automatisation/test-output/ScreenShots/SoftAssertScreenshot_2021-11-24 08_50_12.png

  • Put a debug point after line ImageIO.write(image, "PNG", new File(DestFile)); to confirm image is successfully written in the given location.

  • screenshot.getImage(); what is the purpose of getImage() method? Does it returning RenderedImage? If yes, where are you passing the file location? I am doing like below below and it is working. Are you following same approach?

String DestFile = System.getProperty("user.dir")   "/Data/" imageName ".png";
Image image = ImageIO.read(new File(DestFile));
BufferedImage buffered = (BufferedImage) image;
ImageIO.write(buffered, "PNG", new File(DestFile));

This should help you. You need to find out the exact location of screenshots folder in Jenkins workspace and update String destDir

  • Related