使用CucumberJS,我正在尝试实现用于UI测试的方案大纲。黄瓜无法正确识别或传递我的论点。这就是我所拥有的。
test.feature
Scenario Outline: User with permissions can Import Payment files with any file format
Given a <username> has logged into site
Examples:
|username |fileName |
|administrator |test1.csv |
|userA |step2.csv |
test_step.js
Given('a {string} has logged into site', async function (username) {
console.log('username = ' + username);
return this.userLogin(username);
});
world.js
'use strict';
const { setWorldConstructor } = require('cucumber');
class testApp {
// Write metrics data object to JSON file
async userLogin(username) {
await this.navigateLoginPage();
}
}
setWorldConstructor(testApp);
现在,当我运行此程序时,我得到以下信息:
Warnings:
1) Scenario: User with permissions can Import Payment files with any file format # features/importPaymentFile.feature:28
? Given a administrator has logged into site
Undefined. Implement with the following snippet:
Given('a administrator has logged into site', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
2) Scenario: User with permissions can Import Payment files with any file format # features/importPaymentFile.feature:29
? Given a administrator has logged into site
Undefined. Implement with the following snippet:
Given('a userA has logged into site', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
所以现在我很困惑。看来我的参数已正确读取,但在步骤定义中却无法识别它们。
任何人都可以给我一些有关如何实现方案大纲参数的见解吗?
更新#3-最终更新 因此它对我这样工作:
test.feature
Scenario Outline: User with permissions can Import Payment files with any file format
Given a "<username>" has logged into site and uploads "<fileName>"
Examples:
|username |fileName |
|administrator |test1.csv |
|userA |step2.csv |
test_step.js
Given('a {string} has logged into site and uploads {string}', async function (username, fileName) {
console.log('username = ' + username);
console.log('fileName = ' + fileName);
return this.userLogin(username);
});
world.js
'use strict';
const { setWorldConstructor } = require('cucumber');
class testApp {
// Write metrics data object to JSON file
async userLogin(username) {
await this.navigateLoginPage();
}
}
setWorldConstructor(testApp);
结果:
> . ./.env; node app.js "--feature" "importPaymentFile"
username = administrator
filename = oneStepApproval_MediaOcean.csv
.username = operations
filename = twoStepApproval_MediaOceanDan.csv
对不起,如果我要详细。如果告诉我,我将其配对:)
更新#1
我尝试了引号,但这没有用。在功能文件中的参数周围加上引号似乎会导致参数无法传递。
test.feature
Scenario Outline: User with permissions can Import Payment files with any file format
Given a "<username>" has logged into site
Examples:
|username |fileName |
|administrator |test1.csv |
|userA |step2.csv |
结果错误:
username =
.username =
.
2 scenarios (2 passed)
2 steps (2 passed)
0m00.015s
(node:16642) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 7): Error: Protocol error(Emulation.setDeviceMetricsOverride): Session closed. Most likely the page has been closed.
(node:16642) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:16642) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 8): Error: Protocol error (Emulation.setDeviceMetricsOverride): Session closed. Most likely the page has been closed.
events.js:183
throw er; // Unhandled 'error' event
^
Error: Timed out while authenticating with server
at Timeout._onTimeout (/Users/huckcarignan/Desktop/sprint26/epay-test-automation/node_modules/imap/lib/Connection.js:139:17)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
更新#2
组合1:&{string}
功能文件:
Given a <username> has logged into Site
步骤定义:
Given('a {string} has logged into Site', async function (username) {
console.log('username = ' + username);
return this.userLogin(username);
});
结果:
? Given a administrator has logged into Site
Undefined. Implement with the following snippet:
Given('a administrator has logged into Site', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
组合2:&([^“] *)
功能文件:
Given a <username> has logged into Site
步骤定义:
Given('a ([^"]*) has logged into Site', async function (username) {
console.log('username = ' + username);
return this.userLogin(username);
});
结果:
? Given a administrator has logged into Site
Undefined. Implement with the following snippet:
Given('a administrator has logged into Site', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
组合3:“”和“([[^“] *)”
功能文件:
Given a "<username>" has logged into Site
步骤定义:
Given('a "([^"]*)" has logged into Site', async function (username) {
console.log('username = ' + username);
return this.userLogin(username);
});
结果:
? Given a {string} has logged into Site
Undefined. Implement with the following snippet:
Given('a administrator has logged into Site', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
组合4:“”&([^“] *)
功能文件:
Given a <username> has logged into Site
步骤定义:
Given('a "([^"]*)" has logged into Site', async function (username) {
console.log('username = ' + username);
return this.userLogin(username);
});
结果:
? Given a {string} has logged into Site
Undefined. Implement with the following snippet:
Given('a administrator has logged into Site', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
组合5:“”和{string} 获胜者-
功能文件:
Given a <username> has logged into Site
步骤定义:
Given('a "([^"]*)" has logged into Site', async function (string) {
console.log('username = ' + string);
return this.userLogin(string);
});
结果:
username = administrator
.
1 scenarios (1 passed)
1 steps (1 passed)
0m01.637s;
Sooooo ...这行得通,多个参数是按顺序处理的-我将结果放在最顶端
答案 0 :(得分:0)
Scenario Outline: User with permissions can Import Payment files with any file format
Given a "<username>" has logged into site
Examples:
|username |fileName |
|administrator |test1.csv |
|userA |step2.csv |
在示例中添加引号,“”“可能是黄瓜期望传递一个字符串参数,而在您的测试中情况并非如此
答案 1 :(得分:0)
我使用了正则表达式
因此,您的示例:
Scenario Outline: User with permissions can Import Payment files with any file format
Given a <username> has logged into site
Examples:
|username |fileName |
|administrator |test1.csv |
|userA |step2.csv |
然后在代码中我将做:
Given(/^a (.*) has logged into site$/, async function (username) {
console.log('username = ' + username);
return this.userLogin(username);
});