How to handle 500 Internal Server Error?

Dear Community,

I have to entry a lot data in a web form on regular basis. That data I used to entry is in the following manner:

What is used to be done here is basically at first specific ExpNo and it’s corresponding Year are being searched. If its found then a those required fields such BillNo, BillDate & Remarks will come up where required data are inputted from an excel sheet. Katalon studio is doing it for me more than 1 year and I am really gratitude to the developers for making our life easy.
But the problem is running the test case an common error named “500 Internal Server Error” in the web browser I am tired of facing in every single though it’s caused from website owner’s end. So is there any way that katalon can handle it by refreshing the page and starting again from the last ExpNo when the error occurred.

Your help in this regard will be highly appreciated!

In short, yes, failed connections can be trapped and retried. However, to advise you further we will need to see the Test Case code you are using and the line of code that suffers from the HTTP 500 error.

An ‘500 HTTP blah’ error it is most of the time generated by an unhandled error in the AUT.
So, until you figure out what is wrong with your testing code (definetly you have a booboo there), you can also dig into the AUT and submit a bug report to your developers.

On the server, not the client.

Dear Russ_Thomas! Thanks for your response. Here is my Test Case Code:

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




WebUI.setText(findTestObject(‘Object Repository/Page_Login/input_Username_p_t02’), ‘username’)

WebUI.setEncryptedText(findTestObject(‘Object Repository/Page_Login/input_Password_p_t03’), ‘hkpG+J/pUNTi4tt/1sPD7g==’)‘Object Repository/Page_Login/a_Login’))‘Object Repository/Page_Welcome/a_Transaction’))‘Object Repository/Page_Exp Transaction/a_EXP Correction (Any Time) Specific Data o_7f0ca5’))

for (def row = 1; row <= findTestData(‘ExportBillInput’).getRowNumbers(); row++) {
WebUI.setText(findTestObject(‘Page_EXP Correction (Some field All time open)/input_Exp Serial_p_t04’), findTestData(
‘ExportBillInput’).getValue(‘Exp’, row))

WebUI.selectOptionByValue(findTestObject('Page_EXP Correction (Some field All time open)/select_202020192018201720162015201420132012_b0c8c4'), 
    findTestData('ExportBillInput').getValue('ExpYear', row), true)'Page_EXP Correction (Some field All time open)/a_Search'))

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/input_Bank Bill No_p_t38'), 
    findTestData('ExportBillInput').getValue('BillNumber', row), FailureHandling.CONTINUE_ON_FAILURE)

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/input_Bank Bill Date (DD-MON-YY)_p_t39'), 
    findTestData('ExportBillInput').getValue('BillDate', row))

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/textarea_Remarks_p_t40'), 

WebUI.setText(findTestObject('Object Repository/Page_EXP Correction (Some field All time open)/textarea_Remarks_p_t40'), 
    'Bank Bill Number & Date Included')'Object Repository/Page_EXP Correction (Some field All time open)/a_Apply Changes'))



For example:

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.util.KeywordUtil

TestObject tObj = new TestObject("500ErrorText")
tObj.addProperty("xpath", ConditionType.EQUALS, "//*[contains(. 'Internal Server Error')]")

boolean errorFound = WebUI.verifyElementPresent(tObj, 10)

