将特征文件中数据 Table 中的数据传递到我的步骤定义 (js)
Passing Data from a Data Table in the feature file to my step definitions (js)
我正在尝试将数据从 table 传递到功能文件,然后最终传递到我的 java 脚本 step-definitions,如下所示。
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 | |
是我的功能文件,我以前使用字符串传递数据但是现在我使用数据 table 它不识别测试时的场景 运行。
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)});
});
我得到的错误是测试未定义,因为场景与步骤定义不匹配,因为使用了 table 标题
我看过使用正则表达式,但是我不确定数据 table 在执行时传递的数据类型,任何指导都会有用,我经历了很多不同的问题和 none 似乎完全回答了我的问题。
任何帮助将不胜感激,我想尽可能避免使用正则表达式,因为目的是使代码尽可能可读。
提前致谢。
所以我找到了解决方案,而不是期待数据的标题 table 我提到使用 {string}
When("I click the button {string}", (buttonID, next) => {
然后在数据中table我意识到我犯的错误只是没有添加引号使数据成为字符串格式。
Examples:
| id | coverTypeID | bundleID | elementID |
| 1 | "coverTypeId101" | "moreDetails1" | "checkbox2" |
通过这样做,该功能现在可以成功地将数据从功能文件提取到 JS 文件中。
我正在尝试将数据从 table 传递到功能文件,然后最终传递到我的 java 脚本 step-definitions,如下所示。
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 | |
是我的功能文件,我以前使用字符串传递数据但是现在我使用数据 table 它不识别测试时的场景 运行。
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)});
});
我得到的错误是测试未定义,因为场景与步骤定义不匹配,因为使用了 table 标题
我看过使用正则表达式,但是我不确定数据 table 在执行时传递的数据类型,任何指导都会有用,我经历了很多不同的问题和 none 似乎完全回答了我的问题。
任何帮助将不胜感激,我想尽可能避免使用正则表达式,因为目的是使代码尽可能可读。
提前致谢。
所以我找到了解决方案,而不是期待数据的标题 table 我提到使用 {string}
When("I click the button {string}", (buttonID, next) => {
然后在数据中table我意识到我犯的错误只是没有添加引号使数据成为字符串格式。
Examples:
| id | coverTypeID | bundleID | elementID |
| 1 | "coverTypeId101" | "moreDetails1" | "checkbox2" |
通过这样做,该功能现在可以成功地将数据从功能文件提取到 JS 文件中。