Cucumber.js,量角器,带有场景大纲的Javascript示例

时间:2017-11-30 10:59:09

标签: protractor cucumberjs

我正在学习如何使用cucumber.js,量角器,bdd等。 我无法了解如何使用'情景大纲'在cucumber.js和量角器

  1. 我的 .feature文件
  2. 中有以下内容

    
    
    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;
    &#13;
    &#13;

    1. 我的 steps.js文件
    2. 中有以下代码

      &#13;
      &#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;
      &#13;
      &#13;

      1. 如何通过&#39;示例&#39;来自&#39;功能的数据&#39;提交给我的&#39;步骤&#39;文件并使用&#39;功能中定义的数据表运行测试&#39;文件?

2 个答案:

答案 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 ) {

-------结果----

});

,您也可以不使用方括号来使用它。