Не удается запустить тесты на огурцы с помощью транспортира

Каждый раз, когда я запускаю тесты, я получаю сообщение об ошибке: TypeError: e.getContext is not a function

Я использую примеры из https://github.com/cucumber/cucumber-js с некоторыми изменениями. в world.js (сделал их для исправления ошибок таймаута)

Версии приложений:

  • узел 4.2.6
  • огурец 0.9.4
  • транспортир 3.0.0
  • транспортир-огурец-каркас 0.3.3
  • зомби 4.2.1

Мой world.js:

// features/support/world.js
var zombie = require('zombie');
zombie.waitDuration = '30s';
function World() {
  this.browser = new zombie(); // this.browser will be available in step definitions
  this.visit = function (url, callback) {
    this.browser.visit(url, callback);
  };
}

module.exports = function() {
  this.World = World;
  this.setDefaultTimeout(60 * 1000);
};

Мой sampleSteps.js:

// features/step_definitions/my_step_definitions.js

module.exports = function () {
  this.Given(/^I am on the Cucumber.js GitHub repository$/, 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.visit('https://github.com/cucumber/cucumber-js', callback);

    // The callback is passed to visit() so that when the job's finished, the next step can
    // be executed by Cucumber.
  });

  this.When(/^I go to the README file$/, 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.pending();
  });

  this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) {
    // matching groups are passed as parameters to the step definition

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

Моя sample.feature:

# features/my_feature.feature

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

Мой protractor-conf.js:

exports.config = {

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

  capabilities: {
    'browserName': 'chrome'
  },

  baseUrl: 'http://127.0.0.1:8000/',

    framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),
  // relevant cucumber command line options
  cucumberOpts: {
    require: ['features/support/world.js', 'features/sampleSteps.js'],
    format: "summary"
  }
};

person svfat    schedule 29.01.2016    source источник
comment
Интересно. Я не использовал транспортир вместе с Zombie. Что произойдет, если вы переключитесь на использование только ChromeDriver? Кроме того, вы случайно не используете холст на странице? Большинство ошибок, связанных с getContext, указывают на проблему с доступом к элементам холста.   -  person Nick Tomlin    schedule 29.01.2016
comment
На каком шаге возникает ошибка? Браузер хоть запускается?   -  person nilesh    schedule 29.01.2016


Ответы (1)


У меня была такая же проблема с этим примером. Проблема со страницей github.com. В чем проблема, я не знаю.

Итак, я внес изменения для страницы, которую нужно посетить, и тесты начинают выполняться без TypeError: e.getContext is not a function.

Я изменил файл sampleSteps.js:

module.exports = function () {
  this.Given(/^I am on the Google.com$/, 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.visit('http://www.google.com/', callback);

    // The callback is passed to visit() so that when the job's finished, the next step can
    // be executed by Cucumber.
  });

  this.When(/^I go to the SEARCH page$/, 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:

    // changed to this one, otherwise next steps also are skipped...
    callback();
  });

  this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) {
    // matching groups are passed as parameters to the step definition

    this.browser.assert.text('title', title);

    callback();
  });
};

Затем некоторые изменения для sample.feature:

Feature: Example feature
  As a user of Google.com
  I want to have search with Google
  So that I can find something

  Scenario: Search something
    Given I am on the Google.com
    When I go to the SEARCH page
    Then I should see "Google" as the page title

Я надеюсь, что это поможет вам на первых этапах работы с огурцом-js и зомби.js.

Это не проблема с транспортиром, потому что та же проблема возникает, когда я запускаю этот пример в WebStorm.

person VikomiC    schedule 19.02.2016