简体   繁体   English

为什么我的RSpec + Capybara测试无法渲染视图?

[英]Why is my RSpec + Capybara test failing to render view?

I use wicked (1.3.1) (not sure if relevant) for an onboarding flow on my rails 5 app. 我将wicked(1.3.1)(不确定是否相关)用于我的Rails 5应用程序的入职流程。 On the last step of my onboarding process, there is an <a> link that navigates to a user#dashboard page . 在入门过程的最后一步,有一个<a>链接导航到user#dashboard page

This works totally fine in all browsers. 这在所有浏览器中都可以正常工作。 For some reason that transition does not work in Capybara (rspec 3.7, rspec-rails 3.7.2, Capybara 2.14). 由于某种原因,过渡在Capybara中不起作用(rspec 3.7,rspec-rails 3.7.2,Capybara 2.14)。 The url changes in the automated browser to the desired route, but the page does not render any content, it retains the old view. 网址在自动浏览器中更改为所需的路线,但是页面未呈现任何内容,它保留了旧视图。 Visually its as if someone typed in a url but did not press return, however, the controller method and view are getting touched when i debug them. 从视觉上看,好像有人键入了一个url但没有按回车键,但是,当我调试它们时,控制器的方法和视图变得很动人。 They appear to return a rendering, but the value is not rendered in the browser 它们似乎返回一个渲染,但该值未在浏览器中渲染

If i throw a sleep in my test after the <a> click, I can manually click on the url bar, press return (to navigate to the correct url) and the page will render then. 如果单击<a>后在测试中进入睡眠状态,则可以手动单击url栏,按回车键(导航到正确的url),然后页面将呈现。 But not on its own. 但不是靠它自己。 Anyone experience this before? 有人以前经历过吗?

I have tried changing the href to a different path to see if it is a problem with the target view/controller - it is not, happens to all of the paths I try. 我尝试将href更改为其他路径,以查看目标视图/控制器是否存在问题-并非如此,所有尝试的路径都发生了。 I have also tried different capybara drivers: :selenium , :chrome , :poltergeist . 我还尝试了不同的水豚驱动程序:selenium:chrome:poltergeist All same result! 都是一样的结果!

Would love to provide more detail but i'm not sure what to show. 很想提供更多细节,但我不确定要显示什么。 Its a simple href and i'm not sure what could go wrong. 它是一个简单的href,我不确定会出什么问题。

Cheers 干杯

EDIT: turns out there was an error in the logs. 编辑:事实证明日志中有错误。 Will update with a solution. 将更新一个解决方案。

error: 错误:

Could not log "render_template.action_view" event. NoMethodError: undefined method `render_views?' for RSpec::ExampleGroups::LayoutsSplash::View:Class ["/Users/mitchellmeyer/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:732:in `method_missing'",

The error shown in the logs is a know rspec/rspec-rails 3.6 issue - upgrading will fix that. 日志中显示的错误是已知的rspec / rspec-rails 3.6问题-升级将解决该问题。 Beyond that, the fact it works when a URL is submitted manually to the browser but not when clicking on the link indicates the link is probably being interfered with by JS. 除此之外,当将URL手动提交给浏览器而不是单击链接时,该链接仍然有效,这表明该链接可能受到JS的干扰。 Most likely that's Turbolinks which you can disable for a given link by adding a data-turbolinks=“false” attribute to the link. 最有可能是Turbolinks,您可以通过为链接添加data-turbolinks=“false”属性来禁用给定链接。 If that fixes the behavior (which you state it did) then it's probable you have a JS error in one of your files. 如果这样可以解决问题(如您所说的那样),则可能是其中一个文件出现JS错误。 Check the developer console in the browser for any errors shown and fix them. 在浏览器中检查开发人员控制台,以查看显示的所有错误并进行修复。

Since you mention Poltergeist, as a driver you tried, in your question it's possible for there to be silent errors that cause JS to fail when using it since it doesn't support anything beyond ES 5.1 so it's not really that suitable for testing modern webapps any more and I would recommend sticking to headless chrome if you need headless testing. 既然您提到了Poltergeist,作为您尝试过的驱动程序,在您的问题中可能会出现无声错误,从而导致JS在使用时失败,因为它不支持ES 5.1以外的任何功能,因此它实际上不适合测试现代Web应用程序如果有更多需要,我建议您坚持使用无头铬。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM