2015-06-23 4 views
2

Я настраиваю тесты cucumber.js для своего проекта. Я следил за учебником, доступным здесь: http://cloudspace.com/blog/2014/11/25/cucumber/#.VYe4w87sNRE Я также пробовал другие учебные пособия, но они все одинаковы и привели к той же проблеме.Неудачные простые тесты cucumber.js + zombie

У меня есть функция файл:

Feature: Example feature 
As a user of cucumber.js 
I want to have documentation on cucumber 
So that I can concentrate on building awesome applications 

Scenario: Reading documentation 
    Given I am on the Cucumber.js GitHub repository 
    When I go to the README file 
    Then I should see "Usage" as the page title 

И шаг определения:

'use strict'; 

module.exports = function() { 
    this.World = require("../../support/world.js").World; 

    this.Given(/^I am on the Cucumber.js GitHub repository$/, function (callback) { 

     this.visit('http://github.com/cucumber/cucumber-js', callback); 
    }); 

    this.When(/^I go to the README file$/, function (callback) { 

     callback.pending(); 
    }); 

    this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) { 

     var pageTitle = this.browser.text('title'); 
     if (title === pageTitle) { 
     callback(); 
     } else { 
     callback.fail(new Error("Expected to be on page with title " + title)); 
     } 
    }); 
    }; 

И следующий word.js файл:

'use strict'; 

var zombie = require('zombie'); 
function WorldFactory(callback) { 

    var browser = new zombie(); 

    var world = { 
    browser: browser,      
    visit: function (url, callback) { 
     this.browser.visit(url, callback); 
    } 
    }; 

    callback(world); 
} 
exports.World = WorldFactory; 

Когда я запускаю это, первый шаг от сценария завершается с ошибкой, и я вижу следующую ошибку:

Scenario: Reading documentation # features/sample.feature:6 
{ [TypeError: undefined is not a function] filename: undefined } 
{ [ReferenceError: $ is not defined] filename: undefined } 
    Given I am on the Cucumber.js GitHub repository # features/sample.feature:7 
     TypeError: undefined is not a function 
      at <anonymous>:9:1625 
      at <anonymous>:9:1814 
      at <anonymous>:9:2704 
      in https://github.com/cucumber/cucumber-js 
    When I go to the README file     # features/sample.feature:8 
    Then I should see "Usage" as the page title  # features/sample.feature:9 

(::) failed steps (::) 

TypeError: undefined is not a function 
    at <anonymous>:9:1625 
    at <anonymous>:9:1814 
    at <anonymous>:9:2704 
    in https://github.com/cucumber/cucumber-js 

Однако, когда я изменяю файл world.js, чтобы передать другую функцию, внутри которой я вызываю метод обратного вызова, методу посещения зомби, шаг проходит (но я все еще получаю ошибку). Вот измененный файл:

'use strict'; 

var zombie = require('zombie'); 
function WorldFactory(callback) { 

    var browser = new zombie(); 

    var world = { 
    browser: browser, 
    visit: function (url, callback) { 
     this.browser.visit(url, function() { 
      callback(); 
     }); 
    } 
    }; 

    callback(world); 
} 
exports.World = WorldFactory; 

С какими проблемами связана данная проблема? И почему такое простое изменение кода заставляет пройти тест?

+0

любой удачи с этим вопросом? Я вижу то же самое. – user1523236

ответ

1

Мне удалось сделать это с .

Файлы:

Характеристика:

Feature: laboradmin Website 
As a user of laboradmin 
I want to visit the portal 

Scenario: Opening the portal 
    Given I am using a browser 
    When I visit the laboradmin homepage 
    Then I should see "laboradmin" as the page title 

World: определение

'use strict'; 

var zombie = require('zombie'); 
function WorldFactory(callback) { 

    this.browser = new zombie(); 
    var self = this; 
    this.world = { 
     browser: self.browser, 
     visit: function (url, callback) { 
      this.browser.visit(url, function() { 
       callback(); 
      }); 
     } 
    }; 

} 
exports.World = WorldFactory; 

Шаг:

module.exports = function() { 
    this.World = require('../support/world').World; 

    this.Given(/^I am using a browser$/, function (callback) { 
     // Express the regexp above with the code you wish you had. Call callback() at the end 
     // of the step, or callback.pending() if the step is not yet implemented: 
     callback(); 


    }); 

    this.When(/^I visit the laboradmin homepage$/, function (callback) { 
     // Express the regexp above with the code you wish you had. 
     // `this` is set to a World instance. 
     // i.e. you may use this.browser to execute the step: 
     this.world.visit('http://localhost/laboradmin/dist/#/', callback); 
// The callback is passed to visit() so that when the job's finished, the next step can 
     // be executed by Cucumber. 
    }); 

    this.Then('I should see "$title" as the page title', function (title, callback) { 
     // the above string is converted to the following Regexp by Cucumber: 
     // /^I should see "([^"]*)" as the page title$/ 

     var pageTitle = this.world.browser.text('title'); 
     if (title === pageTitle) { 
      callback(); 
     } else { 
      callback(new Error("Expected to be on page with title " + title + "\n but page title is: " + pageTitle)); 
     } 
    }); 
}; 
Смежные вопросы