Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Specflow在使用时会重复使用_Selenium_Specflow - Fatal编程技术网

Selenium Specflow在使用时会重复使用

Selenium Specflow在使用时会重复使用,selenium,specflow,Selenium,Specflow,我目前正在使用Specflow和Selenium自动化测试。我已经创建了一些简单的函数,我想与Specflow一起重用。我遇到的问题是,一旦我将一个步骤定义为When,以后我就不能将此步骤与Then一起重复使用 例如: Scenario: 1 Given user navigates to 'http://www.anyURL.com/' When user inserts 'data' into field with ID 'id' And user clicks on button with

我目前正在使用Specflow和Selenium自动化测试。我已经创建了一些简单的函数,我想与Specflow一起重用。我遇到的问题是,一旦我将一个步骤定义为When,以后我就不能将此步骤与Then一起重复使用

例如:

Scenario: 1
Given user navigates to 'http://www.anyURL.com/'
When user inserts 'data' into field with ID 'id'
And user clicks on button with ID 'id'
Then user sees 'x' amount of search results
这就是场景1。现在在场景2中,我想使用 “当用户将‘数据’插入ID为‘ID’的字段时” 作为: “然后用户将‘数据’插入ID为‘ID’的字段”

但在我的代码中,我的函数以[When(@“user inserts'(.*)”)开头……Sepcflow与此不匹配

我记得Cucumber过去是自动完成的


非常感谢您的帮助!

在specflow中,您只需向要绑定的方法添加另一个属性:

[When(@"user inserts '(.*)'"]
[Given(@"user inserts '(.*)'"]
public void UserInertsData(string data)
{
     ....
}

哦,哇!有那么简单吗?我只是在Specflow文档中找不到这个解决方案。非常感谢!您也可以通过简单地在方法上使用更多相同类型的属性来创建措辞稍有不同的步骤[Given,当(@“user inserts”(.*))]-->是偶数时shorter@ward这行吗?这不是说
[Given()]
没有正则表达式和
[当(@“用户插入”(.*))]时]
,这可能会导致不同的匹配情况