Multiple Match bindings found on line with two different parameters

拥有回忆 提交于 2019-12-07 09:55:23

问题


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.


回答1:


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.




回答2:


AFAIK the Visual Studio integration jumps to the first step definition it finds.

The Regex of the def()- Steps catches also the cases of the abc- Step. Did you tried to put the parameters within single quotes?

Like that:

Feature:

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

Step Bindings:

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

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

That should fix your problem.



来源:https://stackoverflow.com/questions/34545533/multiple-match-bindings-found-on-line-with-two-different-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!