我试图将数据从表传递到功能文件中,然后最终传递到我的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)});
});
我遇到的错误是由于表标题的使用,场景未正确匹配步骤定义,因此测试未定义
我已经看过使用正则表达式,但是我不确定执行时数据表将传递哪种类型的数据,任何指导都将有用,我经历了很多不同的问题,而且似乎都没有回答我的。
任何帮助将不胜感激,如果可能的话,我想避免使用正则表达式,因为这样做的目的是使代码尽可能地易读。
谢谢。
答案 0 :(得分:0)
所以我找到了解决方案,而不是期望我使用{string}引用的数据表的标题
When("I click the button {string}", (buttonID, next) => {
然后在数据表中,我意识到我犯的错误就是根本没有添加引号将数据转换为字符串格式。
Examples:
| id | coverTypeID | bundleID | elementID |
| 1 | "coverTypeId101" | "moreDetails1" | "checkbox2" |
通过执行此操作,此功能现在已成功将数据从功能文件中提取到JS文件中。