Rails 5/6 系统测试未找到输入字段
Rails 5/6 System test not finding input field
我使用 Capybara 进行的 Rails 6 系统测试没有在我的 haml 代码中找到 text_field 输入:
.form-group
= f.label :summary
= f.text_field :summary, placeholder: 'A brief 2-3 lines summarizing your idea', class: 'form-control summary'
有测试:
fill_in "Summary", with: "Some generic text"
我收到以下错误:
Error:
ActivitiesTest#test_creating_an_activity:
Capybara::ElementNotFound: Unable to find field "Summary" that is not disabled
test/system/activities_test.rb:20:in `block in <class:ActivitiesTest>'
事实证明,如果您使用占位符,则必须对该文本执行 fill_in:
fill_in "A brief 2-3 lines summarizing your idea", with: "Some generic text"
它会起作用。
我使用 Capybara 进行的 Rails 6 系统测试没有在我的 haml 代码中找到 text_field 输入:
.form-group
= f.label :summary
= f.text_field :summary, placeholder: 'A brief 2-3 lines summarizing your idea', class: 'form-control summary'
有测试:
fill_in "Summary", with: "Some generic text"
我收到以下错误:
Error:
ActivitiesTest#test_creating_an_activity:
Capybara::ElementNotFound: Unable to find field "Summary" that is not disabled
test/system/activities_test.rb:20:in `block in <class:ActivitiesTest>'
事实证明,如果您使用占位符,则必须对该文本执行 fill_in:
fill_in "A brief 2-3 lines summarizing your idea", with: "Some generic text"
它会起作用。