3

So I have implemented a Cucumberjs data table, however I do not think I have done it right.. Here what I have

this.And(/^If I click the row "([^"]*)" then I should the following nested information$/, function (rowName, data) {
        resultPage.clickRow(rowName);
        data = dataTable.raw();
        return console.log(data);
    });

And my Gherkin step looks like

Then If I click the row "Summary" then I should the following nested information
      | Tax       | 11.50
      | Gratuity  | 4.50
      | Total     | 26.59

right now I am just trying to get this table and print it out to make sure it comes back in the right format, but I get a lexing error and the test wont even start. How can you implement this in Javascript?? I cant seem to find any documentation or examples online for cucumberjs, but of course there are several for java/cucumber.

Also, I understand that the lexing error is related to the fact that it is expecting this to be a scenario outline, and that I did not specify Example: before the table. However, this is not supposed to be a scenario outline. This is supposed to be a data table..

Tree55Topz
  • 1,102
  • 4
  • 20
  • 51
  • What is the error you are getting? – Grasshopper Nov 29 '16 at 17:44
  • Lexing error on the line that my table starts – Tree55Topz Nov 29 '16 at 17:45
  • 1
    One thing I noticed in the table is that you need to end each line with the divider ie '|'. Not sure if that is a copy-paste mistake here. – Grasshopper Nov 29 '16 at 17:51
  • @Grasshopper Oh crap, that did it! No that was my own fault :P It runs now, but I am getting a data.raw is not a function.. same result if I try data.hashes – Tree55Topz Nov 29 '16 at 18:03
  • Not sure about this as never coded in javascript cucumber, but in your code above you are using dataTable.raw() instead of data.raw(). Saying becoz data is the parameter you are using in the function which cucumber will fill in the datatable details. – Grasshopper Nov 29 '16 at 18:07
  • I got it. It was actually because I had changed the function when I was trying to fix it and changed the order of the paramaters. If I keep it at rowName, data it works great. Thanks for your help! – Tree55Topz Nov 29 '16 at 18:10

2 Answers2

4

The answer to this question is actually not very far off from the original question. I was missing the additional '|' on the right side of the table.

Then If I click the row "Summary" then I should the following nested information
      | Tax       | 11.50  |
      | Gratuity  | 4.50   |
      | Total     | 26.59  |

Additionally, ensure that the javascript step definition contains the parameters in order of use. So in this case, the same step definition used in the question is correct

this.And(/^If I click the row "([^"]*)" then I should the following nested information$/, function (rowName, data) {
        resultPage.clickRow(rowName);
        data = dataTable.raw();
        return console.log(data);
    }); 

This was suprisingly easy compared to the examples I saw for cucumber / java. Cucumberjs really needs to improve their documentation..

Tree55Topz
  • 1,102
  • 4
  • 20
  • 51
3

you can check data of table by some inbuilt methods.

(table.rows(),table.hashes(),table.rowsHash())

you can find implementation of above methods at(https://github.com/cucumber/cucumber-js/blob/master/features/data_tables.feature)

Jared Forth
  • 1,577
  • 6
  • 17
  • 32