elute
elute

Reputation: 1

How to access params of example/template data table (cucumber)?

We use codeceptjs with cucumber for api tests. In the test steps we decided to use a docstring to hand over variables instead of a data tables. Now the creation of a Scenario Outline (cucumber style) presents us with some challenges. In the example/template data table we have some variables. Some of them we want to call in the docstring. But the normal usage (<example>) didn't work. So, is there any other possibility to access this variables?

Example for better understanding (cucumber scenario):

Scenario Outline: Send message
    Given I build a message "important"
      """
      {
      "foo": "Clark Kent",
      "bar": "<profile>"
      }
      """
    When I receive this message
    And I execute needed cronjobs to process incoming message
    Then I verify the correct processing

    Examples:
      | profile  |
      | private  |
      | business |

I googled for a long time. For rust is especially explained the replacing is working in a docstring, as well. I tried to find a global variable, where the example/template variables maybe can be found. So as there is existing e.g. "process.url" for other example of use. The idea to find this variable is only to build my own handover function. In my opinion there has to be a possibility to reach the access to this information, because in the log of the current running test execution I can read the taken variable of the data table of example/template:

  Send message {"profile":"private""}

Upvotes: 0

Views: 43

Answers (1)

elute
elute

Reputation: 1

I found out that the example/template variables you can find in the "test.title" in a before hook ("codecept.event.test.before). Something like:

codecept.event.dispatcher.on(codecept.event.test.before, async function (test): Promise<void> {
  const scenarioName = test.title;
  console.log(scenarioName);
}

Then only you have to dig out the needed info of the string.

Upvotes: 0

Related Questions