ErrorCollector.getCollector().getCoppiedErrors().get(index)` Returning Null Outside Test Case Execution

Dear Katalon Support Team,

I am encountering an issue with the ErrorCollector.getCollector().getCoppiedErrors().get(index) function in Katalon Studio. When I execute this function outside of a test case, it returns null, regardless of the index provided. However, when executed inside a test case, the function works as expected and provides errors based on the index.

I intended to use this function to retrieve all failures that I have captured and include them in a report outside of Katalon’s default reporting system. This approach was suggested due to an earlier defect I reported here, where Katalon suggested that an enterprise subscription would be necessary for support. However, this is a defect rather than a feature request, and I believe it should be addressed through community support.

The issue is critical for my reporting needs, and the current workaround does not resolve the problem effectively.

Steps to Reproduce:

  1. Use the function ErrorCollector.getCollector().getCoppiedErrors().get(index) outside of any test case.
  2. Observe that it returns null.
  3. Use the same function inside a test case.
  4. Observe that it works correctly and returns errors based on the index.

Expected Result:

The function should return errors as expected, whether executed inside or outside of a test case, allowing me to utilize it for comprehensive reporting.

Actual Result:

The function returns null when executed outside of a test case, hindering the intended use for reporting purposes.

Additional Information:

  • Katalon Studio Version: 9.0.0
  • OS: Windows 10

I would appreciate your assistance in resolving this issue as it impacts my ability to generate detailed reports. If any additional information or steps are needed, please let me know.

Thank you for your support.

1 Like

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

Hi @osamazaza200,

Thank you for letting us know. I will create a ticket for your issue and let you know soon if any udpate

Dear @Elly_Tran is there any update ?

Then, inside a test case, how about copying the errors contained in the ErrorCollector to a GlobalVariable? Once you have copied the list of errors into a GlobalVariable, your reporting system can consume the GlobalVariable later as it wants to.

Let me show you an example.

I made a GlobalVariable “ERRORS” of type null in the default Profile:

I made a Test Case, which emits 3 Errors

import com.kms.katalon.core.logging.ErrorCollector
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable

TestObject makeTestObject(String id, String xpath) {
	TestObject tObj = new TestObject(id)
	tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
	return tObj	
}

WebUI.openBrowser('')
WebUI.navigateToUrl("http://demoaut.katalon.com")
WebUI.verifyElementPresent(makeTestObject("foo","//div[@id='foo']"), 3, FailureHandling.CONTINUE_ON_FAILURE)
WebUI.verifyElementPresent(makeTestObject("bar","//div[@id='bar']"), 3, FailureHandling.CONTINUE_ON_FAILURE)
WebUI.verifyElementPresent(makeTestObject("baz","//div[@id='baz']"), 3, FailureHandling.CONTINUE_ON_FAILURE)
WebUI.closeBrowser()

ErrorCollector ec = ErrorCollector.getCollector()
List<Throwable> errors = ec.getCoppiedErrors();
GlobalVariable.ERRORS = errors;

and a Test Listener:

import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.context.TestCaseContext

import internal.GlobalVariable

class TL {
	
	@AfterTestCase
	def afterTestCase(TestCaseContext testCaseContext) {	
		List<Throwable> errors = GlobalVariable.ERRORS
		println "errors.size()=" + errors.size();
		errors.forEach({t ->
			println t.getMessage()
		})
	}
}

When I ran the Test Case, I got the following output in the console:

errors.size()=3
com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'foo' located by '//div[@id='foo']' not found (Root cause: com.kms.katalon.core.exception.StepFailedException: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'foo' located by '//div[@id='foo']' not found
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
...

This proves that the Test Listener could see 3 Exceptions thrown by the Test Case.