How to apply Extent Reports to Katalon Studio project

I have published a GitHub repository at


Problem to solve

In the Katalon Community forum, there was a topic

Let me quote a part of the post here:

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

The original poster tried to customize the built-in HTML report compiled by Katalon Studio, but he could not find out the way. I knew the answer to him. The Katalon built-in report is not customizable at all. Then, what should he do?

Solution

In the following post, I suggested Extent Reports. Using it, he should be able to compile a new test execution report. It would be easy to insert the Git branch name, like GIT BRANCH: master.

Description

In the GitHub, I found a public repository by coty, Katalon CTO.

The repository contains a Katalon Studio project. Katalon users can learn how to use the Extent Reports in a Katalon project.

I forked the project to form a new GitHub repository at

I made some changes in the forked repository, and got a success to create a HTML report that displays :

GIT BRANCH master

Environment

I used

  • macOS Sonoma 14.7.3

  • Katalon Studio Free 10.1.0

How to run the demo

You can run the project and see the demonstration as follows:

  1. Clone the Git repository https://github.com/kazurayam/extent-reports-applied-to-katalon-studio-project to your local machine.

  2. Open the project with your Katalon Studio. Execute “Test Suites/Suite002”. It will take 30 seconds or so.

  3. When the Test Suite finished, you will find <projectDir>/Extent/yyyyMMdd_hhmmss/kseqatestreport.html, which looks something like this:

kseqatestreport.html

How the project is coded

My demo project is entirely a fork from the coty’s original project.

I made several changes in my demo project. You can find the exact differences between the original and my derivatives at the GitHub diff compare page at

Please note the following 3 points:

No change in com.katalon.extent.report.ExtentReport class

The com.katalon.extent.report.ExtentReport class
is the core part of the project, which implements the interface between your Katalon test scripts and the Extent Reports library. I made no change in it. The class source in my demo project is just
the same as the original.

Therefore, whenever the original repository is updated, I would not hesitate to do “git pull” from the original repository in to my fork.

A new class com.kazurayam.ks.ExtentReportsKeyword

I added a new class com.kazurayam.ks.ExtentReports. This class borrows all the methods of the com.katalon.extent.report.ExtentReport class as component. However, my class is capable to inject my own customization in to the report. For example, see the startEReport method:

   @Keyword
    def startEReport(TestCaseContext testCaseContext) {
        component.startEReport(testCaseContext)
        // customize the report!
        component.extentTest.assignCategory("GIT BRANCH: " + getGitBranch())
    }

Changed the TestListener

I edited the Test Listeners/ExtentReportsListener.groovy so that it no longer calls the original com.katalon.extent.ExtentReport keyword. Instead, It calls the new com.kazurayam.ks.ExtentReportKeyword. You can see the diff of old/new ExtentReportsListener at:

I would quote a small piece out of the changes:

        @BeforeTestSuite
        def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) {
-               //CustomKeywords.'com.katalon.extent.report.ExtentReport.deleteFolderContents'()
-               CustomKeywords.'com.katalon.extent.report.ExtentReport.attachEReport'(testSuiteContext, "Extent Report", "KSE QA Test Report")
+               //CustomKeywords.'com.kazurayam.ks.ExtentReportsKeyword.deleteFolderContents'()
+               CustomKeywords.'com.kazurayam.ks.ExtentReportsKeyword.attachEReport'(testSuiteContext, "Extent Report", "KSE QA Test Report")
        }

A warning. If the original repository by @coty is updated in future and if I do “git pull” into the fork, then it is likely to encounter some merge conflicts over the Test Listeners/ExtentReportsListener.groovy. However, I believe the original repository will be left unmaintained in future. So that, I wouldn’t mind this risk too much.

How the external dependancies are managed?

If you look into the <projectDir>/Drivers, you will find several jar files on which this project depends.

$ tree Drivers
Drivers
├── extentreports-5.1.1.jar
├── freemarker-2.3.32.jar
├── katalon_generated_extentreports-5.1.1.jar
├── katalon_generated_freemarker-2.3.32.jar
├── katalon_generated_gson-2.10.1.jar
├── katalon_generated_lombok-1.18.26.jar
├── katalon_generated_reactive-streams-1.0.4.jar
├── katalon_generated_rxjava-3.1.8.jar
├── reactive-streams-1.0.4.jar
└── rxjava-3.1.8.jar

1 directory, 10 files

I have a doubt about this list of dependencies. Do we need the extentreport-5.1.1..jar and katalon_generated_extentreports-5.1.1.jar together? It looks duplicating, isn’t it? But for now I wouldn’t mind this point.

If you are going to use Extent Reports in your own Katalon project, you want to copy those jar files into the Drivers folder of your own project.

When you accidentaly removed all those files, you can restore them by invoking a Gradle build:

