SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

Step definition not reconized in feature files

Open DomZZ opened this issue 2 years ago • 1 comments

SpecFlow Version

4.0.31-beta

Which test runner are you using?

NUnit

Test Runner Version Number

3.13.3

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

{ "$schema": "https://specflow.org/specflow-config.json", "generator": { "addNonParallelizableMarkerForTags": [ "nonparallelizable" ] }, "runtime": { "missingOrPendingStepsOutcome": "Error" } }

Issue Description

I added a step definition with a param (regular expression that should accept 2 different strings (collapse or expand) then in the C# method I know how to behave depending on the param value.

But the step definition that is not reconized in feature files...

Steps to Reproduce

[When(@"I click on summary card ""(expand|collapse)"" button")]
public void WhenIClickOnSummaryCardCollapseExpandButton(string cardAction)
{
   throw new PendingStepExpception();
}

But I've observed that if there is other params it works :

[When(@"I click on summary card ""(expand|collapse)"" button with label ""([^""]*)""")]
public void WhenIClickOnSummaryCardCollapseExpandButton(string cardAction, string label)
{
   throw new PendingStepExpception();
}

Link to Repro Project

No response

DomZZ avatar Oct 18 '23 05:10 DomZZ

This is likely because specflow since 4.0 allows both cucumber and regular expressions. This is automatically determined, but for this this step it makes an incorrect conclusion. To work around this you can write down the step as follow: @"^I click on summary card ""(expand|collapse)"" button$" to ensure it is always detected as a regular expression.

mharwig avatar Oct 20 '23 12:10 mharwig