黄瓜webdriverio数据表

问题描述 投票:0回答:2

FeatureFile

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  |

StepDefininition文件

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)

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

cucumberjs
2个回答
0
投票

我对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  |

0
投票

您在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);
});
© www.soinside.com 2019 - 2024. All rights reserved.