Jp *_*ddy 5 .net c# bdd specflow
我在使用Spec-flow已经有好几天了.我正面临"找到多个匹配.导航到第一个匹配",而调试这个可以解决,但是当我运行整个解决方案时由于绑定中的歧义而失败.我在Single项目中运行了4个C类清单文件
Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
Given I get Inputs Folder and list of Files <inputFolder> then <getInputTokens>(Multiple bindings for this line)
Given I get <outputDirectory>
Given I set saving Mode <ConversionMode>
Given I convert pdf using Conversion
Given I convert to Image <convertToFile>
Then I compare Images <getActualImagePath> and <getExpectedImagePath> and <pageCount>
Run Code Online (Sandbox Code Playgroud)
和步骤定义:
**Binding for Multiple steps is the below binding:**
Run Code Online (Sandbox Code Playgroud)
第一次绑定:
[Given(@"I get Inputs Folder and list of Files (.*) then (.*)")]
public void GivenIGetInputsFolderAndListOfFilesThen(string getInputFolder, string getInputTokens)
{
--logic--
}
Run Code Online (Sandbox Code Playgroud)
二次绑定:
[Given(@"I get (.*)")]
public void GivenIGet(string getOutputDirectory)
{
--logic--
}
Run Code Online (Sandbox Code Playgroud)
第二个绑定修改为:
Given I set OutputDirectory of Pdf <outputDirectory>
[Given]
public void Given_I_set_OutputDirectory_of_Pdf_P0(string p0)
{
--logic--
}
Run Code Online (Sandbox Code Playgroud)
这个也没有帮助我.尝试过Regex仍然无法解决问题.在上面提到的2个绑定中存在歧义.它不仅仅是一个功能,它也观察到其他功能文件.如何解决这一问题,使每一行与一个Binding完全匹配?
正如@perfectionist指出你的问题与你的正则表达式有关.一个是消耗两者的所有字符.试试这个:
Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
Given I get Inputs Folder and list of Files '<inputFolder>' then '<getInputTokens>'
Given I get '<outputDirectory>'
...
Run Code Online (Sandbox Code Playgroud)
和步骤定义:
[Given(@"I get Inputs Folder and list of Files '([^']*)' then '([^']*)'")]
public void GivenIGetInputsFolderAndListOfFilesThen(string getInputFolder, string getInputTokens)
{
}
[Given(@"I get '([^']*)'")]
public void GivenIGet(string getOutputDirectory)
{
--logic--
}
Run Code Online (Sandbox Code Playgroud)
只有当输入不包含'
字符时,此正则表达式才会匹配,因此在使用输入并匹配较长方法时,将阻止第二种方法过于贪婪.
作为一般规则,我更喜欢在场景中将字符串字符包装在单引号中,因为它会使这样的问题更容易缓解
显然,只有输入'<inputFolder>','<getInputTokens>' and <outputFolder>
不包含任何'
字符时,上述内容才有效.如果他们这样做,你可能需要一个更复杂的正则表达式
归档时间: |
|
查看次数: |
2564 次 |
最近记录: |