Specflow support for excel based data driven sheet-wise

1,455 views
Skip to first unread message

Palani Selvam

unread,
Jun 14, 2017, 12:25:55 AM6/14/17
to SpecFlow
Hi All,

  For our tests, planning to keep the data in multiple excel sheets. Based on features, will use different sheet as data set. I didn't get any sample using excel sheet-wise. I would like to know, whether Specflow supports data from excel sheet-wise or NOT.

Thanks,
Palani

Andreas Willich

unread,
Jun 14, 2017, 7:28:58 AM6/14/17
to spec...@googlegroups.com
Hi Palani

SpecFlow itself does not have the functionality to get examples out of an excel sheet, but there is SpecFlow+Excel (http://specflow.org/plus/excel/) which is part of the SpecFlow+ Suite (http://specflow.org/plus/).

Have a look at the "Getting started with Excel" http://specflow.org/plus/excel/getting-started/ and an example project (https://github.com/techtalk/SpecFlow.Plus.Examples/tree/master/ExcelExample) how to use it.

Best regards
Andreas

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Palani Selvam

unread,
Jun 15, 2017, 3:35:25 AM6/15/17
to SpecFlow
Hi Andreas,
 Thanks for your reply.

 I've used Excel as data source and didn't keep my feature steps in Excel. I would like to use excel instead of table. There is no provision to feed inputs excel sheet-wise. Please see below scenario and tell me whether it is possible to give the inputs sheet-wise.

For example, my scenario looks like below:
@GetPet
Scenario Outline: Find Pet by Id
Given I have prepared Pet API request
And Set the request to find Pet by <Id>
When the request is sent as GET
Then Validate the response by <Result>

@source:DataSet.xlsx
Examples: 
| Id | Result |


Thanks,
Palani

Andreas Willich

unread,
Jun 15, 2017, 4:33:16 AM6/15/17
to SpecFlow
Hi Palani

It is possible to only get the data from excel and have the scenario in a feature file with SpecFlow+Excel.
And it looks like your example.


Scenario Outline: Subtract two numbers
Given I have entered <Number1> into the calculator
And I have also entered <Number2> into the calculator
When I press substract
Then The result should be <Result> on the screen

#The following line references the examples in SubtractTwoNumbers.examples.xlsx
#You can also extend the table below with additional examples
@source:SubtractTwoNumbers.examples.xlsx
Examples: 
| Number1 | Number2 | Result |

Best regards
Andreas

Tz

unread,
Jun 15, 2017, 5:12:15 AM6/15/17
to SpecFlow
You can specify the sheet name too (if the default logic does not fit) as explained here:
http://specflow.org/plus/documentation/Prepare-feature-files-for-external-examples/

Br,
Tz

Palani Selvam

unread,
Jun 15, 2017, 5:18:55 AM6/15/17
to SpecFlow
Hi Andreas,
 Thanks for the info.

Please validate below statements.
1.  Using SpecFlow+ Excel, I'll not able to use data sheet-wise,  if the scenarios are available only in feature file.
2.  Should I need to procure the licence, if I use excel only for data set? like this ==> https://github.com/techtalk/SpecFlow.Plus.Examples/blob/master/ExcelExample/ExcelExample/Features/CalculatorSubtract.feature

Thanks,
Palani.

Stephen McCafferty

unread,
Jun 22, 2017, 7:02:36 AM6/22/17
to SpecFlow
You essentially have the following options:
  1. Define both the steps and the example data in a feature file
  2. Define both the steps and the example data in an Excel sheet
  3. Define the steps in a feature file and example data in an Excel sheet. Refer to the Excel sheet containing the example data using @source:FileName.xlsx
  4. Define both steps and example data in a feature file, and reference additional example data in an Excel sheet. Refer to the Excel sheet containing the example data using @source:FileName.xlsx

There are examples of each of these in the Excel sample project you referenced above. The CalculatorMultiply.feature file demonstrates the combination of the two:

#The following line references the examples in MultiplyTwoNumbers.part.examples.xlsx
@source:MultiplyTwoNumbers.part.examples.xlsx
#The examples in the table below are ALSO used
Examples:
   
| Number1 | Number2 | Result |
   
| -10       | 10        | -100   |
   
| 42        | 13        | 546    |


In this case, the examples in the table at the bottom are used, as well as the two test cases in MultiplyTwoNumbers.part.examples.xlsx


You will need a SpecFlow+ license if you want to use SpecFlow+ Excel to read data in Excel sheets, whether these are the steps or the example data.
Reply all
Reply to author
Forward
0 new messages