我在我的Symfony2项目中使用Behat和Mink进行集成测试,并且在整个网站上使用了以下语法并取得了成功,但在一个地方我发现了一些看起来没有任何意义的奇怪错误(对于我):
方案如下:
Scenario: I can create a new event
Given I am on "/event/new"
When I fill in the following:
| Title | Test Event |
| Event Details | Description |
And I check the "Active" option for "Published"
And I press "Save"
Then I should see "New event posted successfully!"
我收到以下错误:
Form submit button for field with xpath
"(//html/.//*[self::input | self::textarea | self::select][not(./@type = 'submit'
or ./@type = 'image' or ./@type = 'hidden')][(((./@id = 'Title' or ./@name = 'Title')
or ./@id = //label[contains(normalize-space(string(.)), 'Title')]/@for) or
./@placeholder = 'Title')] | .//label[contains(normalize-space(string(.)),
'Title')]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or
./@type = 'image' or ./@type = 'hidden')])[1]"not found
In step `And I fill in the following:'.
所以我认为" Title"字段,但错误消息暗示它正在寻找提交按钮!?如果我将场景中的字段名称更改为不存在的字段名称,则会得到预期的(并且更具可读性)"字段未找到"错误信息。
答案 0 :(得分:3)
似乎包含了html片段:
var errorString = '<div class="help-inline time-error">Please select a valid time for your event</div>';
在表单中的javascript部分搞砸了DOM解析 - 将div内容放在实际表单中并用css隐藏它,然后使用jquery选择器将它放在我希望它工作的地方!