[英]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.