Skip to content

Commit

Permalink
Merge pull request #556 from dougnoel/555As_a_user_I_wish_to_store_th…
Browse files Browse the repository at this point in the history
…e_contents_of_a_CSV_for_verification

CSV Value storage and retrieval step and tests
  • Loading branch information
tyBouch authored Jun 28, 2023
2 parents 2c172d0 + bcb5cf5 commit 17e8cc6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
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

0 comments on commit 17e8cc6

Please sign in to comment.