Is possible to add in html or pdf reports, the git current branch?

I´m trying to customize the html and pdf report in order to show some usefull information.

I would like to show the current branch of the repository that I´m testing in the Excecution environment section of the report

I have been able to print the current branch at test case level with this code in the test case file:

import com.kms.katalon.core.util.KeywordUtil

def branchName = ‘git branch --show-current’.execute().getText().trim()
KeywordUtil.logInfo("La rama actual de este análsis es: "+ branchName)

But where can I print the branchName varable in order to be shown in Excecution environment section? Is it possible to do it?

Thanks in advence.

1 Like

Hi there, and thanks for posting in the Katalon community! :hugs:

To help you faster, please review our guide on Git here:

Double-checking the steps and configurations might resolve the issue.

If the doc doesn’t help, feel free to provide more details, and a community member will assist you soon. Thanks for being a part of our community!

Best,
Albert Le

No, you can’t.

The program which compiles the built-in reports (both HTML and PDF) is not customizable at all. You are wasting your time. I would recommend you to abandon your idea.


I would explain by code what I stated above. The com.kms.katalon.core.reporting.ReportUtil is the program that compiles the reports. You can find the full souce code in the <Katalon Studio installed folder>/Contents/Eclipse/configuration/resources/source/com.kms.katalon.core/com.kms.katalon.core-sources.jar file.

Let me quote a method:

