How to get the request payload from recorded Katalon test case

I used Katalon Studio’s Record Web tool to record a a series of clicks on a website, it includes some POST request. I have a lot of pages and want to get the request payload content for each page, so I would like to use Katalon to record the steps for each page and get the request payload for each page. I clicked the script tab of the recorded test case and here is a sample of the script:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.verification.WSResponseManager

WebUI.setText(findTestObject(‘Object Repository/Page_Login/input_Username_username’), ‘username’)
WebUI.setEncryptedText(findTestObject(‘Object Repository/Page_Login/input_Password_password’),
‘some password’)‘Object Repository/Page_Login/div_LOG IN’))‘Object Repository/Page_Settings/span_User Profile’))
WebUI.doubleClick(findTestObject(‘Object Repository/Page_Settings/input_Update Interval every’))‘Object Repository/Page_Settings/button_Accept’))
RequestObject request = WSResponseManager.getInstance().getCurrentRequest()

I added these to try to print out the request object but I got null in the console.
RequestObject request = WSResponseManager.getInstance().getCurrentRequest()

Any idea how I can get the request payload?

Hi @hewin9, Try doing a Google search for “Katalon api video”, for example: katalon api video - Google Search

You have a misunderstanding. WebUI.* keywords and RequestObject has nothing to do with each other.

See my post:

Your requirement will be met quite easily if you choose Chrome Devtools Protocol-based test tools, for example Playwright: See their doc

You can monitor all the Requests and Responses:

const { chromium, webkit, firefox } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();

  // Subscribe to 'request' and 'response' events.
  page.on('request', request =>
      console.log('>>', request.method(), request.url()));
  page.on('response', response =>
      console.log('<<', response.status(), response.url()));
  await page.goto('');

  await browser.close();

The Playwright speaks to Chrome browser via Chrome DevTools Protocol, not via W3 WebDriver protocol. Due to the difference in the protocol’s scope & capabilities, CDP-based software is capable of some featueres that Selenium3 WebDriver-based software will never be.

You may want to look at Playwright. They provide codegen, which is a record & playback tool.

Thanks for the help. The BrowserMob Proxy works like a charm. The generated har file is quite large but I am ok with it. Is there a way to just write the POST request or GET request to har file?

Thank you @kazurayam for the Playwright solution. It also works but Katalon is better at capturing the web elements than Playwright.

jq command is well-known and heavily used in the open source world to process JSON in general

for mac and linux

for windows

You can write a Groovy Script (Test Case) that call jq as os command:

Yes, I can use other script to parse the json result. But if the BrowserMob Proxy can filter the POST and GET reuqest then the har file will be smaller for later process.

I don’t know.
Please study yourself.
If you could find how to, please share it for the others.

Ok, thanks @kazurayam

I think that Playwright is good in capturing the web elements as well; as good as KS, but in completely different syntax. You have to write test in JavaScript/TypesScript in Playwright.

I would prefer JavaScript’s "(async () => {await ...})()" syntax to WebDriver’s "new WebDriverWait(driver, timeout).until(condition)" instruction in Java.