Sample usage of BrowserMob Proxy in Katalon Studio

I have published a GitHub project

Background

In the Katalon User Forum, there is a Frequently Asked Question.

I want to do a Web UI test using browsers and at the same time I want to save the payload of HTTP requests and responses into a file. How can I do it?

Katalon Studio v8.5.x does not support recording the payload of HTTP messages exchanged between a web browser and HTTP servers. You need to employ additional technologies. The following post by matteo.lauria at Feb '21 suggested BrowserMob Proxy for this purpose.

BrowserMob Proxy will enable us to make a HAR file which contains all HTTP requests and responses recorded during tests in Katalon Studio. The HTTP messages will be formated in JSON.

The post suggested the way how to make use of BrowserMob Proxy in Katalon Studio. Unfortunately the presented sample codes were not complete (e.g, the import statements were trimmed off), so it was a bit difficult to reuse on your machine.

What’s this

Here I would show you a runnable Katalon Studio project empowered by BrowserMob Proxy which makes a HAR file that contain HTTP messages exchanged by browser and HTTP servers.

sequence

You can download the zip of the project from the Releases page. You want to download the zip; unzip it; open the project with your local Katalon Studio; run the “Test Suite/TS1”; when it finished you will find sample.har file is created in the project folder.

How to view

The sample.har file will be a very large JSON text file. It is difficult to see it and grasp overall in a text editor. You would need a tailored viewer for HAR file. I use Visual Studio Code with HAR Viewer plugin installed. The following image shows an example:

VSCode HAR Viewer

Hope this helps.

1 Like

@kazurayam I like it.
Note that, you have some typo (altough the code works, is still a typo)

	@Keyword
	def initProxy() {
        BrowserMobProxyServer initPorxy = new BrowserMobProxyServer()
-----
		return [
			initPorxy, 
----
	}

The startProxy and stopProxy functionality can be moved in a Test Listener, for the rest looks nice.

To view HAR files, there are also some online tools available, where you can analyze them like in DevTools networking tab, e.g:

https://toolbox.googleapps.com/apps/har_analyzer/

http://www.softwareishard.com/har/viewer/

Or you can import the HAR file straight in your browser:

@kazurayam
Side note, browsermob-core-2.15 is already provided in Katalon
(I think it is used to intercept API calls with webservice projects)
so the .jar in your Drivers folder is redundant.
See the classpath file:

Katalon_Studio_Linux_64-8.5.0/configuration/resources/lib/browsermob-core-2.1.5.jar