Excel Plugin
The plugin provides the ability to work with Excel documents.
Installation
-
Copy the below line to
dependencies
section of the projectbuild.gradle
filePlease make sure to use the same version for all VIVIDUS dependencies. Example 1. build.gradleimplementation(group: 'org.vividus', name: 'vividus-plugin-excel', version: '0.6.6')
-
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.
Table Transformers
FROM_EXCEL
FROM_EXCEL
transformer generates table from the given Excel file.
Parameter | Default | Description |
---|---|---|
|
the resulting column name in the generated table. If it’s missing in properties then the first row is used for the column headings. |
|
|
the Excel resource name or the Excel file path |
|
|
the sheet name from the excel file |
|
|
the range of cells from the specified excel sheet |
|
|
the comma-separated collection of the cell addresses from the specified excel sheet |
|
|
|
the increment used to traverse the specified |
|
|
defines whether cell values should be joined |
|
empty string |
value to substitute line breaks in cell values |
The following data types can be used in cells: NUMERIC (whole and fractional numbers), BOOLEAN , FORMULA , STRING . Other types are converted to empty string.
|
range and addresses are competing parameters and only one can be specified in the transformer declaration at the same time.
|
Examples:
{transformer=FROM_EXCEL, path=/my-excel-file.xlsx, sheet=Data, range=A2:A7, lineBreakReplacement= , increment=2, column=test}
Examples:
{transformer=FROM_EXCEL, path=/my-excel-file.xlsx, sheet=Data, addresses=A2;B4;A7, column=test, joinValues=true}
Examples:
{transformer=FROM_EXCEL, path=/my-excel-file.xlsx, sheet=Data, range=A2:B4}
Steps
Create excel file containing sheet with specified content
Create temporary excel file with specified content and save the path to the variable
When I create temporary excel file with content:$content and put path to $scopes variable `$variableName`
-
$content
- The data to be put to the excel file. Any valid ExamplesTable -
$variableName
- The variable name
When I create temporary excel file with content:
|key1 |key2 |
|value1|value2|
and put path to scenario variable `path`
Create excel file containing sheet with specified name and content
Create temporary excel file containing sheet with specified name and content and save the file’s path to the variable
When I create temporary excel file containing sheet with name `$sheetName` and content:$content and put its path to $scopes variable `$variableName`
-
$sheetName
- Then name of the Excel sheet. -
$content
- The data to be put to the excel file. Any valid ExamplesTable -
$variableName
- The variable name
When I create temporary excel file containing sheet with name `movies` and content:
|name |year|
|14 Peaks: Nothing Is Impossible|2021|
|Free Solo |2018|
|Grizzly Man |2005|
and put its path to scenario variable `movies-path`
Add sheet to existing excel file
Add new sheet with the specified name and content to the existing excel file.
When I add sheet with name `$sheetName` and content:$content to excel file at path `$path`
-
$sheetName
- Then name of the sheet. -
$content
- The data to put into the sheet. Any valid ExamplesTable. -
$path
- The path to existing excel file.
When I add sheet with name `pets` and content:
|type|name |
|duck|DuckDuckGo|
|fish|GlassFish |
|dog |Datadog |
to excel file at path `/home/collection.xslx`
Excel validations
By sheet name
Checks that excel has a sheet with name name and specified records.
Then `$excelDocument` contains excel sheet with name `$name` and records:$records
-
$excelDocument
- The excel document data to verify. -
$name
- The name of the sheet to verify. -
$record
- The ExampleTable that contains specified expected records in the sheet. Available columns:-
cellsRange
- The range of the cells to verify. (e.g. "B1:D8", "A1", "C1:C5") -
valueRegex
- The regular expression to match a value against.
-
When I execute HTTP GET request for resource with URL `https://github.com/vividus-framework/vividus/blob/master/vividus-plugin-excel/src/test/resources/TestTemplate.xlsx?raw=true`
Then response code is = `200`
Then `${response-as-bytes}` contains excel sheet with name `Mapping` and records:
{valueSeparator=!}
|cellsRange|valueRegex |
!A4:B5 !(Product|Price)\d+\s* !
!B3 !Price !
!C1:C5 ! !
By sheet index
Checks that excel has a sheet with index index and specified records.
Then `$excelDocument` contains excel sheet with index `$index` and records:$records
-
$excelDocument
- The excel document data to verify. -
$index
- The index of the sheet to verify. -
$record
- The ExampleTable that contains specified expected records in the sheet. Available columns:-
cellsRange
- The range of the cells to verify. (e.g. "B1:D8", "A1", "C1:C5") -
valueRegex
- The regular expression to match a value against.
-
When I execute HTTP GET request for resource with URL `https://github.com/vividus-framework/vividus/blob/master/vividus-plugin-excel/src/test/resources/TestTemplate.xlsx?raw=true`
Then response code is = `200`
Then `${response-as-bytes}` contains excel sheet with index `0` and records:
{valueSeparator=!}
|cellsRange|valueRegex |
!A4:B5 !(Product|Price)\d+\s* !
!B3 !Price !
!C1:C5 ! !