Javascript Cumber JS:我得到一个;表.行();不是有效的函数";将表和另一个变量传递到步骤def时出错

Javascript Cumber JS:我得到一个;表.行();不是有效的函数";将表和另一个变量传递到步骤def时出错,javascript,protractor,cucumberjs,Javascript,Protractor,Cucumberjs,我试图验证从cucumber数据表到前端的值。当我只将datatable传递给我的step def时,但当我将变量与datatable一起传递时,测试工作正常;测试中断并给出错误“table.rows()不是有效函数” 这是我的功能文件: Then(/^the student info for student "([^"]*)" should be correct in the fund list page$/, function (table, studNumber) { let testTa

我试图验证从cucumber数据表到前端的值。当我只将datatable传递给我的step def时,但当我将变量与datatable一起传递时,测试工作正常;测试中断并给出错误“table.rows()不是有效函数”

这是我的功能文件:

Then(/^the student info for student "([^"]*)" should be correct in the fund list page$/, function (table, studNumber) {
let testTable = table.rows();
return this.pages.prd2Page.getCellInfo(studNumber).then((actualTexts) => {

return assert.deepEqual(testTable.toString(), actualTexts.toString());
//return console.log(actualTexts.toString());
});
});
那么学生“1761”的学生信息在学生列表页面中应该是正确的

|姓名| ID |部门|| |蒙尼| 123 | 1761|

步骤定义:

Then(/^the student info for student "([^"]*)" should be correct in the fund list page$/, function (table, studNumber) {
let testTable = table.rows();
return this.pages.prd2Page.getCellInfo(studNumber).then((actualTexts) => {

return assert.deepEqual(testTable.toString(), actualTexts.toString());
//return console.log(actualTexts.toString());
});
});
如您所见,我正在传递一个数据表和一个变量。如果我删除变量并硬编码变量的所有值。这个测试通过了。
有人能分享一些关于这里可能有什么问题的信息吗

我尝试了你想通过这一步实现的目标(这一步听起来可能很傻,只是一个测试):

自动生成的步骤定义为:

Then(/^I should see "([^"]*)" these in Missing required fields popup$/, function(arg1, callback) {
  // Write code here that turns the phrase above into concrete actions
  callback(null, 'pending');
});
似乎不可能同时传递参数和表。相反,您可以使用表中的值将stdNumber传递给getCellInfo函数:

    Then(/^the student info for student "([^"]*)" should be correct in the fund list page$/, function (table, studNumber) {
      table.rows().forEach(row => {
          return this.pages.prd2Page.getCellInfo(row[2]).then((actualTexts) => {
            return assert.deepEqual(row.toString(), actualTexts.toString());
            //return console.log(actualTexts.toString());
            });
          });

      });
    }
cucumber还解释了其他用法


注意:我的示例是在typescript中,您需要指定传递到步骤定义中的所有变量

还需要考虑参数的“强>阶< /强>。这张桌子正在最后通过

例如:

Then I order from "Dominos" a pizza for 4 ppl
  | Size  | Crust   |  Sauce  | Cheese     | 
  | 13.5  | Stuffed |  Tomato | Mozzarella |
给你(按顺序):

  • 比萨饼地名
  • 人数
  • 数据表
定义是:

Then(/^I order from "(.*)" a pizza for (\d) ppl$/, function (pizza_place, ppl_num, table) {
  console.log('Buy from: ' + pizza_place);
  console.log('For ' + ppl_num + ' people');

  const input = table.hashes()
  console.log('Size: ' + input[0].Size);
  console.log('Crust: ' + input[0].Crust);
  console.log('Sauce: ' + input[0].Sauce);
  console.log('Cheese: ' + input[0].Cheese);
});
产出将是:

Buy from: Dominos
For 4 people
Size: 13.5
Crust: Stuffed
Sauce: Tomato
Cheese: Mozzarella