svfat
svfat

Reputation: 3363

Can't run cucumber tests with protractor

Every time when I am running tests, I got the error: TypeError: e.getContext is not a function

I am using examples from https://github.com/cucumber/cucumber-js with some changes in world.js (made them to fix timeout errors)

Versions of apps:

My 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);
};

My 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));
    }
  });
};

My 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

My 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"
  }
};

Upvotes: 2

Views: 1612

Answers (1)

VikomiC
VikomiC

Reputation: 91

I had same issue with this example. The problem is with github.com page. What the problem, I don't know.

So, I made changes for the page which to visit and tests start run without TypeError: e.getContext is not a function.

I changed sampleSteps.js file:

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();
  });
};

Then some changes for 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

I hope, this will help with first steps working with cucumber-js and zombie.js.

It's not the problem with protractor, because same problem is, when I run this sample in the WebStorm.

Upvotes: 1

Related Questions