CSV Plugin

The plugin provides the ability to work with CSV files.

Installation

  1. Copy the below line to dependencies section of the project build.gradle file

    Please make sure to use the same version for all VIVIDUS dependencies.
    Example 1. build.gradle
    implementation(group: 'org.vividus', name: 'vividus-plugin-csv')
  2. If the project was imported to the IDE before adding new dependency, re-generate the configuration files for the used IDE and then refresh the project in the used IDE.

Properties

Property Name Acceptable values Default Description

csv.delimiter-char

<char>

,

The char used for value separation, must not be a line break character

csv.escape-char

<char>

<disabled: no escape char>

The char used to escape special characters in values, may be disabled

Table Transformers

The table transformers properties marked with bold are mandatory.

FROM_CSV

FROM_CSV transformer generates table from the given CSV file.

Parameter Description

path

The CSV resource name or the CSV file path.

The path parameter can not be used together with the variableName or csvPath parameter.

variableName

The name of the variable containing source CSV, only variables of scopes global and next_batches are allowed. Exceptions are cases when the transformer using in step which initializes a variable with a table.

The variableName parameter can not be used together with the path or csvPath parameter.

csvPath

The CSV resource name or the CSV file path.

The csvPath parameter is deprecated and will be removed in VIVIDUS 0.7.0, please use path instead.
The csvPath parameter can not be used together with the variableName or path parameter.

delimiterChar

The char used for value separation, must not be a line break character

If delimiterChar is not set, then the corresponding property will be used during parsing.

Example 2. The transformer based on the default configuration
{transformer=FROM_CSV, path=/data/example.csv}
Example 3. The transformer based on the default configuration with variable CSV source
{transformer=FROM_CSV, variableName=csvVariable}
Example 4. The transformer with custom inlined configuration
{transformer=FROM_CSV, path=/data/another-example.csv, delimiterChar=;}

Steps

Save CSV into variable

Saves CSV string to indexed zero-based variable with column name mappings, e.g. var[0].key2, var[1].key1 etc. Please see the documentation for more information about complex variables.

When I save CSV `$csv` to $scopes variable `$variableName`
  1. $csv - CSV string.

  2. $scopes - The comma-separated set of the variables scopes.

  3. $variableName - The name of the variable to save CSV string.

Example 5. Validate CSV data
Given I initialize scenario variable `csv` with value `key1,key2,key3
val1-1,val1-2,val1-3
val2-1,val2-2,val2-3`
When I save CSV `${csv}` to scenario variable `expected-csv`
When I save CSV `#{loadResource(/data/simple-csv.csv)}` to scenario variable `actual-csv`
Then `${expected-csv}` is equal to `${actual-csv}`
Then `${csv-from-file[1].key2}` is equal to `val2-2`