在线找到具有两个不同参数的多个匹配绑定 [英] Multiple Match bindings found on line with two different parameters

查看:91
本文介绍了在线找到具有两个不同参数的多个匹配绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一要素文件中写了两行(何时)

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

[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.."

当我尝试导航到第一行时,它给出了错误信息……但是当我使用第二条While行进行导航时.它正在正确导航.

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.

推荐答案

问题是您的第二个正则表达式:

The problem is that your second regex:

with (.*) in (.*)

匹配这两行

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

首先,它将选择"partridge"和梨树"作为两个参数.在第二个中,它将选择圣诞节的隔离区"和一棵梨树"作为参数.由于您的第一个正则表达式也与第二行匹配,因此确实可以找到多个绑定.

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.

您可以使用其他正则表达式.例如,如果您想选择一个完整的单词而不包含任何空格,请尝试使用(\S*)而不是(.*). .匹配任何内容,包括空格.有关正则表达式的更多信息此处.

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.

这篇关于在线找到具有两个不同参数的多个匹配绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