How can I write values to a CSV file from Katalon Studio

I want to return the time taken to load one page of my site. I have created a calculation which can determine how long it took to get there between steps and now I have the variable of the time taken saved, I can write it in the execution log but I require to be able to append these values to a CSV file.

Is there any way in katalon studio to write variables to a CSV file?

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!

A very recent thread below - any help?

this does not help so much as it can be a good way to return in the log viewer the time taken to load the URL but not so much for the time taken to load all the content on the page.

I would prefer not to use a third party libary and would prefer a way through katalon if it is available

A very basic method to accomplish this:

File file = new File("path\\csvFile.csv")

file.createNewFile()

file.append("${variable}, ${variable}")

As an example this creates a new CSV file at desired location, and then appends variables to cells A1 and B1.

If this is along the way of what you’re looking for…

I do something similar for tracking runtime of test cases and test suites using a Test Listener, and @SetUp and @TearDown on test suites, but using a text/tmp file instead since the timestamp was the only text on the file, its simple to pull from and then delete to clean up.

So, for my example, when the test case starts, I create my temp file and timestamp it, when it completes (once the page is loaded), get the start time from text file, record the current time and determine the runtime with those.

This is how I calculate my runtime, just change the time format to how you have your time variable saved:

public static String getTime() {
		return new Date().format("HH:mm:ss:SSS").toString()
	}

public static String getRuntime(String startTime, String endTime) {
		Date start = Date.parse("HH:mm:ss:SSS", startTime)
		Date end = Date.parse("HH:mm:ss:SSS", endTime)
		TimeDuration duration = TimeCategory.minus(end, start)
		return duration.toString()
	}
startTime = file.getText()
endTime = getTime()
runTime = getRuntime(startTime,endTime)

Unfortunately katalon doesn’t help writing CSV automagically. I think that katalon expects users to write their own code. With or without 3rd party library — they don’t care.

But how? Learn the following article.

In a .classpath file in a Katalon project, I found the following line:

	<classpathentry kind="lib" path="/Applications/Katalon Studio.app/Contents/Eclipse/plugins/net.sf.supercsv.super-csv_2.1.0.jar"/>

This implies that Katalon Studio uses Super CSV library for its own sake (Katalon can write test reports in CSV, you know). Any user can reuse the Super CSV in their own codes . They do not have to explicity import the jar into Katalon project.

Please find a sample code at Is there a way to populate an excel spreadsheet with the elapsed time of a single step - #7 by kazurayam