How to extract and write data in a test case with Katalon Recorder
When testing a website with Katalon Recorder, you might want to extract data from the website and store the data in an external file. Katalon Recorder facilitates this process of extracting and writing data with several commands.
This tutorial shows you how to use Katalon Recorder to extract data from a website and write the data to a CSV file.
- To use the sample project of this tutorial, navigate toActions > Sample Projects, then add the Extract and write data to a CSV fileproject.
Test case scenario
In our example, we follow the scenario "extract and write product information to a file", which consists of these steps:
- Navigate to the application under test (AUT) - the Katalon Zack Market page:
https://demo-store.katalon.com/
. - Select a shopping item.
- On the item page, get the name and price of the selected item.
- Write the name and price information to a CSV file.
The item page displays the item with name and price as follows:
We can use Katalon Recorder to first extract and store the item name and price. Then with the appendToCSV
command, we can append the extracted data to a CSV file.
Prepare a CSV file
As Katalon Recorder navigates using column names in a CSV file, we need to create a CSV file with specific column names for data extraction. In our case, we need two columns for name and price.
Add the CSV file to the workspace
Follow these steps:
-
Open Katalon Recorder. In the Workspace sidebar, click on Open a Data File in the Test Data section.
-
In the displayed file explorer, select the CSV file.
The added CSV file is displayed under the Test Data section.
Extract and write the data
After adding the CSV file to the workspace, we create a test case that navigates to the shopping item page, then extracts and writes item information to the CSV file.
Follow these steps:
-
In Katalon Recorder, create a test suite, then create a test case inside that test suite. Click Record to start recording.
-
In an active browser tab, navigate to the AUT - Katalon Zack Market:
https://demo-store.katalon.com
.
-
Click on a shopping item.
-
Get the item name and price.
While recording a test case, you can manually add a test step for an element by right-clicking on it.
To get item name, right-click on the name text and select Katalon Recorder > storeText.
Katalon Recorder then asks you to enter the variable name that stores the name text. Here, we name the variable
itemName
.
To get the item price, right-click on the price text and select Katalon Recorder > storeText.
Here, we name the variable for the price text
itemPrice
.
-
Click Stop to stop the test recording.
-
Write the name and price to the CSV file.
In the test case recorded, we add another test step and use the
appendToCSV
command to write the name and price to the added CSV file.
Command Target Value appendToCSV
name-price.csv
${itemName}, ${itemPrice}
The Target here is the name of the added CSV file.
In the Value field, we specify the values to write to the CSV file:
${itemName}
and${itemPrice}
. The placeholder syntax${variable_name}
here expands a variable into its value. As a result, when Katalon Recorder runs theappendToCSV
command, it writes the name and price values to the next empty row of thename-price.csv
file. -
Play the test case until it finishes and download the CSV file.
-
Open the downloaded CSV file and verify the results.
The downloaded CSV file should display the extracted item name and price.
- As a browser extension, Katalon Recorder cannot write data directly to the user file system; the extension only writes to the version of the data file that is added to the workspace. Therefore, you need to download the data file again to view the extracted data.