Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<commons-lang3.version>3.20.0</commons-lang3.version>
<extentreports-cucumber7-adapter.version>1.14.0</extentreports-cucumber7-adapter.version>
<mysql-connector-j.version>9.5.0</mysql-connector-j.version>
<opencsv.version>5.9</opencsv.version>

<!-- Suite XML path -->
<suite.feature>src/test/resources/suites/SuiteFeatureByTag.xml</suite.feature>
Expand Down Expand Up @@ -317,6 +318,13 @@
<version>${aspectjweaver.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
</dependency>

</dependencies>

<!-- This profile execute the TestNG suite inside the suites folder on test/resources/suites -->
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/anhtester/helpers/CsvHelpers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Anh Tester
* Automation Framework Selenium
*/

package com.anhtester.helpers;

import com.anhtester.utils.LogUtils;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvException;

import java.io.FileReader;
import java.io.IOException;
import java.util.List;

public class CsvHelpers {

/**
* Reads all data from a CSV file.
*
* @param csvFilePath the path to the CSV file.
* @return a 2D String array containing the CSV data, or null if an error occurs.
*/
public static String[][] readCsvData(String csvFilePath) {
try (CSVReader reader = new CSVReader(new FileReader(csvFilePath))) {
List<String[]> allRows = reader.readAll();
return allRows.toArray(new String[0][]);
} catch (IOException | CsvException e) {
LogUtils.error("Failed to read CSV file: " + e.getMessage());
return new String[0][];
}
}

}
Loading
Loading