使用水豚的黄瓜 web_step#follow 会产生 NameError
有谁知道为什么当我使用 web_step#follow 方法时出现以下错误?
When I follow "Stuff" within "#main-nav" # features/step_definitions/web_steps.rb:33
undefined local variable or method `node' for #<Capybara::Driver::RackTest::Node:0x00000101409b40> (NameError)
./features/step_definitions/web_steps.rb:35:in `block (2 levels) in <top (required)>'
./features/step_definitions/web_steps.rb:14:in `block in with_scope'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'
这是 html 输出:
<ul id='main-nav'>
<li><a href="/things">Things</a></li>
<li><a href="/stuff">Stuff</a></li>
</ul>
PS 我已经删除了 webrat 并且仅使用 capybara
提前致谢!
Does anyone know why I get the following error when I use the web_step#follow method?
When I follow "Stuff" within "#main-nav" # features/step_definitions/web_steps.rb:33
undefined local variable or method `node' for #<Capybara::Driver::RackTest::Node:0x00000101409b40> (NameError)
./features/step_definitions/web_steps.rb:35:in `block (2 levels) in <top (required)>'
./features/step_definitions/web_steps.rb:14:in `block in with_scope'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'
This is the html output:
<ul id='main-nav'>
<li><a href="/things">Things</a></li>
<li><a href="/stuff">Stuff</a></li>
</ul>
P.S. I have removed webrat and am solely using capybara
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
per: https://github.com/jnicklas/capybara/issues/110
注释掉
env.rb
中的这一行:require 'cucumber/rails/capybara_javascript_emulation'
注意:注释该行后,您必须使用
显式标记您的功能/场景@javascript
如果您想使用 onclick javascript 处理程序单击链接。另请参阅:https://github.com/aslakhellesoy/cucumber-rails/issues/77< /a> 最终会带您踏上一段旅程,发现它应该在
cucumber-rails v0.4.0
(2011-03-20) 中修复。对于使用cucumber-rails v0.3.2
的Rails 2.3.x
项目的人来说,这可能仍然相关per: https://github.com/jnicklas/capybara/issues/110
comment out this line in
env.rb
:require 'cucumber/rails/capybara_javascript_emulation'
Note: after commenting that line you'll have to explicitly tag your features/scenarios with
@javascript
if you want to click links with onclick javascript handlers.See also: https://github.com/aslakhellesoy/cucumber-rails/issues/77 which eventually takes you on a journey to discover it should be fixed in
cucumber-rails v0.4.0
(2011-03-20). This may still be relevant for folks withRails 2.3.x
projects usingcucumber-rails v0.3.2
这意味着页面的实际输出不包含您尝试搜索的元素。例如,如果您有
with_scope("#my_div")
,但您的内容没有任何 ID 为my_div
的 div,则会引发此异常。我建议尝试在失败步骤之前添加一个黄瓜步骤
Then show me the page
,并调查生成页面的来源。This means that the actual output of your page does not include the element you're trying to search for. For example, if you had
with_scope("#my_div")
but your content didn't have any divs with the idmy_div
it would raise this exception.I'd suggest trying to add a cucumber step of
Then show me the page
before the failing step, and investigate the source of the generated page.