:~/katalon-workspace/extent-reports-applied-to-katalon-studio-project (master *)
$ rm Drivers/*
:~/katalon-workspace/

$ gradle katalonCopyDependencies
...
BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
:~/katalon-workspace/

$ ls Drivers/
katalon_generated_extentreports-5.1.1.jar
katalon_generated_freemarker-2.3.32.jar
katalon_generated_gson-2.10.1.jar
katalon_generated_lombok-1.18.26.jar
katalon_generated_reactive-streams-1.0.4.jar
katalon_generated_rxjava-3.1.8.jar

If you are interested in how Gradle works in this project, you should study the build.gradle file.

2 Likes

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

To help you faster, please review our guide on Custom Keyword here: Introduction to custom keywords in Katalon Studio | Katalon Docs. 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

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

I admit that the v0.1.0 of my project has an issue to be fixed — you need to insert a lot of call to

CustomKeywords.'com.katalon.extent.report.ExtentReport.attachLog'

See for example extent-reports-applied-to-katalon-studio-project/Scripts/Test/ExtentReport001-Login/Script1714727732025.groovy at 0.1.0 · kazurayam/extent-reports-applied-to-katalon-studio-project · GitHub

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.click(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/a_Make Appointment'))

CustomKeywords.'com.katalon.extent.report.ExtentReport.attachLog'('a_Make Appointment')

CustomKeywords.'com.katalon.extent.report.ExtentReport.addScreenshot'()

WebUI.click(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/span_Demo account_demo_username_label'))

CustomKeywords.'com.katalon.extent.report.ExtentReport.attachLog'('span_Demo account_demo_username_label')

WebUI.setText(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/input_Username_username'), user)

CustomKeywords.'com.katalon.extent.report.ExtentReport.attachLog'('User name : John Doe')

WebUI.setText(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/input_Password_password'), pass)

WebUI.click(findTestObject('OR Web/Page_CURA Healthcare Service/button_Login'))

CustomKeywords.'com.katalon.extent.report.ExtentReport.attachLog'('Login')

I don’t like this. I would rather like the Test Case script to be as follows:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.click(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/a_Make Appointment'))

WebUI.click(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/span_Demo account_demo_username_label'))

WebUI.setText(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/input_Username_username'), user)

WebUI.setText(findTestObject('Object Repository/OR Web/Page_CURA Healthcare Service/input_Password_password'), pass)

WebUI.click(findTestObject('OR Web/Page_CURA Healthcare Service/button_Login'))

In short, I want to keep the Test Case script as usual and still want to print the log messages into the HTML report compiled by Extent Reports.

Is it possible?

Yes, I think I can develop a trick. Let me work out for a while …

2 Likes

I would interimly report my progress applying Extent Reports framework to a Katalon Studio project. I am now investigating how to transfer messages emitted by WebUI.comment(String message) into the HTML report compiled by Extent Reports while keeping my Test Case as usual. I don’t like to make explicit calls to Extent Reports’ API in my Test Case scripts. I want WebUI.comment(String message) to internally emit the message in to the Extent Report. I’ve developed a prototype, which looks promissing. Let me show it here.

I wrote a Test Case as follows:

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

WebUI.comment("Psalm 201 – En vänlig grönskas rika dräkt")
WebUI.comment("")
WebUI.comment("En vänlig grönskas rika dräkt har smyckat dal och ängar.")
WebUI.comment("Nu smeker vindens ljumma fläkt de fagra örtes-ängar;")
WebUI.comment("Och solens ljus och lundens sus och vågens sorl bland viden")
WebUI.comment("förkunna sommartiden.")
WebUI.comment("")
WebUI.comment("Sin lycka och sin sommar-ro de yra fåglar prisa;")
WebUI.comment("Ur skogens snår, ur stilla bo framklingar deras visa.")
WebUI.comment("En hymn går opp med fröjd och hopp från deras glada kväden")
WebUI.comment("från blommorna och träden")
WebUI.comment("")
WebUI.comment("Men Du, o Gud, som gör vår jord så skön i sommarns stunder,")
WebUI.comment("Giv, att jag aktar främst ditt ord och dina nådesunder,")
WebUI.comment("Allt kött är hö, och blomstren dö och tiden allt fördriver")
WebUI.comment("blott Herrens ord förbliver.")
WebUI.comment("")
WebUI.comment("Musik: Waldemar Åhlén")
WebUI.comment("Text: Carl David af Wirsén")
WebUI.comment("quoted from https://1.se/text-psalm-201-en-vanlig-gronskas-rika-drakt-sommarpsalm/")

I executed this and got the following report:

Further development needed yet.

1 Like

See my new experiment also:

I would quit this work. I would not work on Extent Reports & Katalon integration any longer.

1 Like