if (errorFound) {
    KeywordUtil.markFailedAndStop("Internal Server Error")
} else {
    // normal
    // your existing codes come here
    WebUI.setText(findTestObject(‘Object Repository/Page_Login/input_Username_p_t02’), ‘username’)

The above code examines if the responded page shows a text ‘Internal Server Error’ somewhere in the page. If the text is found, react to it somehow and quit soon. If not found, you should have got a normal web form page; go on as usual.

1 Like

From my understanding, he got this error when submitting a certain set of data from hist test data through a given form.
So, i suppose for that specific set, the frontend sends a certain request to a certain server and the server replies with 500 (and the browser displays this …)

By AUT i consider the entire application (frontend + backend), not only the web page.
So the issue is in the AUT :stuck_out_tongue:

Where to handle the 500 error is at the developer disposal, server side or on the page. However it is still an unhandled error.

Now I should go back to the original post by @shadbhowmik7

He want to retry X times until

  1. X times of “Internal Server Error”, or
  2. a successful data submit

Well, I believe, this requirement it is quite possible to program. But it is complexed enough.

@shadbhowmik7 it is happening every time at the same iteration (same row in the dataset) or randomly?
If it is the first case you may have to look a bit in depth to see if the data you try to sumbit it is valid.

If is random, could be that by doing data driven test you put a bit too much pressure on the backend.
However, in both cases you may need to take a deeper look on what is actually happening and perhaps have a chat with the developers.
Without access to your application I am afraid we cannot help you much.

Hey @bionel thanks for your response!

It’s happening randomly. Yeah I can show you and give you access to the website through Ultraviewer!

Hello @ kazurayam I can provide you and show you through ultraviewer.

@ kazurayam
I need your help to understand the followings:
xpath = Here I will have to input the xpath of Internal Server error.
WebUI.verifyElementPresent(tObj, 10) = Would you please tell me what you meant by (tObj, 10)?
I’m just a beginner so don’t have much knowledge about it?

TestObject tObj = new TestObject("500ErrorText")
tObj.addProperty("xpath", ConditionType.EQUALS, "//*[contains(. 'Internal Server Error')]")
boolean errorFound = WebUI.verifyElementPresent(tObj, 10)

Sorry, I can not make the above 3 lines clearer.

If you do not understand this code, possibly you need to learn Java/Groovy programming from the very basic. I personally started learning Java programming with Core Java book decades ago.

Hi @kazurayam,

TestObject tObj = new TestObject(“500ErrorText”) → define one test object called "tObj "
tObj.addProperty(“xpath”, ConditionType.EQUALS, “//*[contains(. ‘Internal Server Error’)]”) → set xPath for this object

(Those 2 steps can be manually created via Katalon Tool using Manual Mode):

  • Create one test object
  • Double click on object
  • Go to xpath tab and set value for it

And last one: WebUI.verifyElementPresent(tObj, 10) → this line will check tObj present in the page with timeOut 10 second, return true if found and false if not found.



Thank you for your comment.

I just wanted to avoid using “Object Repository”. I wanted to show everything in a TestCase code including how to create a TestObject. This is easier for me than operating Katalon Tools.

1 Like

Here I show a sample Test Case script. You can copy&paste this in your Katalon Studio project, and just run it to see.

import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

def url = ''
def isReady

// First attempt. This will pass
isReady = navigateToUrlWithRetry(url, '//h2[contains(., \'Login\')]')

if (isReady) {
    WebUI.comment('Login form is ready! You can proceed.') // enter username
    // enter password
    // click button
    // ...
} else {
    KeywordUtil.markFailed('Failed to load the Login form after retry')

// Second attempt. This will fail
isReady = navigateToUrlWithRetry(url, '//h2[contains(., \'Make Appointment\')]', 2, 3)

if (isReady) {
    WebUI.comment('Login form is ready! You can proceed.')
} else {
    KeywordUtil.markFailed('Failed to load the Login form after retry')


 * try to navigate to the url,
 * verify if we successfully navigated to the Url by trying to find a element that matches to the SuccessCriteria
 * if the pages is found not what is expected, will retry Times with given Interval seconds 
 * @param url
 * @param interval
 * @param times
 * @param successCriteria
 * @return
def navigateToUrlWithRetry(String url, String successCriteria, Integer times = 5, Integer interval = 10) {
    TestObject tObj = new TestObject('successCriteria')
    tObj.addProperty('xpath', ConditionType.EQUALS, successCriteria)
    for (int i = 0; i < times; i++) {
        if (WebUI.verifyElementPresent(tObj, interval, FailureHandling.OPTIONAL)) {
            return true
	return false

This sample presents a Groovy function named

  • navigateToUrlWithRetry(url, interval, times, xpath)

It is similar to the Katalon built-in keyword WebUI.navigateToUrl() but slightly enhance it.

  1. You can pass an XPath expression as the criteria to check if the loaded web page is what you expected.
  2. If the loaded page was what you had expected, then the function immediately returns true
  3. If the loaded page was not what you had expected (e.g, the page showed “500 Internal Server Error”), then the function will retry n times opening the URL. The function puts interval seconds between tries.
  4. After retries expired and was unable to load what you expected, the function will return false.
  5. you can specify the interval seconds, default to 10 secs
  6. you can specify the number of tries, default to 5


I hope this sample code shows enough information for you to develop a solution.

1 Like

Hi Thanks for your response again.
I want to make it clear that, Internal Server Error doesn’t appear when i try to log in the web page. It occurs sometimes at the time of updating data (data entry).

Internal sever error may appear at the time of entering any of following data such as:
Or Clicking on Update Button

Suppose katalon has completed till Remarks and
When it goes to click the submit button then Internal Server Error Appears. If I just refresh the web page or click on webui back button manually then katalon will skip that ExpNo without updating it’s information to the next ExpNo.

It would be enough for me if Katalon just can detect the internal server error while it’s occurred and start again from the last ExpNo or the ExpNo of last Exp can also be okay.

This is a question of testing philosophy. I don’t know what yours is, or what you’re expected to provide by your employer, but here’s mine:

  1. The application should work correctly.
  2. Tests should try to prove the application is working correctly or is broken.
  3. Tests should not try to dance around broken applications in order to make them pass.

It’s clear your application is broken - an HTTP 500 is BAD. You appear to be trying to workaround point #3. You should trap the error, fail the test and report the error in the normal manner.

I think i read that before, don’t remember where…
Sorry @Russ_Thomas, cannot hold it :slight_smile:

System is but a walking broomstick :broom: . You need to tell it how to dance :dancer:.