1

我在我的 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:'.

所以我认为它在“标题”字段上出错,但错误消息暗示它正在寻找提交按钮!?如果我将场景中的字段名称更改为不存在的名称,我会收到预期的(并且更具可读性)“未找到字段”错误消息。

4

1 回答 1

3

似乎包括html片段:

var errorString = '<div class="help-inline time-error">Please select a valid time for your event</div>';

在表单中的 javascript 部分搞砸了 DOM 解析 - 将 div 内容放在实际表单中并用 css 隐藏它,然后使用 jquery 选择器将它放在我想要它工作的地方!

于 2013-05-17T12:35:52.507 回答