Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV Value storage and retrieval step and tests #556

Merged
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
29 changes: 29 additions & 0 deletions src/main/java/com/dougnoel/sentinel/steps/CsvSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,33 @@ public static void verifyNumberOfRows(int numRows){
assertEquals(errorMessage, numRows, file.getNumberOfDataRows());
}

/**
* Stores the value of a specific row and column cell within a CSV file with a given name.
* Used for storing a CSV cell value that will not be modified for later comparison.
* <p>
* <b>Gherkin Examples:</b>
* <ul>
* <li>I store the cell value in the <b>last</b> row of the <b>name</b> column in the csv as <b>last name entry</b></li>
* <li>I store the cell value in the <b>4th</b> row of the <b>1st</b> column in the csv as <b>comment entry</b></li>
* </ul>
* @param rowNum String the row of the cell. Can contain an ordinal such as 1st, 3rd, 4th, or last
* @param column String the column of the cell. Can contain the column name or it's ordinal form
* @param storageKey String the name to store the value as
*/
@Then("^I store the cell value in the (la|\\d+)(?:st|nd|rd|th) row of the (.*?) column in the (?:csv|CSV) as (.*?)$")
public static void storeCsvValue(String rowNum, String column, String storageKey) {
CsvFile file = (CsvFile) FileManager.getCurrentTestFile();
int rowIndex = rowNum.equals("la") ? file.getNumberOfDataRows() : Integer.parseInt(rowNum);

String storageValue;
String firstColumnCharacter = column.substring(0, 1);
if(StringUtils.isNumeric(firstColumnCharacter)){
storageValue = file.readCellData(SentinelStringUtils.parseOrdinal(column), rowIndex);
}
else{
storageValue = file.readCellData(column, rowIndex);
}

Configuration.update(storageKey, storageValue);
}
}
21 changes: 19 additions & 2 deletions src/test/java/features/386 CSV Steps.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#author: sampacos

@386 @csv @525
@386 @csv @525 @555
Feature: Verify and Edit CSVs

@386A @csv
Expand Down Expand Up @@ -79,4 +79,21 @@ Feature: Verify and Edit CSVs
And I delete the 2nd row entry in the CSV file
Then I verify the CSV has 2 data rows
And I verify the comment column of the csv does not have the text me
And I verify the 5th column of the csv does not have the text now
And I verify the 5th column of the csv does not have the text now

@555A @csv
Scenario: Store and verify the value of a CSV file
Given I navigate to the Downloads Test Page
When I verify that by clicking the csv download link a new file is downloaded with the extension csv
And I find and open the last downloaded csv file with 1 header row
And I store the cell value in the last row of the name column in the csv as originalFinalName
And I store the cell value in the 1st row of the name column in the csv as originalFirstName
Then I verify the name column of the csv contains the same text used for the originalFinalName
And I verify the name column of the csv does not contain the text change original final name
And I verify the name column of the csv does not contain the text change original first name
When I set the value in the last row of the name column to change original final name in the CSV file
And I set the value in the 1st row of the name column to change original first name in the CSV file
Then I verify the name column of the csv contains the text change original final name
And I verify the name column of the csv contains the text change original first name
And I verify the name column of the csv does not contain the same text used for the originalFinalName
And I verify the name column of the csv does not contain the same text used for the originalFirstName
Loading