水豚:fill_in 动作定位器
所以我有这个规范
describe "visit /signup" do
before(:each) do
get signup_path
end
it "has an email input field" do
page.has_field?("#user_email")
end
it "accepts an email address" do
page.fill_in('#user_email', :with=>Faker::Internet.email)
end
end
第一个测试(有电子邮件输入)通过,第二个测试失败,
Failure/Error: page.fill_in('#user_email', :with=>Faker::Internet.email)
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label '#user_email' found
输入[type ='text']元素存在于具有该DOM ID的页面上,已尝试使用带或不带散列的ID进行定位,并使用其 input:name 作为定位器。
我做错了什么?
So I have this spec
describe "visit /signup" do
before(:each) do
get signup_path
end
it "has an email input field" do
page.has_field?("#user_email")
end
it "accepts an email address" do
page.fill_in('#user_email', :with=>Faker::Internet.email)
end
end
The first test (has an email input) passes, the second fails with
Failure/Error: page.fill_in('#user_email', :with=>Faker::Internet.email)
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label '#user_email' found
The input[type='text'] element exists on the page with that DOM ID, have tried locating with the ID with and without the hash, and using its input:name as a locator too.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是因为当您应该在
before
块内使用visit
时,您却使用了get
。这:应该是这样:
否则你是在告诉
Rack::Test
访问该路径,而不是水豚!一个小小的区别经常让很多人绊倒!It's because you're using
get
when you should be usingvisit
inside thebefore
block. This:Should be this:
Otherwise you're telling
Rack::Test
to visit that path, not Capybara! A small distinction that trips quite a few people up frequently!也许你应该删除
#
,例如maybe you should remove the
#
, e.g.我认为 fill_in 不在页面上。只需使用 fill_in:
I think fill_in is not on page. Just use fill_in: