我想在Node.js中实现一个涉及数据表的Gherkin步骤,但是我不确定应该如何传入数据。这是一个我知道不使用数据表的例子
test.feature
Feature: Testing login
Scenario: Logging in with credentials
When I login with credentials "user@example.com" and "p@ssw0rd"
login.js
import loginAsCreds from './loginAsCreds'
module.exports = function when () {
this.When(
/^I login as "(.+)" and "(.+)"/i,
loginAsCreds
)
loginAsCreds.js
module.exports = (email, password, done) => {
browser.element('#email').keys(email)
browser.element('#password').keys(password)
browser.element('#signInButton').click()
done()
}
这就是我想要的功能文件。
test-desired.feature
Feature: Testing login
Scenario: Logging in with credentials
When I login with credentials:
| user@example.com | p@ssw0rd |
我尝试过修改login.js
以传递数据表和loginAsCreds.js
接受它的一些事情,但我是Node.js和WebdriverIO的新手(但不是Selenium或Gherkin) )。请问有人请指出我正确的方向吗?数据表对于我计划编写的其他步骤也非常有用。谢谢!
答案 0 :(得分:0)
我有人指着.raw()
文档。我不知道要搜索那个,所以我找到了这个页面:
https://github.com/cucumber/cucumber-js/blob/9959ca9fd9f8c64f0b5133f9bb241da9b854e570/README.md
...这告诉我我需要在我的参数中添加Feature: Testing login
Scenario: Logging in with credentials
When I login with credentials:
| user@example.com | p@ssw0rd |
来访问数据(因为该表是一个二维数组),并指向这个例子:
这就是我现在的代码:
<强>测试desired.feature 强>
import loginAsCreds from './loginAsCreds'
module.exports = function when () {
this.When(
/^I login as:/i,
loginAsCreds
)
<强> login.js 强>
module.exports = (creds, done) => {
email = creds.raw()[0][0]
password = creds.raw()[0][1]
browser.element('#email').keys(email)
browser.element('#password').keys(password)
browser.element('#signInButton').click()
done()
}
<强> loginAsCreds.js 强>
criteria.addOrder(Order.desc("historyId"));
criteria.setMaxResults(1);