本文介绍了有没有一种方法可以使用Rspec / Capybara / Selenium将javascript console.errors打印到终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行rspec时,是否有可能使capybara / selenium报告任何javascript console.error和其他异常返回给rspec?

When I run rspec, is it possible to have capybara/selenium report any javascript console.errors and other exceptions back to rspec?

我有一堆测试失败,但是当我手动测试它时我的应用程序正在运行。在不知道仅在测试期间可能会阻塞我的单页Web应用程序的javascript错误的情况下,很难弄清楚测试失败的原因。

I have a whole bunch of tests failing, but my application is working when I manually test it. Without knowing the javascript errors that are likely blocking my single-page web app only during testing, it's really hard to figure out why the tests are failing.

推荐答案

我不知道这是否会解决这个问题。任何帮助,但您可以尝试切换到Thoughtbot的capybara-webkit驱动程序。它是Selenium的替代品,它没有头,这意味着它不会打开浏览器来运行测试。当我使用此驱动程序运行测试时(在RSpec + Capybara设置中),所有Javascript错误都会与RSpec输出一起内联显示。

I don't know if this will be of any help, but you could try switching over to thoughtbot's capybara-webkit driver. It's an alternative to Selenium that's headless, meaning it doesn't open a browser to run the tests. When I run my tests using this driver (in an RSpec+Capybara setup), all Javascript errors get printed inline with my RSpec output.

我从未尝试过从Selenium到capybara-webkit,所以我不知道在现有项目上这是多么可行。如果您没有对Selenium做任何真正想做的事情,那么过渡可能会非常顺利。但是,如果您希望能够查看在浏览器中运行的测试,或者对Selenium有其他特定需求,那么不幸的是,我的回答将没有太大用处。

I've never tried switching from Selenium to capybara-webkit, so I don't know how feasible this is on an existing project. If you're not doing anything really fancy with Selenium, the transition might be pretty smooth. However, if you depend on being able to watch the tests running in the browser, or have some other specific need for Selenium, then my answer unfortunately won't be of much use.

您可以在此处找到capybara-webkit:

You can find capybara-webkit here: https://github.com/thoughtbot/capybara-webkit

安装它可能很麻烦,因为您需要Qt4库。如果您的系统上尚未安装Qt4,则构建过程可能会花费很长的时间。对我来说,麻烦是值得的。与我尝试过的其他解决方案相比,我更喜欢capybara-webkit。

Getting it installed might be a pain, since you'll need the Qt4 library. If you don't already have Qt4 on your system, the build process can take a long time. For me, it was well worth the trouble. I much prefer capybara-webkit to any other solution I've tried.

这篇关于有没有一种方法可以使用Rspec / Capybara / Selenium将javascript console.errors打印到终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 18:50