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

One question in the original post has been left unaddressed:

How can I get the current GIT branch name, and make it observable for a Test Case scripts in Katalon Studio?

If you have the git command installed on your machine, then in the command line you can easily do this operation:

$ cd <projectdir>
$ git branch --show-current
master

The string "master" here is the current GIT branch name. So, I would require executing the "git branch --show-current" command from a Katalon test script, capture the output string from the git command, save the returned value into a Groovy variable, and reuse the value somehow (e.g, transfer it into a test report).

I found a Katalon documentation titled “Execute Windows Commands in Katalon Studio” that describes how to use java.lang.Runtime class in a Test Case script. I tried the way that this document describes. I made a Test Case/TC0, which looks:

// Test Cases/TC0
Runtime.getRuntime().exec("git branch --show-current")

I ran the TC0 using Katalon Studio v10.1.0 on Mac. It silently PASSED. It showed the following message in the Console.

3月 17, 2025 12:13:18 午後 com.kms.katalon.core.logging.KeywordLogger startTest
情報: --------------------
3月 17, 2025 12:13:18 午後 com.kms.katalon.core.logging.KeywordLogger startTest
情報: START Test Cases/TC0
3月 17, 2025 12:13:19 午後 com.kms.katalon.core.logging.KeywordLogger endTest
情報: END Test Cases/TC0

Not useful at all. The document didn’t tell me how to read the output from the executed command. The doc is not worth reading.

Solution

I read the following article:

I made a Test Cases/TC1:

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

Process subprocess = 
	new ProcessBuilder("git", "branch", "--show-current").start()

BufferedReader brStderr = 
	new BufferedReader(new InputStreamReader(subprocess.getErrorStream()))
List<String> errLines = brStderr.readLines()
errLines.forEach { println it }

//The Process InputStream (our point of view) is the STDOUT from the subprocess point of view
BufferedReader brStdout = 
	new BufferedReader(new InputStreamReader(subprocess.getInputStream()))
List<String> outLines = brStdout.readLines()
outLines.forEach { println it }

println "exit: " + subprocess.exitValue()

String branchName = outLines[0]
WebUI.comment("Current GIT branch: ${branchName}")

When I ran this using Katalon Studio v10.1.0 Free, I got the following output in the console:

3月 17, 2025 6:07:48 午後 com.kms.katalon.core.logging.KeywordLogger startTest
情報: START Test Cases/TC1
master
exit: 0
3月 17, 2025 6:07:49 午後 com.kms.katalon.core.logging.KeywordLogger logInfo
情報: Current GIT branch: master
3月 17, 2025 6:07:49 午後 com.kms.katalon.core.logging.KeywordLogger endTest
情報: END Test Cases/TC1

The TC1 could get the current GIT branch name “master”. I think this is good enough.

1 Like