Amo*_*tir 2 ruby-on-rails cucumber
我从Cucumber开始,我正在运行这个简单的场景:
Scenario: Creating a project
Given I go to the new project page
And I fill in "Name" with "xxx"
...
Run Code Online (Sandbox Code Playgroud)
新项目表格已经到位,如下所示:
<% form_for (@project) do |f| %>
<%= f.text_field :name %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
如您所见,我没有定义标签(不需要一个).问题是黄瓜没有找到该领域:
鉴于我转到新的项目页面
我填写"名称"和"我需要的东西"#features/step_definitions/web_steps.rb:68无法填写,没有文本字段,文本区域或密码字段,其中包含id,name或标签'名称'找到(Capybara :: ElementNotFound)
但是,如果我添加标签,它会找到它.我发现它有点可疑,它与我给出的相应文本字段的名称不匹配.
怎么了?
谢谢
尝试将黄瓜功能更改为:
Scenario: Creating a project
Given I go to the new project page
And I fill in "project_name" with "xxx"
Run Code Online (Sandbox Code Playgroud)
要么...
Scenario: Creating a project
Given I go to the new project page
And I fill in "project[name]" with "xxx"
Run Code Online (Sandbox Code Playgroud)
这是失败的原因是因为如果你没有标签,capybara(黄瓜使用)会查找该字段的ID或name属性.作为apneadiving提及,您可以通过查看生成的文件的来源来检查这些值.你会看到类似的东西:
<input id="project_name" name="project[name]" type="text">
Run Code Online (Sandbox Code Playgroud)