黄瓜、水豚和 ElementNotFound
在我的 Rails 应用程序中,我有一个带有执行 javascript 函数的链接的页面:
<%= link_to_function("Add an address", "add_fields(this)".html_safe) %>
在我的黄瓜功能中,我有:
And I press "Add an address"
我得到的消息是:
Capybara::ElementNotFound: no button with value or id or text 'Add an address' found
我可能丢失了一些东西,但我找不到它是什么..
In my rails application, I have a page with a link that execute a javascript function :
<%= link_to_function("Add an address", "add_fields(this)".html_safe) %>
In my cucumber feature I have :
And I press "Add an address"
And the message I get is :
Capybara::ElementNotFound: no button with value or id or text 'Add an address' found
I'm probably missing something, but I can't find what it is..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该执行以下操作中的一项且仅执行一项:
向您的按钮添加一个 id,并更改测试,例如这个:
查看
= f.submit '保存', :id => :foo
测试
我按“foo”
You should do one, and only one, of the following:
Add to your button an id, and also change the test, like this:
view
= f.submit 'Save', :id => :foo
test
And I press "foo"
由 joaomilho 解决:
您应该执行以下操作中的一项且仅执行一项:
将提交按钮重命名为“创建”
将您的测试更改为“然后我按“保存””
向按钮添加一个 id,并更改测试,如下所示
:
= f.submit '保存', :id => :foo
测试
我按“foo”
1个场景(1个通过)
3步(3步通过)
0m2.510s
这里有同样的行为,我正在使用:
Rails 3 Cucumber/Capybara/Haml
步骤:
查看新内容:
错误:
_form:
Solved by joaomilho:
You should do one, and only one, of the following:
Rename your submit button to 'Create'
Change your test to 'And I press "Save"'
Add to your button an id, and also change the test, like this:
view
= f.submit 'Save', :id => :foo
test
And I press "foo"
1 scenario (1 passed)
3 steps (3 passed)
0m2.510s
Same behavior here, I'm using:
Rails 3 Cucumber/Capybara/Haml
Step:
View New:
Error:
_form:
我相信你想要
I believe you want
Sebastian:尝试向您的链接添加一个 ID,并在测试中引用它。
Sebastian: Try to add an id to your link, and reference it in your test.
最初的问题不是您创建链接但尝试按按钮吗?
仔细阅读水豚文档,你会发现方法是不同的。
Wasn't the original problem that you were creating a link but trying to press a button?
Read the capybara docs carefully, and you'll see the methods are different.