Is it possible to have two step definition classes with first being in one namespace/project, and second in another one? I have like this:
My test project which I run: namespace: ABZ.ExcelTest class name: ABZ.ExcelTest.ExcelStepDefinition
My other project which is Logic for testing: namespace: ABZ.OfficeAddInTestLogic class name: ABZ.OfficeAddInTestLogic.StepDefinition
I have [Binding] attribute on both my classes but this one which is not in test project (ABZ.OfficeAddInTestLogic.StepDefinition) cannot be found, I get NUnit error:
No matching step definition found for the step. Use the following code to create one: ...
Is it possible to have 2 step definition classes in different projects?
Right-click on any step of the Feature File, then click on Generate Step Definitions option. In the Generate Step Definition Skeleton pop-up, check the steps for which we want to generate the implementation. Add a Class Name, then click on the Generate button.
Open your feature file. Right-click in the editor and select Define steps… from the menu. Enter a name for your class in the Class name field. Click on create to generate a new step definition file or use the Copy methods to clipboard method to paste the skeleton code in an existing step definition file.
You have to add the [Binding] attribute to the class where your step definitions are: [Binding] public class StepDefinitions { ... } > Note: Bindings (step definitions, hooks) are global for the entire SpecFlow project.
Yes it is - that feature is called External steps (see https://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/ExternalSteps/ExternalSteps.feature)
What you probably are missing is an app.config setting like this:
<specFlow>
<stepAssemblies>
<stepAssembly assembly="ExternalStepsCS" />
</stepAssemblies>
That will look for steps in an external assembly called ExternalStepsCS in this case.
I will often have a "Test Helpers" library, with common code shared between multiple test projects. I'll have a class in this shared library, let's call it CucumberBase
. Then, in my actual test project, I'll have a class like this:
[Binding]
public class SomeFeatureSpecs : CucumberBase
{
...
}
Every public CucumberBase
method that is tagged with [Given()]
/[When()]
/[Then()]
/etc. gets picked up correctly in my actual test project, within the SomeFeatureSpecs
class. This lets me override and extend common functionality as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With