【发布时间】: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