Adding entries to an open Excel spreadsheet during runtime
When running the API test for several thousand entries, I noted that matching up an invalid request with the correct source data could be a needle in the haystack affair. Instead, it would be better to record any errors right alongside the source data in the XLSX spreadsheet file. That can be done by writing to a new cell during runtime.
The process is only a couple of additional lines of code.
To start, a new file needs to be opened using:
FileOutputStream outFile = new FileOutputStream(new File("//Postman Testing//Data Files//pricing.xlsx")
Data can then be written to the sheet using,
.createCell(5) refers to column 5 in the spreadsheet. I'm using columns 0-4 for source data.
sheet.getRow(loop).createCell(5).setCellValue("ERROR: Failure Message on pricing request " + loop + " " + failure_message)
At the end, all data needs to be written to the workbook:
And like other files, it needs to be closed when finished:
During runtime, if an error is encountered, it is written inline with the source data. When the
pricing.xlsx file is opened, the error message and data used to replicate the error is all in one place.
Other articles of interest:
- Data Driven API Testing with Katalon using Spreadsheet Data
- Determine if a Spreadsheet Cell contains Numeric or Text data
- Connecting Katalon Studio into XLS and CSV files
- Programmatic Database query with Katalon
- Checking for Page Load with a Custom Keyword
- Output status messages and test information by writing to the Log File Viewer in Katalon Studio
- Wait For Alert, Verify Alert Present in Katalon Studio
- Creating 3rd party file formats from inside DevonThink
- Reviewing the Execution Logs of Katalon Studio
- Index Your Files is Refreshingly Good