使用cucumberjs设置量角器(量角器 - 黄瓜 - 框架)

时间:2016-08-30 18:05:35

标签: angularjs protractor e2e-testing cucumberjs

cucumberjs --version 1.2.2
protractor --version 4.0.1
Both installed globally via npm 

我尝试使用这两个链接来设置我的Protractor与更新的cucumberJs: 量角器 - 黄瓜 - 框架:https://github.com/mattfritz/protractor-cucumber-framework cucumberJs:https://github.com/cucumber/cucumber-js

不幸的是,当我运行测试时,无论测试是否失败,它们总是会通过。

有时它们会在5000毫秒之前超时,我通过这样做解决了这个问题:

exports.config = {
  // set to "custom" instead of cucumber.
  framework: 'custom',

  // path relative to the current config file
  frameworkPath: require.resolve('protractor-cucumber-framework'),

  // relevant cucumber command line options
  cucumberOpts: {
        require: [
          conf.paths.e2e + '/steps/**/*Steps.js',
          conf.paths.e2e + '/support/env.js',
        ],
        format: 'pretty'
      }
};

请注意我在黄瓜选项块中包含了我的env.js,这是我的env.js内容:

// features / support / env.js

var configure = function () {
  this.setDefaultTimeout(60*1000);
};

module.exports = configure;

我也有这个world.js,我不知道如何进入我的测试:

// features/support/world.js
var zombie = require('zombie');
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;
};

我查看'zoombie.js',它似乎是一个无头浏览器,我不关心,因为量角器团队不鼓励我们使用像PhantomJS这样的无头浏览器;请参阅:http://www.protractortest.org/#/browser-setup#setting-up-phantomjs(“ 注意:我们建议不要使用PhantomJS进行Protractor测试。有许多报告的PhantomJS崩溃问题,其行为与真实浏览器不同。 “)

我还尝试使用以下命令返回Protractor控制流内的回调: return browser.controlFlow()。execute(callback);但这似乎不起作用,而是抛出这个错误:

  

函数接受回调并返回一个promise

我的步骤定义文件如下所示:

 module.exports = function () {
      this.Given(/^I am logged in as "([^"]*)" for "([^"]*)"$/, function (username, password, callback) {
        return app.getShell().getLogonPage().logonWithoutAngular(username, password, org).then(null, function (error) {
          console.error('Sorry an error occurred: ' + error);
          throw error;
        });
        return browser.controlFlow().execute(callback); //returning the callback within the Protractor controlFlow queue
      });

我想我最大的困惑是我不知道我是否需要那个world.js来在Chrome浏览器上运行我的测试;我不关心zombie.js无头浏览器,因为他们在cucumberjs github页面上使用:https://github.com/cucumber/cucumber-js

由于那个world.js,我是否遇到了所有这些问题,用更新的cucJs设置我的量角器测试?基本上我的测试全部通过,即使我故意投入一个失败的案例,也都是绿色的。令人沮丧的;希望有人可以提供帮助

0 个答案:

没有答案