Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Match bindings found on line with two different parameters

I have written two lines(When's) in my same feature file

When user $action1$ $key1$ with $value1$ for $atttributeType_Value$ in $Filename1_SectionId1$
Then abc
When user $action2$ $key2$ with $value2$ in $Filename2_SectionId2$
Then def

and corresponding step definition in step definition file

as

[When(@"user (.*) (.*) with (.*) for (.*) in (.*)")]
public void abc()
{   //operation }

[When(@"user (.*) (.*) with (.*) in (.*)")]
public void def()
{   //operation }

But, its showing up an error as "Multiple match bindings found. Navigating to first match.."

When I try to navigate for 1st line its giving error... But when I navigate using second When line. it's navigating properly.

I have used "$" at the place where "<" and ">" should be there.

like image 676
Suraj Gupta Avatar asked Feb 09 '23 04:02

Suraj Gupta


1 Answers

The problem is that your second regex:

with (.*) in (.*)

matches both these lines

with a partridge in a pear tree
with a partridge for Christmas in a pear tree

In the first instance, it'll pick up "partridge" and "a pear tree" as the two arguments. In the second, it will pick up "partridge for Christmas" and "a pear tree" as the arguments. Since your first regex also matches that second line, it is indeed finding multiple bindings.

You could use a different regex. For instance, if you want to pick out a whole word and not have any whitespace included, try (\S*) instead of (.*). That . matches anything, including spaces. More on regex here.

like image 148
Lunivore Avatar answered Feb 11 '23 01:02

Lunivore