SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

Documentation request:

Open saiparth opened this issue 3 years ago • 5 comments

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")

saiparth avatar Aug 04 '22 07:08 saiparth

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?

SabotageAndi avatar Aug 04 '22 11:08 SabotageAndi

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

saiparth avatar Aug 04 '22 13:08 saiparth

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

SabotageAndi avatar Aug 04 '22 13:08 SabotageAndi

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")

saiparth avatar Aug 18 '22 09:08 saiparth

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

SabotageAndi avatar Aug 18 '22 14:08 SabotageAndi