Intercepting request with Chrome Devtools Protocol

Sample project used in this topic: GitHub - katalon-studio-samples/katalon-studio-chrome-devtools-protocol-plugin-samples

The topic covers how to use Chrome Devtools Protocol (CDP) in Katalon Studio to intercept HTTP requests. Please note that this sample requires the plugin Chrome DevTools Protocol Integration.
This example will show you how to mock search requests in Wikipedia website so that the result will always be “Katalon Studio”. You can find the following code in the sample project (Intercept request test case).

Setup CDP


ChromeDevToolsService cdts = CdpUtils.getService()

Page page = cdts.getPage()

Fetch fetch = cdts.getFetch()

Intercepting request

fetch.onRequestPaused({def requestIntercepted -> 

    String interceptionId = requestIntercepted.getRequestId()
	boolean isMocked = requestIntercepted.getRequest().getUrl().contains('api.php')
	String response = '["Katalon Studio",["Katalon Studio"],["Katalon Studio is an automation testing solution developed by Katalon LLC."],[""]]'
	String rawResponse = Base64.encode(response)
	System.out.printf('%s - %s%s', isMocked ? 'MOCKED' : 'CONTINUE', requestIntercepted.getRequest().getUrl(), System.lineSeparator())
		fetch.fulfillRequest(interceptionId, 200, new ArrayList(), rawResponse, null)
	    else {

Enable CDP components



Selenium scripts

After setup with CDP, we can navigate, set text, click test object with Katalon as usual. Every request that matches our mocking conditions will return predefined responses. Here we search for “Intercept request” and the result show “Katalon Studio”.


WebUI.setText(findTestObject('Page_Wikipedia the free encyclopedia/Search input'), 
    'Intercept request')

WebUI.waitForElementVisible(findTestObject('Page_Wikipedia the free encyclopedia/Select Katalon'), 10)'Page_Wikipedia the free encyclopedia/Select Katalon'))


The plugin uses GitHub - kklisura/chrome-devtools-java-client: Chrome DevTools java client. to connect to CDP. Please see the library’s repository for more examples.