简体   繁体   English

使用 selenium webdriverjs 运行 mocha 测试时调用堆栈不是很有帮助

[英]Not very helpful callstack when running a mocha test using selenium webdriverjs

When running a test in mocha using the selenium webdriver for JavaScript the call-stack it not really helpful.当使用 selenium webdriver for JavaScript 在 mocha 中运行测试时,调用堆栈并不是很有帮助。

As a simple example I've used the following simple test script test.js :作为一个简单的例子,我使用了以下简单的测试脚本test.js

var webdriver = require('selenium-webdriver'),
    test = require('selenium-webdriver/testing');

const TIMEOUT = 30000;

test.describe('selenium webdriverjs', function () {
    var driver;

    this.timeout(TIMEOUT);

    test.before(function () {
        driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.firefox()).build();
        driver.manage().timeouts().pageLoadTimeout(TIMEOUT);
    });

    test.after(function () {
        driver.quit();
    });

    test.it('error stack', function () {
        driver.get('http://www.google.com');
        driver.findElement(webdriver.By.id('doesnotexit'));
    });
});

that generates the following error stack when (for example) run from Gulp:当(例如)从 Gulp 运行时会生成以下错误堆栈:

  selenium webdriverjs
    1) error stack


  0 passing (4s)
  1 failing

  1) selenium webdriverjs error stack:
     NoSuchElementError: Unable to locate element: {"method":"id","selector":"doesnotexit"}
      at new bot.Error (...\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
      at Object.bot.response.checkResponse (...\node_modules\selenium-webdriver\lib\atoms\response.js:109:9)
      at ...\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:379:20
      at promise.Promise.goog.defineClass.invokeCallback_ (.../node_modules/selenium-webdriver/lib/goog/../webdriver/promise.
js:1337:14)
      at promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (.../node_modules/selenium-
webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (.../node_modules/selenium-webdriver
/lib/goog/../webdriver/promise.js:2758:21)
      at goog.async.run.processWorkQueue (...\node_modules\selenium-webdriver\lib\goog\async\run.js:124:15)
  From: Task: selenium webdriverjs error stack
      at Context.ret (...\node_modules\selenium-webdriver\testing\index.js:128:10)
      at callFnAsync (...\node_modules\mocha\lib\runnable.js:306:8)
      at Test.Runnable.run (...\node_modules\mocha\lib\runnable.js:261:7)
      at Runner.runTest (...\node_modules\mocha\lib\runner.js:421:10)
      at ...\node_modules\mocha\lib\runner.js:528:12
      at next (...\node_modules\mocha\lib\runner.js:341:14)
      at ...\node_modules\mocha\lib\runner.js:351:7
      at next (...\node_modules\mocha\lib\runner.js:283:14)
      at Immediate._onImmediate (...\node_modules\mocha\lib\runner.js:319:5)

The stack consists of a series of deeply nested function in the mocha and selenium libraries of the local node_modules directory and actual test script test.js is not even part of the stack.该堆栈由本地node_modules目录的mochaselenium库中的一系列深度嵌套函数组成,实际测试脚本test.js甚至不属于堆栈的一部分。

I'm wondering, if this is really the best information I can get from this setup if I just did something wrong?我想知道,如果我做错了什么,这是否真的是我可以从这个设置中获得的最佳信息?

Yes, this is really too much unnecessary and not really helpful information with all of the meaningless async traceback cruft, but the most important part of it, the webdriver error itself, is on top and is pretty self-descriptive :是的,对于所有无意义的异步回溯,这确实是太多不必要且没有真正有用的信息,但其中最重要的部分,即 webdriver 错误本身,位于最重要的部分,并且非常具有自我描述性

NoSuchElementError: Unable to locate element: {"method":"id","selector":"doesnotexit"} NoSuchElementError:无法定位元素:{"method":"id","selector":"doesnotexit"}

You may try to clean up the output with the help of mocha-clean package.您可以尝试在mocha-clean包的帮助下mocha-clean输出。 When applied, it should really leave the error message itself and only relevant parts of the stack trace eliminating everything mocha - and selenium-webdriver -specific:应用时,它应该真正留下错误消息本身,并且只保留堆栈跟踪的相关部分,消除所有mocha - 和selenium-webdriver -specific:

Mocha stack traces are riddled with frames that you don't want to see, like code from modules and Mocha internals. Mocha 堆栈跟踪中充斥着您不想看到的帧,例如来自模块和 Mocha 内部的代码。 It strips away mocha internals, node_modules, absolute paths (based on cwd), and other unneccessary cruft.它剥离了 mocha 内部结构、node_modules、绝对路径(基于 cwd)和其他不必要的杂物。

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

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