BDD 和 Behat 特殊字符

标签 bdd behat gherkin

有一个类似的问题@Gherkin in Behat and input validations scenarios

但是不一样。

我的问题是我需要对场景大纲示例或数组进行描述

Given I have a problem with data
   | in  | this    | array      |
   | how | can     | I          |
   | add | special | characters | 

大多数特殊字符都可以,但是引号和管道呢?

special characters example: \|!"#$%&/()=?«»'{}[]'`^~*+ºª-_.:,;<>@ł€¶ŧ←↓→øþĸħŋđðßæ|«»¢“”nµ

谢谢

最佳答案

我知道自发布以来已经过去了一年,但今天遇到了类似的问题,我已经发布了我的解决方案 here .

我在这里复制它以防谷歌群组帖子被删除:

问题

我的 .feature 文件是这样的:

 Then I get a response with "error" equals to "<error>"

 And I get a response with "error" equals to "<error_message>"


 Examples:

 |error                    |  error_message                                                              |

 |NotFoundHttpException    |  Something with quotes "More text here"                     |

如您所见,我正在调用相同的步骤来检查其中一个列包含文本中的引号和另一列不包含引号。

当我运行 Behat 测试时,“这里有更多文本”被作为另一个参数,Behat 建议另一个片段。

解决方案

为了解决这个问题,我们必须使用不同于 "的另一个字符来告诉 Behat 存在一个变量,在我的例子中我使用了单引号。

所以,我已经像这样更改了 .feature:

 Then I get a response with "error" equals to "<error>"

 And I get a response with "error_message" equals to '<error_message>' escaping quotes

 Examples:

 |error                    |  error_message                                                            |

 |NotFoundHttpException    |  Something with quotes "More text here"                     |

然后我更新了我的 php 测试实现,如下所示:

/**
 * @Then I get a response with :attibute equals to :value
 * @Then /^I get a response with "([^"]+)" equals to '([^']+)' escaping quotes$/
 */
public function iGetAResponseWithEqualsTo($attibute, $value)

调用完全相同的实现。

我在阅读 this page 后提出了这个解决方案,以防有人需要。

关于BDD 和 Behat 特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18745962/

相关文章:

selenium - Behat with Selenium Hub和Firefox错误:无法打开连接:从webdriver接收到的有效载荷有效,但意外出现json

testing - 在 Behat 的功能文件中使用占位符

ubuntu - 在 Ubuntu 上安装 Teambox。 Gherkin 2.3.3 安装失败

c# - 哪些行为驱动开发 (BDD) 工具/框架可用于 Microsoft Stack?

python - 生菜、 Django 的背景

php - 如何测试Behat Context?

cucumber - Cucumber 中的可重用/通用示例表

cucumber - 将 cucumber 与 jruby 一起使用

mysql - 使用 UNION 处理重复结果

cucumber - 如何提高 SpecFlow/Gherkin 步骤之间的可重用性?