public class ReportUtil {
    ....
    private static StringBuilder generateVars(List<String> strings, TestSuiteLogRecord suiteLogEntity,
            StringBuilder model) throws IOException {
        StringBuilder sb = new StringBuilder();
        List<String> lines = IOUtils
                .readLines(ResourceLoader.class.getResourceAsStream(ResourceLoader.HTML_TEMPLATE_VARS));
        for (String line : lines) {
            if (line.equals(ResourceLoader.HTML_TEMPLATE_SUITE_MODEL_TOKEN)) {
                sb.append(model);
            } else if (line.equals(ResourceLoader.HTML_TEMPLATE_STRINGS_CONSTANT_TOKEN)) {
                appendReportConstantValues(strings, sb);
            } else if (line.equals(ResourceLoader.HTML_TEMPLATE_EXEC_ENV_TOKEN)) {
                StringBuilder envInfoSb = new StringBuilder();
                envInfoSb.append("{");
                envInfoSb.append(String.format("\"host\" : \"%s\", ", suiteLogEntity.getHostName()));
                envInfoSb.append(String.format("\"os\" : \"%s\", ", suiteLogEntity.getOs()));
                envInfoSb.append(String.format("\"" + StringConstants.APP_VERSION + "\" : \"%s\", ",
                        suiteLogEntity.getAppVersion()));
                if (suiteLogEntity.getBrowser() != null && !suiteLogEntity.getBrowser().equals("")) {
                    if (suiteLogEntity.getRunData().containsKey("browser")) {
                        envInfoSb.append(
                                String.format("\"browser\" : \"%s\",", suiteLogEntity.getRunData().get("browser")));
                    } else {
                        envInfoSb.append(String.format("\"browser\" : \"%s\",", suiteLogEntity.getBrowser()));
                    }
                }
                if (suiteLogEntity.getDeviceName() != null && !suiteLogEntity.getDeviceName().equals("")) {
                    envInfoSb.append(String.format("\"deviceName\" : \"%s\",", suiteLogEntity.getDeviceName()));
                }
                if (suiteLogEntity.getDeviceName() != null && !suiteLogEntity.getDeviceName().equals("")) {
                    envInfoSb.append(String.format("\"devicePlatform\" : \"%s\",", suiteLogEntity.getDevicePlatform()));
                }
                envInfoSb.append("\"\" : \"\"");

                envInfoSb.append("}");
                sb.append(envInfoSb);
            } else {
                sb.append(line);
                sb.append("\n");
            }
        }
        return sb;
    }
    ...

As you see, the content of “the Execution environment section of the report” is hard-coded in the ReportUtil class.

You would need to “change” the source code of the ReportUtils class. But in fact you can’t do it.

you can try with custom report not with katalon built-in reports

Thanks for the answers I´m going to explore your options @dineshh and @kazurayam, but I get the idea that it is not to be easy.

1 Like

If you are “going to explore something”, I would recommend you to look at the Extent Reports

https://extentreports.com/

It enables you to compile a test report using the Extent Reports. It is open-sourced, is free to use.

By the way, Katalon offers a Plugin “Extent Reports integration”:

The integration plugin is priced. If you have an Katalon Studio Eterprise license, it will help you a lot.

If you don’t have an Enterprise license, and if you are a skilled Java programmer, you would be able to re-invent the plugin for yourself. It would be a fun.

1 Like

Hi @amartinezalf,

Can you please help try @kazurayam suggestion and let us know if it helps? So that other people can refer to this. Thank you

Why don’t you just say “Please consider purchacing an Enterprise license and apply the Extent Reports integration plugin” ?

That’s the shortest path, isn’t it.

1 Like

I found a GitHub repository that contains a Katalon Studio project with some sample codes that work with Extent Reports:

This project is licensed under the MIT License.

This project seems to work with Katalon Studio Free v10.1.0. I cloned the repository; I amended the project a bit (I found a compile error, but I could easily fix it); I could run it successfully. I got a report like this.

It appears fine.


By the way, what is the relationship between the Extent Reports integration plugin and the Extent Report sample project? These 2 projects share a single class named com.katalon.extent.report.ExtentReport. I’m confused.

I guess, Katalon started with the the Extent Report sample project on GitHub, but one day (five months ago) they decided to stop maintaining it for free; they transfered the code base to their private repository, published the priced “Integration plugin”. Possibly, they will maintain only the “Integration plugin” in future. ---- This is just my guess. I don’t know the true history.

@amartinezalf

I modified the code of Extent Report sample a bit.

package com.katalon.extent.report
...
public class ExtentReport {
    ...
	@Keyword
	def startEReport(TestCaseContext testCaseContext) {
		if(getExecutionSourceName.startsWith("Test Suite")) {
			String driverString = DriverFactory.getExecutedBrowser().getName()
			String execID = RunConfiguration.getExecutionSourceName()
			String testcasename = testCaseContext.getTestCaseId().substring(testCaseContext.getTestCaseId().lastIndexOf('/') + 1)
			extentTest = extent.createTest(execID+" : "+testcasename, "Test Execution: "+testCaseContext.getTestCaseId());
			extentTest.assignAuthor("HOST: "+RunConfiguration.getHostName().toUpperCase())
			extentTest.assignCategory("BROWSER: "+driverString.substring(0, driverString.indexOf("_")))
			extentTest.assignCategory("PROFILE: "+RunConfiguration.getExecutionProfile().toUpperCase())
			extentTest.assignCategory("GROUP: "+TestCaseFactory.findTestCase(testCaseContext.getTestCaseId()).getTag().toUpperCase())
			
            extentTest.assignCategory("GIT BRANCH:" + "master") // @kazurayam inserted this statement
		}
		else {
			WebUI.comment("To Generate an Extent Report execute tests from the Test Suite.")
		}
	}

The report showed "GIT BRANCH: master", as follows

It was easy.

1 Like

Amazing research, thanks @kazurayam I will check it when reporing tasks appear in the following sprints. Thanks for your time

As I wrote above, I experimented customizing the source code of com.katalon.extent.report.ExtentReport class. It worked fine. I copied the original source out of the GitHub repository extent-report-sample/Keywords/com/katalon/extent/report/ExtentReport.groovy at master · coty/extent-report-sample · GitHub as one shot. I would never fetch the source from the extent-report-sample repository again.

On the other hand, the changelog of the plugin tells me that Katalon has made serveral updates to the plugin recently. They will continue updating the plugin in future.

Now I’ve got a doubt. Let me assume I get an Enterprise license and apply the Extent Report integration plugin. And let me assume I have made the aforemention amendment to the com.katalon.extent.report.ExtentReport class.

What will happen if the plugin is updated in future, and if I pull the updated plugin version?

Will the Groovy source of the com.katalon.extent.report.ExtentReport be

  1. overwritten by the updated plugin version.
  2. perform line-by-line merging

???

I don’t know. I guess the case.1 is likely. The case2 is unlikely.

In the case1, I would loose any changes that I made in the source. In other words, the Extent-Report-Integration plugin does not allow me to customize it.

I think that it is a poor idea for me to edit the source of com.katalon.extent.report.ExtentReport class which is originated by Katalon. I need to find out some alternative coding trick.

See also

How to apply Extent Reports to Katalon Studio project