清理量角器堆栈跟踪 [英] Cleaning up Protractor stack trace
问题描述
问题:
是否可以清理堆栈跟踪并仅保留相关的框架以消除所有内容量角器
, WebDriverJS
和 Jasmine
具体?
Is it possible to clean up the stack trace and leave only relevant frames eliminating everything Protractor
, WebDriverJS
and Jasmine
specific?
故事:
让我们执行此示例测试:
Let's execute this example test:
describe("SO test", function () {
beforeEach(function () {
browser.get("https://angularjs.org");
});
it("should throw a meaningful error", function () {
element(by.id("not_found")).click();
});
});
以下堆栈跟踪会失败:
SO test should throw a meaningful error
- Failed: No element found using locator: By.id("not_found")
at new bot.Error (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:108:18)
at /usr/local/lib/node_modules/protractor/lib/element.js:676:15
at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
at goog.async.run.processWorkQueue (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:124:15)
at process._tickCallback (node.js:377:9)
Error
at [object Object].ElementArrayFinder.applyAction_ (/usr/local/lib/node_modules/protractor/lib/element.js:382:21)
at [object Object].ElementArrayFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.js:78:17)
at [object Object].ElementFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.js:711:7)
at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:9:37)
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:96:23
at [object Object].promise.Promise.goog.defineClass.constructor (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1056:7)
at new wrappedCtr (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:2468:26)
at controlFlowExecute (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:82:18)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
From: Task: Run it("should throw a meaningful error") in control flow
at Object.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:81:14)
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:18:5
at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
at goog.async.run.processWorkQueue (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:124:15)
From asynchronous test:
Error
at Suite.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:8:5)
at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:3:1)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
正如您所看到的,在测试中找到错误实际发生的位置并不容易。它隐藏在由 Protractor
, WebDriverJS
和 Jasmine $ c覆盖的堆栈跟踪内的某处$ c>堆栈帧。这使得调试和开发端到端测试变得困难。
As you can see, it's not easy to find on which line in the test the error actually happened. It's hidden somewhere inside the stack trace covered by Protractor
, WebDriverJS
and Jasmine
stack frames. This makes it difficult to debug and develop end-to-end tests.
期望的输出:
SO test should throw a meaningful error
- Failed: No element found using locator: By.id("not_found")
at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:9:37)
From asynchronous test:
Error
at Suite.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:8:5)
at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:3:1)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
使用量角器
3.0.0和 jasmine2
。
mocha
世界上有一个相关的 mocha-clean
包过滤掉来自 node_modules
和 mocha
内部的所有内容,留下干净的堆栈跟踪易于阅读。
In mocha
world, there is a relevant mocha-clean
package that filters out everything coming from inside node_modules
and mocha
itself leaving a clean stack trace that is easy to read.
推荐答案
事实证明,如果你使用任何自定义记者,他们可能会引入新的行为控制堆栈跟踪的输出。 Protractor本身隐藏了很多东西,所以你不会看到来自node_modules或Jasmine的任何日志条目。
As it turns out, if you use any custom reporters, they may introduce new behavior in controlling output of a stack trace. Protractor itself hides pretty much everything, so you won't see any log entries from node_modules or Jasmine.
当你使用 jasmine-spec-reporter ,它提供了控制堆栈跟踪的选项,可能就是这样,你设置了一些详细模式在选项中。在 Protractor的文档中某些原因建议使用所有
模式,它基本上显示enitre堆栈跟踪。
As you use jasmine-spec-reporter, which provides an option to control a stack trace, it might be the case, that you have set some verbose mode in the options. In the docs for Protractor for some reason it is suggested to use all
mode, which basically displays the enitre stack trace.
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
}
}));
如果您只是更改 displayStacktrace
选项所有
到无
,你应该得到干净的结果,没有任何堆栈痕迹。还有选项摘要
和 specs
。您可能没有注意到它们之间的区别,但如果您在套件中添加更多规格,那么您将能够看到差异:
If you simply change the option displayStacktrace
from all
to none
, you should get clean results without any stack traces. There are also options summary
and specs
. You might not notice the difference between them in your example, but if you add a few more specs in your suite, then you'll be able to see the difference:
-
specs
- 如果规范在运行测试过程中失败,你会在规范失败消息后立即看到它的堆栈跟踪 -
summary
- 如果规范在运行测试过程中失败,你不会看到它的堆栈跟踪在规范失败消息之后立即执行,但在所有测试结束时您将获得所有堆栈跟踪列表中的失败规范 -
all
- 结合specs
和摘要
- 如果规范在运行测试过程中失败,你会看到一个堆栈在规范失败消息后立即跟踪和,您将在所有测试结束时获得失败规格的所有堆栈跟踪列表 -
none
- 堆栈跟踪不会显示在任何地方
specs
- if spec fails in the process of running tests, you'll see a stack trace for it immediately after a spec failure messagesummary
- if spec fails in the process of running tests, you'll not see a stack trace for it immediately after a spec failure message, but you'll get a list of all stack traces for failed specs in the end of all testsall
- combinesspecs
andsummary
- if spec fails in the process of running tests, you'll see a stack trace for it immediately after a spec failure message and you'll get a list of all stack traces for failed specs in the end of all testsnone
- stack traces won't be shown anywhere
这篇关于清理量角器堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!