运行Mocha测试时,如何解决之前的所有错误?

时间:2019-07-25 16:11:44

标签: javascript node.js mocha

该错误最近开始在我的摩卡测试套件中出现,到目前为止,我发现的答案并不能真正帮助理解问题所在。

我得到的错误是:

/var/lib/jenkins/workspace/test_suite/test/integration/adds_image_and_confirms_style_via_edit_button.js
Thu Jul 25 2019 15:46:22 GMT+0000 (utc)
DB Reset complete!
Orgs in database
[ 102 ]
(node:25283) DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.
(node:25283) DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
Entering pin: null
    1) "before all" hook: ret

  0 passing (8s)
  1 failing

  1) Admin adds survey with rich text and confirms style via edit button
 "before all" hook: ret:
     TypeError: each key must be a number of string; got object
      at keys.forEach.key (node_modules/selenium-webdriver/lib/webdriver.js:1971:21)
      at Array.forEach (<anonymous>)
      at Promise.all.then.keys (node_modules/selenium-webdriver/lib/webdriver.js:1966:16)
      at <anonymous>
      at process._tickDomainCallback (internal/process/next_tick.js:228:7)
  From: Task: WebElement.sendKeys()
      at Driver.schedule (node_modules/selenium-webdriver/lib/webdriver.js:414:17)
      at WebElementPromise.schedule_ (node_modules/selenium-webdriver/lib/webdriver.js:1820:25)
      at WebElementPromise.sendKeys (node_modules/selenium-webdriver/lib/webdriver.js:1983:19)
      at test/init.js:115:14
      at node_modules/selenium-webdriver/lib/webdriver.js:753:14
      at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:2736:14)
      at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:2719:21)
      at asyncRun (node_modules/selenium-webdriver/lib/promise.js:2642:25)
      at node_modules/selenium-webdriver/lib/promise.js:639:7
      at <anonymous>
      at process._tickDomainCallback (internal/process/next_tick.js:228:7)
  From: Task: <anonymous>
      at pollCondition (node_modules/selenium-webdriver/lib/promise.js:2178:16)
      at node_modules/selenium-webdriver/lib/promise.js:2174:9
      at new ManagedPromise (node_modules/selenium-webdriver/lib/promise.js:1029:7)
      at node_modules/selenium-webdriver/lib/promise.js:2173:14
      at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:2736:14)
      at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:2719:21)
      at asyncRun (node_modules/selenium-webdriver/lib/promise.js:2595:27)
      at node_modules/selenium-webdriver/lib/promise.js:639:7
      at <anonymous>
      at process._tickDomainCallback (internal/process/next_tick.js:228:7)
  From: Task: <anonymous wait>
      at ControlFlow.wait (node_modules/selenium-webdriver/lib/promise.js:2171:17)
      at Driver.wait (node_modules/selenium-webdriver/lib/webdriver.js:749:29)
      at Object.kTest.customSendKeys (test/init.js:112:25)
      at Object.kTest.enterPin (test/init.js:137:11)
      at test/integration/adds_image_and_confirms_style_via_edit_button.js:93:19
      at ManagedPromise.invokeCallback_ (node_modules/selenium-webdriver/lib/promise.js:1315:14)
      at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:2736:14)
      at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:2719:21)
      at asyncRun (node_modules/selenium-webdriver/lib/promise.js:2595:27)
      at node_modules/selenium-webdriver/lib/promise.js:639:7
      at <anonymous>
      at process._tickDomainCallback (internal/process/next_tick.js:228:7)
  From: Task: Admin adds survey with rich text and confirms style via edit button
   "before all" hook: ret
      at Context.ret (node_modules/selenium-webdriver/testing/index.js:137:10)

看着https://romaklimenko.github.io/curves/docs/mocha.html,我不确定ret是什么,所以我看不出问题出在哪里。测试看起来像这样,但这在其他测试中也会发生,并且这些测试以前还不错,所以不确定如何调试。任何意见将是有益的。我还应该提到这是在我的Jenkins服务器上发生的,并且只有在本地运行测试时才偶尔发生。

Test.describe("Adds image and confirms style via edit button\n", function() {
    this.timeout(mochaTimeOut);

Test.before(function(done) {
    kTest.logFilename(__filename);
    kTest.setup().then(function() {
        return Factory.createA({
            ...
        });
    }).then(function () {
        return Factory.createB({
            ...
        });
    }).then(function () {
        return Factory.createC({
            ...
        });
    }).then(function () {
        return Factory.createD({
            ...
        });
    }).then(function () {
        kTest.login(testVariables.email, testVariables.password);
    }).then(function () {
        var elementSelector = 'h3';
        var element = kTest.driver.findElement(By.css(elementSelector));
        element.getText().then(function(text) {
            assert.equal(text, "Enter your pin");
        });
    }).then(function() {
        return adminDb.Users.findOne({userId: testVariables.userId});
    }).then(function(admin) {
        kTest.enterPin(admin.textPin, testVariables.password);
    }).then(function() {
        var button = kTest.driver.wait(until.elementLocated(By.className('fa-bars')), K_TEST_TIMEOUT);
        button.click();

        kTest.driver.findElement(By.className("side_menu_q")).click();

        kTest.driver.wait(until.elementLocated(By.id("selectOption")), K_TEST_TIMEOUT);
        var elementSelector = "h4";
        var element = kTest.driver.findElement(By.css(elementSelector));
        element.getText().then(function(val) {
            assert.equal(val, "IMAGE NAMES");
        });
    }).then(function() {
        done();
    }).catch(function(err) {
        throw err;
    });
});
...
});

enableTimeouts无效,顺便说一句

Mocha test fails with error from "before all" hook

0 个答案:

没有答案