Reuse of background between multiple feature files

760 views
Skip to first unread message

sunita shaw

unread,
Jan 3, 2016, 11:57:06 PM1/3/16
to SpecFlow
I have multiple feature files that reuse the same background which is actually a data setup. How do I reuse this background between multiple feature files so that if anything ever changes with data I have just one place to change?

Background: 
Given I am logged in as active user 'Bob' with roles: [Administrators] and accounting event groups: [Financial Analysts]
And below data exists in the database:
| Station | Accounting Event group | Agency Administrator |
| Gherkin Testing Station | Financial Analyst       | Gherkin Testing Administrator    | 

And the Offender Trust Account exists:
|  Name         | Description   | Account Type | Account Category | Trust Category |
| Offender Spending   | Offender Trust Account | Liability | Funds to pay out | Spending       |
| Offender Retention | Offender Retention for release | Liability | | |

And the Cash Drawer Account exists:
| Name | Decsription | Account Type | Acocunt Category |  
| Cash Drawer Account | Drawer for receiving and releasing individuals' funds | Asset       | Cash on hand    | 

Sam Holder

unread,
Jan 4, 2016, 9:44:22 AM1/4/16
to specflow
The simplest way would be to create a single step and just call that. I would have something like

Background:
   Given I have done the common setup

Then do all of the stuff in your original background either in that step or by calling the other steps individually.

--
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.

Umair Chagani

unread,
Jan 4, 2016, 12:04:00 PM1/4/16
to spec...@googlegroups.com
Since this is a common setup, I would put this in a hook and tag the scenarios/features that need it.  That way you don't need to litter your feature files with data that everyone already knows.  

dinesh sharma

unread,
Aug 24, 2017, 2:50:29 AM8/24/17
to SpecFlow, umair....@gmail.com
I used the same approach of using a hook and tagging the other feature files with that. The issue i faced is it is not picking the feature files in a ordered way.it is behaving in a unstructured manner.

Ladislav Varga

unread,
Sep 17, 2017, 1:10:19 PM9/17/17
to SpecFlow
Hello,

We are sharing not only specflow steps between solution but Hooks too. It is helping new solution to run as soon as possible. 
You can use ordering in Hooks.

Example:
[BeforeScenario(Order = HookAttribute.DefaultOrder)] 
(10000) in this situation

Dne čtvrtek 24. srpna 2017 8:50:29 UTC+2 dinesh sharma napsal(a):
Reply all
Reply to author
Forward
0 new messages