Providing Examples in more than 1 row Specflow

127 Views Asked by At

When I provide examples in a single row it works fine. When I provide examples in more than a row I'm getting binding parameter exception. If I provide all examples in a single line its not readable easily.

Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
    Given I get Inputs Folder and list of Files <inputFolder> then <getInputTokens>
    Given I get '<outputDirectory>'
    Given I get directory to save Images '<ImagesOutputDirectory>'

Examples: 
     | inputFolder                                                             | getInputTokens        | outputDirectory                                                                        | ImagesOutputDirectory                                                    |
     | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Inputs\2files | Input1.pdf,Input2.pdf | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\AfterConvertingToPdf\2files  | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Actual\2files  |
    Given I set saving  Mode <ConversionMode>
    Given I convert pdf using Conversion
    Given I convert to Image '<convertToFile>'
    Then I compare Images '<getActualImagePath>' and '<getExpectedImagePath>' and '<pageCount>'

    | ConversionMode      | convertToFile                                                                         | getActualImagePath                                                      | getExpectedImagePath                                                      | pageCount |
    | ConvertToSingleFile | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\AfterConvertingToPdf\2files | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Actual\2files | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Expected\2files | 82        |

Works fine if Examples look like this :

Examples:
    | inputFolder                                                             | getInputTokens        | outputDirectory                                                                        | ImagesOutputDirectory                                                   | ConversionMode       | convertToFile                                                                          | getActualImagePath | getExpectedImagePath | pageCount |
    | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Inputs\2files | Input1.pdf,Input2.pdf | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\AfterConvertingToPdf\2files\ | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Actual\2files\|  ConvertToSingleFile | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\AfterConvertingToPdf\2files\ | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Actual\2files |D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Expected\2files | 82                 |
1

There are 1 best solutions below

0
On BEST ANSWER

There are a couple of things wrong with your first scenario. You have mixed you steps with your examples. The steps must be in the scenario outline, they can't be in the examples.

Given that, if you re-wrote your scenario with the steps in the outline then it would look like this:

Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
    Given I get Inputs Folder and list of Files <inputFolder> then <getInputTokens>
    Given I get '<outputDirectory>'
    Given I get directory to save Images '<ImagesOutputDirectory>'
    Given I set saving  Mode <ConversionMode>
    Given I convert pdf using Conversion
    Given I convert to Image '<convertToFile>'
    Then I compare Images '<getActualImagePath>' and '<getExpectedImagePath>' and '<pageCount>'
Examples: 
     | inputFolder                                                             | getInputTokens        | outputDirectory                                                                        | ImagesOutputDirectory                                                    |
     | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Inputs\2files | Input1.pdf,Input2.pdf | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\AfterConvertingToPdf\2files  | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Actual\2files  |
     | ConversionMode      | convertToFile                                                                         | getActualImagePath                                                      | getExpectedImagePath                                                      | pageCount |
     | ConvertToSingleFile | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\AfterConvertingToPdf\2files | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Actual\2files | D:\SVN_Projects\XDoc.Net\SpecFlow\Conversion\ConvertToPdf\Expected\2files | 82        |

now it becomes more obvious why you can't have two sets of examples on different lines, because it looks like the inputFolder has a value of ConversionMode, when actually ConversionMode is a title.

you main problem here is that you have full file paths in your examples. This is an implementation detail and it would be better, IMHO, to remove these paths and to use monikers instead. After all those full file paths are not going to work on anyone elses machine that yours and not on the build server. I would consider rewriting them like this:

Examples:
    | inputFolder | getInputTokens        | outputDirectory | ImagesOutputDirectory | ConversionMode      | convertToFile | getActualImagePath | getExpectedImagePath | pageCount |
    | 2files      | Input1.pdf,Input2.pdf | 2files          | 2files                | ConvertToSingleFile | 2files        | 2files             | 2files               | 82        |

Although even this has a lot of duplicate information now it has been reduced and so your entire scenario could be re-written like this

Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
    Given I am processing files in the subdirectory <workingFolder> of the input folder then <getInputTokens>
    And I save file to the subdirectory <workingFolder> of the output folder
    And I save Images to the subdirectory <workingFolder> of the images folder
    And I set saving  Mode <ConversionMode>
    And I convert pdf using Conversion
    And I convert to Image the files in the subdirectory <workingFolder> of the output folder
    When I compare Images of page '<pageCount>' in the subdirectory <workingFolder> of the actual image folder and subdirectory <workingFolder> of the expected image folder
    Then the images should be the same 
Examples:
    | workingFolder | getInputTokens        | ConversionMode      | pageCount |
    | 2files        | Input1.pdf,Input2.pdf | ConvertToSingleFile | 82        |

and then you base folders can either be made relative to you project and deployed as part of the tests build or can be held in configuration.