TypeError: table.rows is not a function - while accessing examples from feature file in protractor

TypeError: table.rows is not a function - while accessing examples from feature file in protractor

我正在使用 protractor-cucumber-framework

这是功能文件

Feature: welcome to protractor cucumber

    Scenario Outline: DataTable
        Given I am learning
        Then I print following table

        Examples:
            | First | Middle |
            | qwerty   | xyz  | 

在步骤定义文件中,我想打印 table 数据。

    Given(/^I am learning$/, async () => {
        console.log("I am learning");   
    });

    Then(/^I print following table$/, (table: TableDefinition) => {
        const tableData = table.rows();
        console.log(tableData[0][0]);

      });

但是出现以下错误

TypeError: table.rows is not a function
    at World.(anonymous) (/.../Protr_cucumber/stepDef/Sample_stepDef.ts:9:29)

您正在混淆场景大纲和数据 tables。

当您想执行具有多个测试数据的场景时,使用场景大纲。

数据table 有助于将多个测试数据传递到场景中的单个步骤。您可以使用 hashesrows.

在步骤定义中访问此数据

您可以找到文档 here and examples here

找到了关于 Gherkin 的更详细的文档 here