简体   繁体   English

如何使用capybara和poltergeist检查Javascript错误?

[英]How do I check for Javascript errors using capybara and poltergeist?

I'm trying to figure out how exactly to implement this functionality of Poltergeist into my existing Capybara tests, and I'm not having any luck after reading the documentation here: https://github.com/teampoltergeist/poltergeist 我正在试图弄清楚如何将Poltergeist的这个功能实现到我现有的Capybara测试中,并且在阅读这里的文档后我没有运气: https//github.com/teampoltergeist/poltergeist

I have included the below code, but when I run my tests I'm not seeing any warning about JS errors when I know there are JS errors in the console. 我已经包含了下面的代码,但是当我运行我的测试时,当我知道控制台中存在JS错误时,我没有看到任何关于JS错误的警告。 Am I missing something? 我错过了什么吗? Do I have to pass in a specific command in the terminal in order to make sure this checks for JS errors? 我是否必须在终端中传入特定命令才能确保检查JS错误? Thanks! 谢谢!

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

options = {js_errors: true}
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, options)
end

I ran into your posting after I googled a similar question. 在我搜索了类似的问题后,我遇到了你的帖子。 In my case I had started with webkit as driver in capybara. 在我的情况下,我开始使用webkit作为capybara的驱动程序。 I had read a blog post that suggested the following code , which used "have_errors" matcher to capture any js error. 我读过一篇博文,建议使用以下代码,使用“have_errors”匹配器来捕获任何js错误。

it 'should not have JavaScript errors', js: true do     
 visit(root_path)       
 expect(page).to_not have_errors        
end

In the event you are referring to something similar, you do not need to use any specific method to check when you are using poltergeist. 如果你指的是类似的东西,你不需要使用任何特定的方法来检查你何时使用poltergeist。 You can see my code that shows what I have switched. 你可以看到我的代码,显示我已切换的内容。

https://github.com/alaghu/learn_jquery/compare/dev...1d6be6dfd500 https://github.com/alaghu/learn_jquery/compare/dev...1d6be6dfd500

Basically, every test will automatically check if the page has errors. 基本上,每个测试都会自动检查页面是否有错误。 I only had to introduce js: true in my tests. 我只需要在我的测试中引入js:true。 I have verified this by intentionally erroring js files to validate these tests. 我通过故意错误的js文件来验证这些测试。

Hope this was helpful. 希望这有用。

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

相关问题 在Capybara + Poltergeist中显示javascript backtrace - Showing javascript backtraces in Capybara + Poltergeist 如何使用Selenium或Poltergeist与javascript弹出窗口进行交互? - How do I interact with a javascript popup with Selenium or Poltergeist? 使用Capybara / Poltergeist使用fullcalendar测试拖放 - Testing drag and drop with fullcalendar using Capybara/Poltergeist 如何在Capybara / Poltergeist的页面上运行一个函数? - How to run a function on a page with Capybara/Poltergeist? 自从我开始使用Capybara :: Poltergeist以来,“无法创建线程:资源暂时不可用” - Getting “can't create Thread: Resource temporarily unavailable” since I started using Capybara::Poltergeist 如何在运行时检查javascript或html错误? - How do i check javascript or html errors at runtime? 如何让Capybara / Poltergeist等待js启动导航完成? - How to make Capybara/Poltergeist wait for js initiated navigation to finish? 如何使用Capybara 2.1断言AJAX完成并重定向? - How do I assert AJAX complete and redirect using Capybara 2.1? Javascript如何检查多个等待异步mssql DB请求结果中的错误? - Javascript how do I check multiple await async mssql DB request results for errors? 水豚和Poltergeist的“选择”文本输入 - Capybara and poltergeist 'select' text input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM