Data Reader

A utility to read test data from excel and csv and write data as needed

License

License

Categories

Categories

Data
GroupId

GroupId

dev.spiti.utilities
ArtifactId

ArtifactId

data-reader
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Data Reader
A utility to read test data from excel and csv and write data as needed
Project URL

Project URL

https://github.com/spiti-dev/data-reader
Source Code Management

Source Code Management

https://github.com/spiti-dev/data-reader

Download data-reader

How to add to project

<!-- https://jarcasting.com/artifacts/dev.spiti.utilities/data-reader/ -->
<dependency>
    <groupId>dev.spiti.utilities</groupId>
    <artifactId>data-reader</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/dev.spiti.utilities/data-reader/
implementation 'dev.spiti.utilities:data-reader:1.0.0'
// https://jarcasting.com/artifacts/dev.spiti.utilities/data-reader/
implementation ("dev.spiti.utilities:data-reader:1.0.0")
'dev.spiti.utilities:data-reader:jar:1.0.0'
<dependency org="dev.spiti.utilities" name="data-reader" rev="1.0.0">
  <artifact name="data-reader" type="jar" />
</dependency>
@Grapes(
@Grab(group='dev.spiti.utilities', module='data-reader', version='1.0.0')
)
libraryDependencies += "dev.spiti.utilities" % "data-reader" % "1.0.0"
[dev.spiti.utilities/data-reader "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.apache.poi : poi-ooxml jar 3.16

runtime (2)

Group / Artifact Type Version
com.opencsv : opencsv jar 4.1
log4j : log4j jar 1.2.17

Project Modules

There are no modules declared in this project.

Data Reader - Simple way to read from and write to XLSX and CSV files

Contents

Key Features

  • Reads .xlsx and .csv files
  • Creates .xlsx and .csv files
  • Returns data as a an array of <Map<String, String> where key is column name and value is cell value
  • Filters data for a specific value from a given column, before returning
  • Add header and rows from ArrayList<String>

Usages

  • Integrate into TESTNG and other automation frameworks
  • Use in @DataProvider methods to read data and stream to @Test methods as Object[]
  • Create test report files and add results after every test

Limitations

  • Creates and adds data to XLSX FILES ONLY
  • Defaults to read files from src/test/resources/ directory
  • Empty row is considered as Enf of File

Examples

Read XLSX files

Object[] data = new Excel("DataFile", "Sheet1").getData();
  • Reads data from sheet Sheet1 from file src/test/resources/DataFile.xlsx
  • Streams entire sheet as Object[]
  • Each row is one object of Map<String, String>
  • Key is column name and Value is cell value from the row
Object[] data = new Excel("DataFile", "Sheet1").getData("testType", "Regression");
  • Accepts column name and cell value as parameters to filter data
  • Filters and returns data that has cell value Regression on column testType

Read CSV files

Object[] data = new CSV("DataFile").getData();
  • Reads data from file src/test/resources/DataFile.csv
  • Streams entire sheet as Object[]
  • Each row is one object of Map<String, String>
  • Key is column name and Value is cell value from the row
Object[] data = new CSV("DataFile").getData("testType", "Regression");
  • Accepts column name and cell value as parameters to filter data
  • Filters and returns data that has cell value Regression on column testType

Create and write to XLSX files

String fileInPath = new Excel().createFile("thisFile");
  • Creates src/test/resources/results/thisFile_<timestamp>.xlsx
  • Returns src/test/resources/results/thisFile_<timestamp>.xlsx
  • timestamp is in yyyyMMddHHmm format
new Excel().writeHeader(new Excel().createFile("thisFile"),"Sheet1", headerList);
  • Creates Sheet1 on file src/test/resources/results/thisFile_<timestamp>.xlsx
  • headerList is List. First row is created with strings as in the order from the list
new Excel().writeRow(new Excel().createFile("thisFile"),"Sheet1", rowList);
  • Reads Sheet1 on file src/test/resources/results/thisFile_<timestamp>.xlsx
  • rowList is an ArrayList
  • Adds data from rowList in the row after the last row in file

Integration to TESTNG

Read from XLSX files

@DataProvider
public Object[] dataFromExcel() {
  return new Excel("DataFile", "Sheet1").getData("testType", "Regression");
}

@Test (dataProvider = "dataFromExcel")
public void readFromExce(Map<String, String> testdata) {
  // Data from excel is available here for test
}

Read from CSV files

@DataProvider
public Object[] dataFromCsv() {
  return new CSV("DataFile").getData("testType", "Regression");
}

@Test (dataProvider = "dataFromCsv")
public void readFromCsv(Map<String, String> testdata) {
  // Data from excel is available here for test
}

Versions

Version
1.0.0