使用水豚的黄瓜 web_step#follow 会产生 NameError

发布于 2024-10-29 08:30:14 字数 884 浏览 1 评论 0原文

有谁知道为什么当我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┊风居住的梦幻卍 2024-11-05 08:30:14

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.2Rails 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 with Rails 2.3.x projects using cucumber-rails v0.3.2

守望孤独 2024-11-05 08:30:14

这意味着页面的实际输出不包含您尝试搜索的元素。例如,如果您有 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 id my_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文