【问题标题】:Passing Data from a Data Table in the feature file to my step definitions (js)将功能文件中的数据表中的数据传递到我的步骤定义 (js)
【发布时间】:2019-04-04 14:58:31
【问题描述】:

我正在尝试将数据从表传递到功能文件,然后最终传递到我的 java 脚本步骤定义中,如下所示。

Scenario: XX | Basket Tests: Cover Type | Building + no bundle + HE 

Given I open the page with the url "http://localhost:3000" and route "/basket"
When I click the button <coverTypeID>
And I click the button <bundleID>
Then I see the result <expectedResult>

| id |             url              | coverTypeID    | bundleID | elementID | expectedResult |
| 1  | http://localhost:3000/basket | coverTypeId101 | NoBundle | null      |                |
| 2  | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox1 |                | 
| 3  | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox2 |                | 
| 4  | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox3 |                | 
| 5  | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox4 |                | 

是我的功能文件,我曾经使用字符串传递数据,但是现在我使用的是数据表,它在测试运行时无法识别场景。

    When("I click the button <coverTypeID>", (buttonID, next) => {

    driver.findElement(By.id(buttonID)).then(pageElement => {                           /////////////////////////////////////////////
        driver.wait(until.elementIsVisible(pageElement), 10000).then(async () => {      //This is to click a button using elementID//
         await driver.sleep(3000);                                                      /////////////////////////////////////////////
         pageElement.click();
         next();
         })
         .catch(ex => {
            console.log(ex.message, ex.stack)
         });
    }).catch(ex => {console.log(ex.message, ex.stack)});
});

我得到的错误是测试未定义,因为使用了表格标题,场景与步骤定义不匹配

我已经研究过使用正则表达式,但是我不确定数据表在执行时传递什么类型的数据,任何指导都会有用,我已经经历了一堆不同的问题,但似乎都没有回答我的。

任何帮助将不胜感激,如果可以的话,我想避免使用正则表达式,因为这样做的目的是使代码尽可能可读。

提前谢谢你。

【问题讨论】:

    标签: selenium automation cucumber gherkin cucumberjs


    【解决方案1】:

    所以我找到了解决方案,而不是期待我使用 {string} 引用的数据表的标题

    When("I click the button {string}", (buttonID, next) => {
    

    然后在数据表中我意识到我犯的错误只是没有添加引号将数据变成字符串格式。

    Examples:
    | id | coverTypeID      | bundleID       | elementID   | 
    | 1  | "coverTypeId101" | "moreDetails1" | "checkbox2" |
    

    通过这样做,该功能现在成功地将数据从功能文件提取到 JS 文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      相关资源
      最近更新 更多