【问题标题】:cucumber webdriverio datatable黄瓜 webdriverio 数据表
【发布时间】:2018-09-16 21:03:22
【问题描述】:

功能文件

Feature: Shopper can add an item to their Grocery List

@kk
Scenario: Mutate multiple User Skills at the same time

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

步骤定义文件

Then(/^If I click the row "([^"]*)" then I should the following nested information$/, function (rowName, data){
 cconsole.log("rowName-----"+rowName)
 console.log("data-----"+data)
 data = dataTable.raw();
 console.log(data);`
});

错误日志 如果我单击“摘要”行,那么我应该以下嵌套信息

  dataTable is not defined


  ReferenceError: dataTable is not defined
at World.<anonymous> (/Users/src/__acceptance__/stepDefinition/android/wdio.apps.stepdefs.js:12:3)
at new Promise (<anonymous>)
at new F (/Users/wdio-cucumber-framework/node_modules/core-js/library/modules/_export.js:36:28)

请帮我解决这个问题.....

【问题讨论】:

  • 您能否格式化代码示例,以便人们可以看到您的行是如何中断的?这可能会影响 cucumber 如何解释您的场景。
  • 感谢您的回复.....我已经编辑了代码.....无论我在功能文件中传递什么,都无法在步骤定义中获取数据表数据。

标签: cucumberjs


【解决方案1】:

我对 Webdriver-io 并不太熟悉,但您似乎正在使用未定义的变量。您正在将 data 传递到您的函数中,但尝试使用抛出错误的 dataTable

您是否尝试过类似的方法:

function(rowName, table) {
  var myData = table.rowsHash();
  console.log(myData);
  console.log(table.raw());
}

与您的问题无关,我建议您将操作步骤与验证步骤分开

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

【讨论】:

  • 感谢您的回复,,,,但运气不好 I should see the following nested information dataTable.rowsHash is not a function TypeError: dataTable.rowsHash is not a function ` 在 World.` (/Users/src/__acceptance__/stepDefinition/android/wdio.apps.stepdefs.js:11:26) ` at new Promise ()` `在新 F (/Users/node_modules/wdio-cucumber-framework/node_modules/core- js/library/modules/_export.js:36:28)`
【解决方案2】:

您在 stepDefinition 文件中的代码有问题:

在线data = dataTable.raw();...没有定义变量dataTable

请尝试以下代码:

Then(/^If I click the row "([^"]*)" then I should the following nested information$/, function (rowName, dataTable){
        console.log(dataTable);
        var data = dataTable.raw();
        console.log(data);
        data.forEach(function(element) {
            console.log("Element:" + element[0]);
            console.log("Element:" + element[1]);
        }, this);
});

【讨论】:

  • 没有成功我无法在 console.log 错误日志中获取数据表:: dataTable------ I should see the following nested information dataTable.raw is not a function TypeError: dataTable.raw is not a function at World.&lt;anonymous&gt; (/Users/src/__acceptance__/stepDefinition/android/wdio.apps.stepdefs.js:12:30) at new Promise (&lt;anonymous&gt;) at new F (/Users/node_modules/wdio-cucumber-framework/node_modules/core-js/library/modules/_export.js:36:28)
  • 如果我能够在步骤定义中获取特征文件的数据表,我的问题将得到解决..... console.log("datatable----->>"+datatable) 是返回空白.....
  • 我尝试了上面的代码,它适用于您的场景。不确定问题可能是什么。你能分享一下你的 npm 模块的版本吗?
  • 感谢您的回复,,,,,实际上我们在执行之前构建了我们的特征文件并将其放在项目内的dist文件夹中.....在构建特征文件时,数据表作为空白空间传递
猜你喜欢
  • 1970-01-01
  • 2021-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-22
  • 2012-10-20
相关资源
最近更新 更多