Get Result from the Scenario Contest

750 views
Skip to first unread message

Vignesh babu V

unread,
Oct 24, 2016, 8:41:00 AM10/24/16
to SpecFlow
Hi All, 

Could you please help me . how to get the test results status from the scenario context .

Thanks 
Vignesh Babu 

Andreas Willich

unread,
Oct 24, 2016, 11:45:22 AM10/24/16
to SpecFlow
Hi

Do I understand you correctly, that you want the status of the current test?
What do you want to do with it and how do you want to use it?

There is a TestError property accessible on the ScenarioContext (https://github.com/techtalk/SpecFlow/blob/master/TechTalk.SpecFlow/ScenarioContext.cs#L50).
Can you work with that?

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.

Vignesh babu V

unread,
Oct 30, 2016, 2:20:48 AM10/30/16
to SpecFlow
I got it . I need step wise test status .

Currently it given only the Step Info . Is it possible to get the Step Status. Could you please help me.

Also If the test is ignored , how to capture the scenario result through test error . Can you please guide me

Andreas Willich

unread,
Oct 30, 2016, 8:15:25 PM10/30/16
to SpecFlow
Could you explain a little bit what you are want to achieve?
So we can give you a solution for your problem. Currently I am not 100% sure what do you want and so I can only make wild guesses for solutions.

About the ignored tests:
SpecFlow generate the appropriate ignore attributes for the unit test framework/runner. 
So the test runners are not executing the tests and no code gets executed.
Why do you want to handle this cases?

Annie Costa

unread,
Apr 4, 2017, 4:16:56 AM4/4/17
to SpecFlow
Hello,

I just see this conversation.
I also would like to know how to get the scenario execution status at the end of his execution - in the AfterScenario method.
I need it as I want to send the result through a Rest API to an external tool to update the status of the test on it.

Of course, the "ScenarioContext.Current.TestError" can help us in case of failed test, but how can we know the exact status for the "skipped", "pending", or "success" scenario?
More over, in cas of failed scenario, we have the stack trace of the error but is it possible to get the exact step that failed in the code (language C#)?

Thanks

Andreas Willich

unread,
Apr 6, 2017, 2:03:47 AM4/6/17
to SpecFlow
Hi

I have to admin, that the error reporting & checking could be improved in SpecFlow.


So, if someone what to improve it, this is a good starting point.
Making some of these properties public, would probably also be helpful: https://github.com/techtalk/SpecFlow/blob/master/TechTalk.SpecFlow/ScenarioContext.cs#L52

PRs in this area are always gladly seen.

Best regards
Andreas

Annie Costa

unread,
Apr 6, 2017, 3:39:42 AM4/6/17
to SpecFlow
I finnaly found a way to get the different status thanks to this method
public static object GetHiddenContent(string element)
       {
           var pInfo = typeof(ScenarioContext).GetProperty(element, BindingFlags.Instance | BindingFlags.NonPublic);
           var getter = pInfo.GetGetMethod(nonPublic: true);
           return getter.Invoke(ScenarioContext.Current, null);
       }

And I give "TestStatus" as the argument.

But my pb now is about scenario tagged as "Ignore".
I put break point on my "[BeforeTestRun]" and "[BeforeFeature]" but if I execute only the "Ignore" scenario, none of them are reached.. So I don"t know how to catch them to be able to send the correct status. :(

Andreas Willich

unread,
Apr 6, 2017, 3:42:22 AM4/6/17
to SpecFlow
Ignored scenarios/tests are normally not executed by the test runner. 
So no SpecFlow code is executed for it.

Annie Costa

unread,
Apr 6, 2017, 4:19:17 AM4/6/17
to SpecFlow
I understand but how could I now that some tests have been ignored to be able to send their status?
I'm not always running all the scenarios of a feature.. so I cannot provide in advanced if a scenario is Ignored or not.. :(

Andreas Willich

unread,
Apr 6, 2017, 4:21:34 AM4/6/17
to SpecFlow
Not within SpecFlow.
Perhaps your test runner has a hook for that. Which one are you using?

Annie Costa

unread,
Apr 6, 2017, 4:31:15 AM4/6/17
to SpecFlow
I'm using SpecRun

Annie Costa

unread,
Apr 14, 2017, 4:58:41 AM4/14/17
to SpecFlow
I'm using SpecRun.Runner version 1.5.2

manoj kundu

unread,
Aug 17, 2018, 5:19:20 PM8/17/18
to SpecFlow
Hi Guys,

I am looking for step wise result too
I want to sent the result to an excel file , right now i can get the error message  

var error = ScenarioContext.Current.TestError;

but this does not tell which step give this error 

i want something which gives result like the log file 

like 

step 1 passed 
step 2 passed 
step 3 failed 


And I enter Insured details as Individual
-> done: RecordVehicleWrittenOffSteps.WhenIEnterInsuredDetailsFirstNameAndLastName("Individual") (0.2s)

And I enter the first name card and last name test
-> done: RecordVehicleWrittenOffSteps.WhenIEnterTheFirstNameAndLastName("card", "test") (2.9s)

Then I am able to confirm the details
-> done: RecordVehicleWrittenOffSteps.ThenIAmAbleToConfirmTheDetails() (0.8s)

And the success message is displayed
-> error:   Success message could not be verified
->   Expected string length 57 but was 58. Strings differ at index 57.
->   Expected: "The vehicle has been successfully recorded as written off"
->   But was:  "The vehicle has been successfully recorded as written off."
Reply all
Reply to author
Forward
0 new messages