Emailable Extent Report for TestNG

If you were following my blog, do you remember few days before I’ve announced a new java library called TestNG Extent Reporter?
Now I’ve released a new feature called Emailable Report which I believe many of us eagerly needed from the extent report.

In case you are new to my blog, and wanted to have a look at TestNG Extent Reporter, head here for more details.

How to generate emailable report?

Follow here to setup. That is all you have to do to generate the emailable-report.html in the TestNG’s default output folder.

In case you want to overwrite the output folder location, then pass the jvm parameter as follows:

mvn clean test -DreportPath=output

The above will generate report.html and emailable-report.html in the ${project directory}/output directory.

This is the initial version of emailable report and there could be more features added. So feature requests are always welcome. To request for features, kindly log it here.

38 Replies to “Emailable Extent Report for TestNG”

  1. Hi Vimal, when I send html report with screenshots using Extent Reports via email to clients, they are not able to see the screenshots. Can you pls help me out to resolve this issue so that everyone can see the snapshots that I send. This is the most crucial part of my project. Thanks in advance! 🙂

    1. Hi Satya,

      Currently you have only option to zip everything along with your screenshots and share it. If you have some server where you can push your screenshots after your execution, then that can be added as a link in the extent report. If this is the case, then I can help you. Otherwise, only zipping can help you.

        1. Hi Satya,

          I second Gothandapani’s comment. The Base64 option could be a ideal solution for your case. I’ll send you some examples once I reach home.

          1. You cannot convert your existing png to base64 and attach it to report. While writing your script itself you should use addBase64ScreenShot() method instead of addScreenCapture() method. Since this thread is going long, I would appreciate you log an issue in the github for further discussion on this. I will try to help you to solve the problem.

    2. Hi Satya, facing same issue. Since the screenshot is in my local system others unable to view it. Could u plz share the full code if u have solved it.

  2. Hi Satya,

    For this screenshot issue, I have taken screenshot using selenium web driver then converted into Base64 and added with image/src tag while adding into the report file. It’s worked. So we will get the screenshots in report itself.

    1. Thanks Vimal, Does zipping html report + screenshots open the html with screenshots once it is unzipped? If it is pushed to the server, how can we do it? It is also helpful for me. Thanks in advance

  3. Hi Sathya,

    Below is the java code.

    Method to take screenshot in base64 format

    @SuppressWarnings("resource")
    public static String addScreenshot() {
        File scrFile = ((TakesScreenshot) BasePage.driver).getScreenshotAs(OutputType.FILE);
        String encodedBase64 = null;
        FileInputStream fileInputStreamReader = null;
        try {
            fileInputStreamReader = new FileInputStream(scrFile);
            byte[] bytes = new byte[(int)scrFile.length()];
            fileInputStreamReader.read(bytes);
            encodedBase64 = new String(Base64.encodeBase64(bytes));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "data:image/png;base64,"+encodedBase64;
    }
    

    Code to add the screenshot into HTML file.

    ExtentReport.getTest().log(LogStatus.FAIL, stepDescription +"<br><br>"+ ExtentReport.getTest().addScreenCapture(ExtentReport.addScreenshot()));
    

        1. Yes, happy me as well. Base64.encodeBase64(bytes) didn’t work, I changed it to Base64.getEncoder().encode(bytes). It has been working. Thanks again.

    1. Hi Muthu,

      I can append the screenshot in extent report has Base64 formate, but in the report when I click on the screenshots to view , It’s display has encrypted.. do we have any solution to click on the base64 screenshot image and view.

    2. Hi Muthu,

      i am also facing the same issue with 2.4, i have tried with above code but no luck still displaying the blank

  4. Hi Vimal,

    Able to add info steps in the report using Reporter.log, but how to add Pass or Fail steps with descriptions.
    I couldn’t find it. Can you please help?

    Thanks.
    Rajaseekhar

      1. I will try to do Vimal..I see one issue is that Time stamp is not updating correctly for steps. I am not able to attach screenshot, Please find the copied steps here:

        Status Timestamp Details
        check_circle 4:27:34 PM Status:1
        info_outline 4:27:34 PM Another Simple testMY Message
        check_circle 4:27:34 PM Passed

      2. Hi Vimal,

        I have tried one small solution for logging PASS/FAIL/INFO steps by tweaking code (afterInvocation method)below :

        for (String log : logs) {
        if (log.contains(“PASS::”)) {
        test.pass(log.split(“::”)[1]);
        } else if(log.contains(“FAIL::”)) {
        test.fail(log.split(“::”)[1]);
        } else if (log.contains(“INFO::”)) {
        test.info(log.split(“::”)[1]);
        } else {
        test.info(log);
        }
        }

        We need to provide Reporter log steps like in below:

        Reporter.log(“INFO:: New Test Info”);
        Reporter.log(“PASS:: New Test Passed”);
        Reporter.log(“FAIL:: New Test Failed”);

        Can you please review and let me know your thoughts.

        Thanks,
        Rajasekhar

      3. Hi Vimal,

        I have tried to add small tweaking in afterInvocation method as in below

        for (String log : logs) {
        if (log.contains(“PASS::”)) {
        test.pass(log.split(“::”)[1]);
        } else if(log.contains(“FAIL::”)) {
        test.fail(log.split(“::”)[1]);
        } else if (log.contains(“INFO::”)) {
        test.info(log.split(“::”)[1]);
        } else {
        test.info(log);
        }
        }

        We need to provide Reporter.log steps like in below

        Reporter.log(“INFO:: New Test Info”);
        Reporter.log(“PASS:: New Test Passed”);
        Reporter.log(“FAIL:: New Test Failed”);

        Can you please review and let me know your thoughts.

        Thanks,
        Rajasekhar

  5. Hi Vimal,

    As we are seeing only INFO steps in extent reports when using Reporter.log. But my team suggested me to log PASS/FAIL/INFO steps instead of just INFO all the times..So tried to tweak the code as mentioned above. Can you please share the latest jar if that is a workable solution?

    Thanks,
    Rajasekhar

        1. The reporter.log is meant to just gather additional information of the test. The reporter log should not ideally decide whether your test pass or fail. With that saying, this plugin will not provide you that feature out of the box. Kindly use the approach as you have mentioned earlier.

  6. Hi Vimal, Can you please provide me your Mail Id or linkedIn profile so that i can interact with you directly.

Leave a Reply