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.22k stars 751 forks source link

Step definition not reconized in feature files #2723

Open DomZZ opened 8 months ago

DomZZ commented 8 months ago

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

mharwig commented 8 months ago

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.