[WS] Verify Response Status Code


This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/ws-verify-response-status-code.html

I have an automation scenario to validate network/api responses based on the action performed in UI

Example Flow:

  1. I click an element using UI tests in Katalon
  2. Based on the click, there are some network/api calls
  3. I need to capture the response codes and validate for any failures.

Can anyone guide on this. Your help is much appreciated

As long as your test script communicates with browsers via Selenium WebDriver interface, you can not do it. WebDriver interface does not tell you how the browser communicated with the HTTP servers. I mean, there is no “WebUI.*” keyword that tells you the HTTP Status code of the HTTP response from the server to browser.

However, if your test script communicates with Chrome browser via “Chrome DevTools Protocol” (CDP for short), you can do it.

CDP does tell you how the browser communicated with the upstream HTTP servers. I have ever implemented a sample in Katalon Studio. See the following:

These 2 scripts have a similar code fragment :

responses.each { resp ->
	if (resp != null && (200 <= resp.getStatus() && resp.getStatus() < 300)) {
            ....

This code is looking at the HTTP Status of HTTP Response from the server to browser, and Chrome browser informed it to the test script via CDP.

Thank you @kazurayam , that really opened a new perspective. Appreciate your help.