4

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.

4

2 に答える 2

8

問題は、2 番目の正規表現:

with (.*) in (.*)

これらの行の両方に一致します

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

最初の例では、2 つの引数として「ヤマウズラ」と「ナシの木」を取得します。2 番目の例では、引数として「クリスマスのヤマウズラ」と「ナシの木」を取り上げます。最初の正規表現もその 2 行目に一致するため、実際には複数のバインディングが見つかります。

別の正規表現を使用できます。たとえば、空白を含めずに単語全体を選択したい場合は、(\S*)代わりに(.*). これ.は、スペースを含め、何にでも一致します。正規表現の詳細はこちら.

于 2016-01-01T15:08:22.917 に答える
0

私の知る限り、Visual Studio 統合は、見つかった最初のステップ定義にジャンプします。

def()-Steps の正規表現は、abc-Step のケースもキャッチします。パラメータを一重引用符で囲みましたか?

そのように:

特徴:

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

ステップバインディング:

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

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

これで問題が解決するはずです。

于 2015-12-31T14:49:39.057 に答える