【问题标题】:Cucumberjs Data Tables - How to turn it to .raw()Cucumberjs 数据表 - 如何将其转换为 .raw()
【发布时间】:2020-10-07 00:22:35
【问题描述】:

所以我已经实现了一个 Cucumberjs 数据表,但是我认为我做得不对.. 这是我所拥有的

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

我的小黄瓜步骤看起来像

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

现在我只是想获取这张表并将其打印出来以确保它以正确的格式返回,但我收到了一个词法错误,甚至无法开始测试。你怎么能在Javascript中实现这个?我似乎无法在网上找到任何 cucumberjs 的文档或示例,但当然有几个适用于 java/cucumber。

另外,我知道词法分析错误与它预期这是一个场景大纲的事实有关,并且我没有在表格之前指定 Example:。但是,这不应该是一个场景大纲。这应该是一个数据表..

【问题讨论】:

  • 您遇到的错误是什么?
  • 我的表格开始行的词法错误
  • 我在表格中注意到的一件事是您需要以分隔符结束每一行,即“|”。不确定这是否是复制粘贴错误。
  • @Grasshopper 哦,废话,做到了!不,那是我自己的错:P 它现在运行,但我得到一个 data.raw 不是一个函数。如果我尝试 data.hashes,结果相同
  • 不确定这一点,因为它从未在 javascript cucumber 中编码,但在您上面的代码中,您使用的是 dataTable.raw() 而不是 data.raw()。说 becoz data 是您在黄瓜将填写数据表详细信息的函数中使用的参数。

标签: javascript protractor cucumber cucumberjs


【解决方案1】:

这个问题的答案其实和原来的问题相差不远。我错过了额外的“|”在桌子的右边。

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

另外,请确保 javascript 步骤定义包含按使用顺序排列的参数。所以在这种情况下,问题中使用的相同步骤定义是正确的

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

与我看到的 cucumber / java 示例相比,这非常容易。 Cucumberjs 确实需要改进他们的文档..

【讨论】:

  • Cucumberjs 确实需要改进他们的文档。真的
【解决方案2】:

你可以通过一些内置的方法查看表格的数据。

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

你可以在(https://github.com/cucumber/cucumber-js/blob/master/features/data_tables.feature)找到上述方法的实现

【讨论】:

    猜你喜欢
    • 2016-04-18
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 2014-10-30
    • 2022-07-30
    • 2012-04-11
    相关资源
    最近更新 更多