问题
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 File
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);`
});
Error Log If I click the row "Summary" then I should the following nested information
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)
Please help me to resolve this issue.....
回答1:
I am not overly familiar with Webdriver-io, but it would appear that you are using a variable that is not defined. You are passing data
into your function, but trying to use dataTable
which is throwing the error.
Have you tried something like:
function(rowName, table) {
var myData = table.rowsHash();
console.log(myData);
console.log(table.raw());
}
Unrelated to your question, I would suggest separating your action steps from your validation steps
If I click the row "Summary"
Then I should see the following nested information
| Tax | 11.50 |
| Gratuity | 4.50 |
| Total | 26.59 |
回答2:
You have a problem in your code on the stepDefinition file:
on the line data = dataTable.raw();
... there is no variable dataTable
defined.
Please try the below code:
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);
});
来源:https://stackoverflow.com/questions/52292496/cucumber-webdriverio-datatable