How to verify entries in Exported CSV file in Selenium

Tram Ho

In this article, we will look to verify the CSV Export function. This export function is exporting a document or downloading a document with the number of records or data to verify. Usually the exported document will be in the form of a csv file. We will now read the csv file with the help of Java FileReader and LineNumberReader

Export button will be set to export the records / data to the local system from the application. If you look at the image below, you will see the different options for exporting available data in the table.

We need to follow the steps below to verify the CSV export function

Step 1 : – First take the number of items the table has.

Step 2 : – Click the Export button (CSV in the example case below).

Step 3 : – Download the document to a specific folder or the default download folder.

Step 4 : – Read csv file and get the number of items in Csv (Need to exclude titles when comparing items)

Step 5 : – Compare items in table and number of items in csv file.

Take a look at the example below:

The method below is used to get the number of items in the table as shown in the image above.

Here’s the method to read the CSV file and get the number of items contained in the exported csv file. It takes the file name as a parameter

The method below is used to get the latest file from the directory. It takes the directory path as a parameter and returns the recently added file to the directory.

Hope this article will help you!

Reference link:

Share the news now

Source : Viblo