【问题标题】:Can't run cucumber tests with protractor不能用量角器运行黄瓜测试
【发布时间】:2016-01-29 14:14:09
【问题描述】:

每次运行测试时,我都会收到错误: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"
  }
};

【问题讨论】:

  • 有趣。我没有将量角器与僵尸一起使用。如果您切换到只使用 ChromeDriver 会发生什么?另外,您是否可能在页面上使用画布?大多数与getContext 相关的错误都指向访问画布元素的问题。
  • 错误发生在哪一步?浏览器是否至少启动?

标签: javascript testing protractor cucumberjs


【解决方案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

我希望,这将有助于使用 cucumber-js 和zombie.js 的第一步。

这不是量角器的问题,因为同样的问题是,当我在 WebStorm 中运行这个示例时。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多