我有以下特性文件:
Feature: Color feature
@test
Scenario Outline: Test color
Given the first color is <COLOR_ONE>
And the second color is <COLOR_TWO>
When the user loads page
Then the <COLOR_THREE> is displayed
Examples:
| COLOR_ONE | COLOR_TWO | COLOR_THREE
| red | white | pink
| blue | black | black
| green | purple | white我正在努力弄清楚如何创建step文件。每当我运行量角器时,它都会给我自动生成的代码;然而,它为每个场景提供了一个代码。例如,它要求我为每一种情况编写六个Given步骤。如何使用传递给函数的变量创建两个Given步骤?Then步骤也是一样的。
我尝试了以下(使用类型记录),但它仍然希望我创建所有不同的步骤用例,当然,下面的例子都没有通过。
import { browser, element, by } from 'protractor';
const { Given, When, Then, defineSupportCode } = require('cucumber');
defineSupportCode(function ({ setDefaultTimeout }) {
setDefaultTimeout(120 * 1000);
});
Given(/^ the first color is "([^"]*)" $/, (color, next) => {
next();
});
Given(/^ the second color is "([^"]*)" $/, (color, next) => {
next();
});
When(/^ the user loads page $/, (next) => {
next();
});
Then(/^ the "([^"]*)" is displayed $/, (color, next) => {
next();
});发布于 2018-04-28 00:13:45
所以我犯了两个错误。我在特性文件中没有COLOR_THREE之后的管道,我需要在step文件中使用{variable_here}。下面是更新的特性文件和代码:
特征文件:
Feature: Color feature
@test
Scenario Outline: Test color
Given the first color is <COLOR_ONE>
And the second color is <COLOR_TWO>
When the user loads page
Then the <COLOR_THREE> is displayed
Examples:
| COLOR_ONE | COLOR_TWO | COLOR_THREE |
| red | white | pink |
| blue | black | black |
| green | purple | white |步骤文件:
import { browser, element, by } from 'protractor';
const { Given, When, Then, defineSupportCode } = require('cucumber');
defineSupportCode(function ({ setDefaultTimeout }) {
setDefaultTimeout(120 * 1000);
});
Given('the first color is {color}', (color, next) => {
next();
});
Given('the second color is {color}', (color, next) => {
next();
});
When('the user loads page', (next) => {
next();
});
Then('the {color} is displayed', (color, next) => {
next();
});现在,您可以从变量内的特性文件中的表中获得各种值。测试通过了(当然,在上面的例子中没有测试任何东西)。希望它能帮到别人!
https://stackoverflow.com/questions/50071490
复制相似问题