# Is there a way to populate an excel spreadsheet with the elapsed time of a single step

**URL:** <https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771>\
**Category:** Integrations\
**Tags:** integrations, katalon-studio\
**Created:** [August 21, 2024, 6:56pm UTC](https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771 "2024-08-21T18:56:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephen.middleton](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/stephen.middleton/32/23870_2.png) [@stephen.middleton](https://forum.katalon.com/u/stephen.middleton)\
**Post date:** [August 21, 2024, 6:56pm UTC](https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771/1 "2024-08-21T18:56:40Z")

</div>

I would like to return the values of the elapsed time of a specific step in my test case into an excel file to include on reporting of how long it takes to execute each step.

Is there any commands or plug ins that can return the value of the elapsed time for a specific test step into an excel sheet?

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [August 21, 2024, 6:56pm UTC](https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771/2 "2024-08-21T18:56:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [August 21, 2024, 9:50pm UTC](https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771/4 "2024-08-21T21:50:36Z")

</div>

Here I would show you an example Test Case, which reports how long in seconds it took to launch a browser and navigate to a URL

```auto
import java.time.Duration
import java.time.LocalDateTime

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

String url = 'http://forum.katalon.com/'

// measure the duration
LocalDateTime start = LocalDateTime.now()
WebUI.openBrowser(url)
LocalDateTime end = LocalDateTime.now()
Duration duration = Duration.between(start, end)

// report the duration
int nano = duration.getNano()
String secondsString = String.format("%.2f", nano / 1000000000)
WebUI.comment("it took ${secondsString} second to navigate to $url")

WebUI.closeBrowser()

```

This gave me the following output

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/0/c/0ce496603fea582854d8bc547748d1225336871a.jpeg)

Collecting duration value is as simple as this. Tedious? yes, it is.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [August 22, 2024, 9:42pm UTC](https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771/5 "2024-08-22T21:42:28Z")

</div>

> [@stephen.middleton](#):
>
> Is there any commands or plug ins that can return the value of the elapsed time for a specific test step into an excel sheet?

Katalon Studio does not provide such feature.

I have developed a class library named “Timekeeper” for me to measure the elapsed time in my Katalon projects:

> **[GitHub - kazurayam/timekeeper: Timekeeper is a Java/Groovy library that helps...](https://github.com/kazurayam/timekeeper)**
>
> Timekeeper is a Java/Groovy library that helps tests to compile performance reports in Markdown.

Timekeeper writes a Markdown text in a table format, like this

![this](https://kazurayam.github.io/timekeeper/images/selenium.png)

This library is intended primarily for my own use. But you can use it as is published at [the Maven Central](https://central.sonatype.com/artifact/com.kazurayam/timekeeper).

This library supports saving the report into a CSV file.

Excel (.xls) is not supported. ---- Why? ---- The reason is personal. I am on mac without MS Excel.

---

<div class="post-metadata">

**Author:** ![leishman\_keith](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/leishman_keith/32/22979_2.png) [@leishman\_keith](https://forum.katalon.com/u/leishman_keith)\
**Post date:** [August 28, 2024, 8:50pm UTC](https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771/6 "2024-08-28T20:50:17Z")

</div>

If you want to write to Microsoft Office applications, I.E. Excel, you should invest time in learning Apache POI. I have been learning this to create custom Excel reports using an excel file template.

Example of writing text to a cell in a basic manner…Combine this with @kazurayam method for getting duration via start and end times.

input: String to enter into cell  
myCell : String reference to cell. I.E. A1  
mySheet: name of the Excel sheet.  
myPath: File path to excel file.

Example:

```auto
setCellText("duration","A2", "Template", ".\\Template\\template - Copy.xlsx")

```

```auto
import org.apache.poi.ss.util.CellReference
import org.apache.poi.xssf.usermodel.XSSFSheet
import org.apache.poi.xssf.usermodel.XSSFWorkbook

public static void setCellText(String input, String myCell, String mySheet, String myPath) {
		File file = new File(myPath)
		FileInputStream fis = new FileInputStream (file);
		XSSFWorkbook workbook = new XSSFWorkbook (fis);
		XSSFSheet sheet = workbook.getSheet(mySheet);

		CellReference cellRef = new CellReference(myCell)
		sheet.getRow(cellRef.getRow()).getCell(cellRef.getCol()).setCellValue(input)

		FileOutputStream fos = new FileOutputStream(myPath);
		workbook.write(fos);
		fos.close();
		fis.close();
	}

```

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [August 28, 2024, 11:50pm UTC](https://forum.katalon.com/t/is-there-a-way-to-populate-an-excel-spreadsheet-with-the-elapsed-time-of-a-single-step/142771/7 "2024-08-28T23:50:48Z")

</div>

I found that Katalon Studio bundles [Super CSV](https://super-csv.github.io/super-csv/index.html)  
See [How can I write values to a CSV file from Katalon Studio - #8 by kazurayam](http://forum.katalon.com/t/how-can-i-write-values-to-a-csv-file-from-katalon-studio/143788/8)  
I made a sample Test Case that utilized Super CSV

“Test Cases/TCx”

```auto
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.time.Duration
import java.time.LocalDateTime

import org.supercsv.io.CsvListWriter
import org.supercsv.prefs.CsvPreference

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

LocalDateTime start = LocalDateTime.now()
WebUI.callTestCase(findTestCase("Test Cases/TC1"), [:]) // TC1 takes a few seconds to finish
LocalDateTime end = LocalDateTime.now()
Duration duration = Duration.between(start, end)

// report the duration
int nano = duration.getNano()
String secondsString = String.format("%.2f", nano / 1000000000)

Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path csvFile = projectDir.resolve("output.csv")

Writer writer = Files.newBufferedWriter(csvFile)
CsvListWriter clw = new CsvListWriter(writer, CsvPreference.EXCEL_PREFERENCE)

clw.write(Arrays.asList("memo","duration"))
clw.write(["calling \"TC1\" took", secondsString])

clw.flush()
clw.close()

```

output.csv

```auto
memo,duration
"calling ""TC1"" took",0.71

```
