Cucumber.js和Angular配置

时间:2017-08-02 16:39:48

标签: angular protractor cucumber cucumberjs

我一直在关注几个教程,但无法在我的Angular应用程序中正确执行Cucumber.js。任何帮助都会非常感激!

我简化的量角器配置:

// protractor.conf.js

exports.config = {
  baseUrl: 'http://localhost:8000',

  seleniumAddress: 'http://localhost:4444/wd/hub',

  capabilities: {
    browserName: 'chrome',
  },

  framework: 'custom',
  frameworkPath: 'node_modules/protractor-cucumber-framework',

  specs: [
    'features/test.feature'
  ],

  jasmineNodeOpts: {
    showColors: true
  },

  cucumberOpts: {
    require: 'features/step_definitions/test.e2e.js',
    format: 'pretty' // or summary
  }
};

非常简单的feature文件:

// features/test.feature

Feature: Running Cucumber with Protractor
  As a user of Protractor
  I should be able to use Cucumber
  In order to run my E2E tests

  Scenario: Protractor and Cucumber Test
    Given I go to "https://angularjs.org/"
    When I add "Be Awesome" in the task field
    And I click the add button
    Then I should see my new task in the list

和它一起使用的步骤定义:

// features/step_definitions/test.e2e.js 

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
var expect = chai.expect;

module.exports = function() {
  this.Given('I go to {stringInDoubleQuotes}', function(site) {
    browser.get(site);
  });

  this.When('I add {stringInDoubleQuotes} in the task field', function(task) {
    element(by.model('todoList.todoText')).sendKeys(task);
  });

  this.When('I click the add button', function() {
    var el = element(by.css('[value="add"]'));
    el.click();
  });

  this.Then('I should see my new task in the list', function(callback) {
    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).to.eventually.equal(3);
    expect(todoList.get(2).getText()).to.eventually.equal('Do not Be Awesome')
    .and.notify(callback);
  });
};

然后我从终端运行protractor protractor.conf.js,我只显示feature个文件而没有运行步骤定义进行验证。

(node:8513) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[11:35:47] I/launcher - Running 1 instances of WebDriver
[11:35:47] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Feature: Running Cucumber with Protractor

    As a user of Protractor
    I should be able to use Cucumber
    In order to run my E2E tests

  Scenario: Protractor and Cucumber Test
  ? Given I go to "https://angularjs.org/"
  ? When I add "Be Awesome" in the task field
  ? And I click the add button
  ? Then I should see my new task in the list

Warnings:

1) Scenario: Protractor and Cucumber Test - features/test.feature:6
   Step: Given I go to "https://angularjs.org/" - features/test.feature:7
   Message:
     Undefined. Implement with the following snippet:

       Given('I go to {stringInDoubleQuotes}', function (stringInDoubleQuotes, callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

2) Scenario: Protractor and Cucumber Test - features/test.feature:6
   Step: When I add "Be Awesome" in the task field - features/test.feature:8
   Message:
     Undefined. Implement with the following snippet:

       When('I add {stringInDoubleQuotes} in the task field', function (stringInDoubleQuotes, callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

3) Scenario: Protractor and Cucumber Test - features/test.feature:6
   Step: And I click the add button - features/test.feature:9
   Message:
     Undefined. Implement with the following snippet:

       When('I click the add button', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

4) Scenario: Protractor and Cucumber Test - features/test.feature:6
   Step: Then I should see my new task in the list - features/test.feature:10
   Message:
     Undefined. Implement with the following snippet:

       Then('I should see my new task in the list', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

1 scenario (1 undefined)
4 steps (4 undefined)
0m00.000s
[11:35:48] I/launcher - 0 instance(s) of WebDriver still running
[11:35:48] I/launcher - chrome #01 passed

0 个答案:

没有答案