SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.24k stars 754 forks source link

Documentation request: #2630

Open saiparth opened 2 years ago

saiparth commented 2 years ago

What's the alternative solution for calling steps from step definitions? (https://github.com/SpecFlowOSS/SpecFlow/issues/1733) We can directly call the methods, but we will loose console output which was logging the information like method name and passed arguments. we can log using reflection, but is there any specflow tool/method which already does this? Ex:

[When(@"Opening all Page")]
public void WhenOpeningAllPage()
{
steps.WhenOpeningPage("Login");
}
[When(@"Opening Page")]
public void WhenOpeningPage(string key)
{
//do something
}

Log this

done: steps.WhenOpeningAllPage()
done: steps.WhenOpeningPage("something")
SabotageAndi commented 2 years ago

The alternative is the driver pattern: https://docs.specflow.org/projects/specflow/en/latest/Guides/DriverPattern.html For output please use our dedicated output api: https://docs.specflow.org/projects/specflow/en/latest/outputapi/outputapi.html

But why do you need or want this output?

saiparth commented 2 years ago

Thanks for reply. Presently we are not using latest version of specflow and using the deprecated feature of calling steps within the steps. We are using custom framework wherein we read the result.xml of nunit CLI and show the console output in report.

If we upgrade specflow, I will have to directly call the step definition method and manually write the logs. I was thinking to use common method using reflection and pass all these methods as argument so that in run time we will fetch the attribute and value like - Given,"I launch browser" etc.

So though of checking any API provided by specflow before implementing the fix

SabotageAndi commented 2 years ago

It is marked as deprecated but not yet removed from 3.9.. So you can still upgrade to 3.9.

saiparth commented 2 years ago

Hi @SabotageAndi
Can you pls share code path where specflow is finding the the method arguments and name? Ex: for logging this to console

done: steps.WhenOpeningAllPage()
done: steps.WhenOpeningPage("something")
SabotageAndi commented 2 years ago

SpecFlow doesn't make this information public. The logging is using the data that is used to execute the method.

https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow/Infrastructure/TestExecutionEngine.cs#L483