【问题标题】:Gherkin test using table fails with error "Cannot read property 'bold' of undefined"使用表的 Gherkin 测试失败并出现错误“无法读取未定义的属性‘粗体’”
【发布时间】:2019-09-28 19:16:03
【问题描述】:

使用 codeceptJs 2.1.1 和 Gherkin 5.1.0 法语测试我正在尝试检查所有字段是否存在于使用数据表提供字段名称的表单中。

这里是小黄瓜测试:

@tabletest
Scénario: Les champs
Alors je vois les champs :
| coteComplete   |
| typeOptionCote |

下面是对应的步骤:

Then('je vois les champs( de saisie) :', (name) => {
  I.say('name', name);
  I.seeElement(`input[name=${name}], select[name=${name}], textearea[name=${name}]`);
});

这是堆栈跟踪:

$ npx codeceptjs run --grep "tabletest" --debug --verbose
CodeceptJS v2.1.1
Using test root "C:\PISTARD\diffusion\dev\pistard-diffusion"
Helpers: Protractor
Plugins: screenshotOnFail, wdio

Recherche par cote @PDIFF-56 --
    Emitted | suite.before ([object Object])
 » Started SeleniumStandaloneLauncher
 » [Session] Starting singleton browser session
  Les champs @tabletest
    Emitted | test.before ([object Object])
    Emitted | hook.start ([object Object])
    Emitted | step.before (I am on page "recherche-avancee")
    Emitted | step.after (I am on page "recherche-avancee")
    Emitted | step.start (I am on page "recherche-avancee")
    Etant donné que je suis sur la page "recherche avancee"
      I am on page "recherche-avancee"
      » Visited http://localhost:4200/recherche-avancee
    Emitted | step.passed (I am on page "recherche-avancee")
    Emitted | step.finish (I am on page "recherche-avancee")
    Emitted | hook.passed ([object Object])
    Emitted | test.start ([object Object])
    [1] Error | TypeError: Cannot read property 'bold' of undefined
    [1] Starting <teardown> session
    Emitted | test.failed ([object Object])
    Emitted | test.finish ([object Object])
    [1] <teardown> Stopping recording promises
 » <screenshotOnFail> Test failed, saving screenshot
 » Screenshot has been saved to C:\PISTARD\diffusion\dev\pistard-diffusion\codeceptjs-output\Les_champs_1557763592.failed.png
  × FAILED in 287ms

    [2] Starting recording promises
    Emitted | test.after ([object Object])
    Emitted | suite.after ([object Object])

-- FAILURES:

  1) Recherche par cote @PDIFF-56
       Les champs @tabletest:
     Cannot read property 'bold' of undefined
  ypeError: Cannot read property 'bold' of undefined
      at Object.say (node_modules\codeceptjs\lib\output.js:139:53)
      at recorder.add (node_modules\codeceptjs\lib\actor.js:40:78)
      at process.internalTickCallback (internal/process/next_tick.js:77:7)


  FAIL  | 0 passed, 1 failed   // 5s
    Emitted | global.result ([object Object])
    Emitted | global.after ([object Object])
 » Stopped SeleniumStandaloneLauncher

【问题讨论】:

    标签: datatable gherkin codeceptjs


    【解决方案1】:

    使用节点检查器,我可以在跟踪中进一步查看。 将参数--node-arg=--inspect-brk 添加到你的命令

    npx --node-arg=--inspect-brk codeceptjs run --grep "tabletest" --debug 
    

    然后通过单击节点图标从您的 chrome devtools 中打开 nodejsinspector:

    至于"bold of undefined"报错吧

    I.say("InputName:" + name);
    

    关于接收到的变量,我可以看到测试实际上接收到一个包含值数组而不是实际值的对象。实际值可以这样访问:

    let name = dataTest.rows[0].cells[0].value
    

    因此您必须在收到的数组中手动​​循环以获取每个值并对其进行测试

    Then('je vois les champs( de saisie)( :)', (dataTest) => {
      let name;
      dataTest.rows.forEach(element => {
        name = element.cells[0].value;
        I.seeElement(`input[name=${name}], select[name=${name}], textearea[name=${name}]`);
      });
      debugger;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-08
      • 2022-06-22
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 2023-01-09
      相关资源
      最近更新 更多