简体   繁体   English

如何使用Poltergeist / Capybara / Rspec记录JavaScript错误?

[英]How can I log javascript errors with Poltergeist/Capybara/Rspec?

I'm using Rspec/Capybara with Poltergeist as a driver to write tests for some large web applications. 我使用带有Poltergeist的Rspec / Capybara作为驱动程序来为一些大型Web应用程序编写测试。

My issue is that I would like to record the messages that appear on the console, but so far I've been unable to do so. 我的问题是我想记录出现在控制台上的消息,但是到目前为止,我还没有这样做。

I am aware of the options js_errors and phantomjs_logger , but I have had some issues with them: 我知道选项js_errorsphantomjs_logger ,但是它们有一些问题:

  • if I set js_errors: false , the file I specify in phantomjs_logger stays empty; 如果我设置js_errors: false ,那么我在phantomjs_logger指定的文件将保持为空;
  • if I set js_errors: true , console.log messages are logged in the file specified in phantomjs_logger , but then almost all my specs fail because of javascript errors that may not even be relevant to the navigation example I'm testing. 如果我将js_errors: true设置为console.log消息,则将其记录在phantomjs_logger指定的文件中,但是由于JavaScript错误可能几乎与我正在测试的导航示例都不相关,因此几乎所有规格都失败了。

Any idea on how I can save the console messages while not breaking specs on every js error? 关于如何在不破坏每个js错误规范的情况下如何保存控制台消息的任何想法吗?

CLARIFICATION: I have no control over the development, my task is to check the stability of the whole stack of the applications in the various environments, accessing from the front-end, so clearing out all the javascript errors is out of the question. 澄清:我无法控制开发,我的任务是检查从前端访问的各种环境中应用程序整个堆栈的稳定性,因此清除所有JavaScript错误是不可能的。 The specs I'm writing are also supposed to ignore javascript errors if they don't impair the usage of the interface. 如果我编写的规范不影响接口的使用,则应该忽略它们。

You can't. 你不能 The PhantomJS client catches javascript error messages and adds them to an array. PhantomJS客户端捕获javascript错误消息并将其添加到数组中。 Then when a command completes, if js_errors == true, that array is checked and if not empty the javascript errors are returned and trigger an error in the test. 然后,当命令完成时,如果js_errors == true,则检查该数组,如果不为空,则返回javascript错误并在测试中触发错误。 There is no other API in poltergeist for accessing those errors. poltergeist中没有其他API可以访问这些错误。 It sounds like you need to have a discussion with your manager about the wisdom of just ignoring JS errors if they apparently don't impair usage - it's a potentially dangerous development practice 听起来您需要与您的经理进行讨论,以了解如果JS错误显然不影响使用率的情况下就忽略JS错误的智慧-这是一种潜在的危险开发实践

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

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