Search code examples
datatablegherkincodeceptjs

Gherkin test using table fails with error "Cannot read property 'bold' of undefined"


Using codeceptJs 2.1.1 with Gherkin 5.1.0 french test I'm trying to check all the fields are present in a form using a datable to provide fields name.

Here is the Gherkin test:

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

Here is the corresponding step:

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

Here is the stack trace:

$ 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

Solution

  • Using node inspector I was able to see further in the trace. Add the argument --node-arg=--inspect-brk to tyou command

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

    Then open nodejsinspector from your chrome devtools by clicking the node icon:

    enter image description here

    As for the "bold of undefined" error it

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

    About the received variables I could see the test in fact receives an object containing the array of values and not actual value. The actual value is accessible like this:

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

    so you have to loop manually in the array you receive to get each value and test it

    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;
    });