How to configure Protractor to use Cucumber

别等时光非礼了梦想. 提交于 2019-12-04 01:38:32

I have created a sample project to show how to configure Protractor with Cucumber and make use of the World.

The World is a place to share commonalities between different scenarios so that you can keep you code organised.

Actually, all you need is to create your world.js file in a folder called /support under /features. You would place there your hooks as well. Every property or function there will be available in your step definitions.

world.js:

module.exports = function() {

  this.World = function World(callback) {
    this.prop = "Hello from the World!";

    this.greetings = function(name, callback) {
      console.log("\n----Hello " + name);
      callback();
    };

    callback();
}

And then in your steps:

var sampleSteps = function() {

    this.Given(/^this is the first sample$/, function (callback) {
      console.log("\n----" + this.prop);
      callback();
    });

    this.Given(/^this is the second sample$/, function (callback) {
      this.greetings("everybody", callback);
    });

};

module.exports = sampleSteps;

Your protractor.js configuration file would look something like this:

exports.config = {

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

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

  baseUrl: 'http://localhost:8081/',

  framework: 'cucumber',

};

This the GitHub repository.

https://github.com/plopcas/st-protractor-cucumber

Hope this helps.

Take a look at protractor-cucumbe -- it comes with selenium-webdriver, supports Promises, and is well documented.

It seems to require minimal configuration, and what is required is clearly documented.

aabes

I've gotten good milage from this setup

  class ChtWorld
    chai = require('chai');
    chaiAsPromised = require('chai-as-promised');

    constructor:  ->
      @browser = @protractor = require('protractor').getInstance()
      @By = @protractor.By
      chai.use(chaiAsPromised)
      @expect= chai.expect


  module.exports= ->
    this.World= (callback) ->
      w = new ChtWorld()
      callback(w)

Since protractor is already setup, just getting a reference to it is sufficient (note that for Cucumber to correctly load up the new world, the modules.exports has to be just right).

As a side note, this is located in features/support/world.coffee, and not explicitly added to the 'requires' list (trying to do that got me into Gherkin Lexing error problems).

Rassiel Rebustillo

Add it as a framework in the configuration file:

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

  // path relative to the current config file
  frameworkPath: 'protractor-cucumber-framework'

  // relevant cucumber command line options
  cucumberOpts: {
    format: "summary"
  }
};

More information here: Protractor Frameworks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!