Using Scenario Outline Examples in BeforeTestRun/BeforeFeature/BeforeScenario hooks

138 views
Skip to first unread message

Matej Straka

unread,
Oct 7, 2020, 4:50:54 AM10/7/20
to SpecFlow
Hello everyone,
Is it possible to retrieve data from Scenario Outline Examples table in [BeforeTestRun], [BeforeFeature] or [BeforeScenario]  hooks?
For example I have simple Scenario Outline like this one:

Scenario Outline: Login to website
Given Login form is displayed
When I fill <Login> and <Password> 
Then I am successfully logged in 
Examples:
| Login | Password   |
| user1 | password1 |
| user2 | password2 |

I want to use values from Examples table in  [BeforeTestRun] or [BeforeFeature] hook.
Here is example with  [BeforeTestRun]  hook:

[BeforeTestRun] 
 public static void PrepareTestUsersBeforeStart()
{
    // code to prepare test data based on data in Scenario outline Examples table
    // create user in our database with credentials from records in Examples table
    // create user with Login "user1"  and Password "password1" in our database
}

Thanks for advices or any suggestions how to solve this issue.

Best,
Matej

praveenreddy narala

unread,
Oct 7, 2020, 5:22:19 AM10/7/20
to spec...@googlegroups.com
Hi,

As far as I know, this is not possible, and it against the BDD design pattern. Before Test Run and After Test Run will execute before and after the Feature run. Hence, you can not call examples in Test Run. Also, Examples are user scenarios (not just test data). 

I hope it helps.

Regards,
Praveen

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/specflow/728240fe-c52e-4cf2-893d-b7a45b2d8990n%40googlegroups.com.

Andreas Willich

unread,
Oct 7, 2020, 6:12:14 AM10/7/20
to SpecFlow

Please don't double post in the future. That makes it even harder for other people later to find an answer. Thanks!

Reply all
Reply to author
Forward
0 new messages