When is the report file created?

I’m trying to read the test report inside of my TearDown method:

@TearDown(skipped = false) 
def tearDown() {
if (GlobalVariable.testSuiteStatus=='FAILED'){
String batchFile = RunConfiguration.getProjectDir() + '/' + 'emailReport.bat'
Process p = Runtime.getRuntime().exec(batchFile)
def reportFolder = RunConfiguration.getReportFolder()
println reportFolder
File file = new File(reportFolder+'/JUnit_Report.xml')
println lines[1]

But I get java.io.FileNotFoundException. After the test finishes, the file is present in /Reports folder. My guess is that the file is not yet created before the test finishes.

Is there a workaround for this?

I believe that a Report is generated after a Test Suite has been completely finished. You can not find the Report file in the @TearDown of a Test Suite nor in the @AfterTestSuite method in a Test Listener. The visualized workflow in https://docs.katalon.com/pages/viewpage.action?pageId=5126383 explains this.

If you want to read the Report of a Test Suite A, you need to create another Test Suite B in which a test case reads the Report of A. In the end you create a Test Suite Collection which binds the 2 Test Suites and execute A and B sequentially. This is the way I tried and found operational.

That’s what I was thinking. I’ll try that, thanks!

But there must be another way to get the info from JUnit_Report.xml? I would like to be able to parse this line .

But there must be another way to get the info from JUnit_Report.xml?

What do you mean “another way” ?

JUnit_Report.xml will be generated after a Test Suite A has completed. — Or it is likely that the JUnit_Report.xml is once written in some temporary directory and moved into the /Reports/testsuitename/timestamp directory after the Test Suite A has completed.

Once the Reports/testsuitename/timestamp/JUnit_Report.xml is placed, you can read the file to instantiate a org.xml.dom.Document, and process a DOM object using javax.xml.XPath. I have ever coded such stuff.

What I meant by “another way” was: Katalon creates the JUnit_Report, so it has access to data such as ‘test case name’, ‘test suite name’, ‘test case status’… I can get some of them using RunConfiguration class.

So I was thinking, maybe there is a class that does that for ‘number of tests’, ‘number of failures’, ‘number of errors’… the stuff written in the .xml file.

I can get some of them using RunConfiguration class

Well, I have ever checked the API document of RunConfiguration (https://api-docs.katalon.com/com/kms/katalon/core/configuration/RunConfiguration.html), and debug-printed most of the properties of a RunConfiguration object. I did not find data such as ‘test case name’, ‘test suite name’, ‘test case status’ stored there.

I guess that Katalon Studio internally transforms its test cases/test suites into JUnit-based tests and runs them with its custom JUnit test runner. I think that reading JUnit_Report.xml is the best reliable method for us to get access to “test case status” sort of thing.

Workflow is off: http://forum.katalon.com/discussion/9432/teardown-method-runs-before-listener?new=1