我正在学习如何使用cucumber.js,量角器,bdd等。 我无法了解如何使用'情景大纲'在cucumber.js和量角器
Scenario Outline : Invalid Login
When I enter invalid <user>
And I enter invalid <pass>
And I press login button
Then I should see an error message
Examples:
|user |pass|
|abc |def|
|bcd |efg|
&#13;
this.When('I enter invalid username', function (callback) {
var userNameElement = element(by.id('username'));
userNameElement.sendKeys('userA');
callback();
});
this.When('I enter invalid password', function (callback) {
var passwordElement = element(by.id('password'));
passwordElement.sendKeys('userB');
callback();
});
&#13;
答案 0 :(得分:1)
场景大纲值作为参数传递给步骤定义。您的步骤定义应如下所示:
this.When(/^I enter "([^"]*)" as invalid username$/, function (user, callback) {
var userNameElement = element(by.id('username'));
userNameElement.sendKeys(user);
callback();
});
this.When(/^I enter "([^"]*)" as invalid password$/', function (pwd, callback) {
var passwordElement = element(by.id('password'));
passwordElement.sendKeys(pwd);
callback();
});
答案 1 :(得分:-1)
在标准javascript中使用方括号将参数表与cumulsjs一起使用的正确语法如下:
client.on("message")
并在js文件中:
Scenario Outline: Joe Given I enter "<goat>" as invalid username
Examples:
| goat |
| goe |
| bill |
| bish |
console.log(“ display参数传递为:” +山羊);
const assert = require('assert');
const { Given, When, Then } = require('cucumber');
// https://docs.cucumber.io/gherkin/reference/#scenario-outline
// https://stackoverflow.com/questions/47571808/cucumber-js-protractor-javascript-example-with-scenario-outlines
When(/^I enter "(.*)" as invalid username$/, function ( goat ) {
-------结果----
});
,您也可以不使用方括号来使用它。