如何配置量角器以使用 Cucumber [英] How to configure Protractor to use Cucumber

查看:169
本文介绍了如何配置量角器以使用 Cucumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

截至 0.20.1 量角器现在完全支持黄瓜,但我我正在努力寻找有关如何正确配置它的任何文档.知道如何设置 world.js 吗?

As of 0.20.1 Cucumber is now fully supported in Protractor but I'm battling to find any documentation on how to configure it properly. Any idea how you would setup world.js?

我在 https://github.com 上找到了这个例子/whyvez/angular-cucumber-example/blob/master/features/support/world.coffee 但我不确定您是否仍需要将所有需要的模块和配置指定为量角器配置文件(referenceConf.js) 已经拥有所有这些信息.

I have found this example at https://github.com/whyvez/angular-cucumber-example/blob/master/features/support/world.coffee but I'm not sure if you would still need to specify all the require modules and configuration as the protractor config file (referenceConf.js) would have all this info already.

assert = require 'assert'
path = require 'path'

protractor = require 'protractor'
webdriver = require 'selenium-webdriver'

driver = new webdriver.Builder().
  usingServer('http://localhost:4444/wd/hub').
  withCapabilities(webdriver.Capabilities.chrome()).
  build()

driver.manage().timeouts().setScriptTimeout(100000)

ptor = protractor.wrapDriver driver

class World
  constructor: (callback) ->
    @browser = ptor
    @By = protractor.By
    @assert = assert
    callback()

module.exports.World = World

推荐答案

我创建了一个示例项目来展示如何使用 Cucumber 配置 Protractor 并利用世界.

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

The World 是一个可以在不同场景之间共享共性的地方,这样您就可以让代码井井有条.

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

实际上,您只需要在/features 下名为/support 的文件夹中创建您的 world.js 文件.你也会把你的钩子放在那里.每个属性或函数都将在您的步骤定义中可用.

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

然后在您的步骤中:

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;

您的 protractor.js 配置文件如下所示:

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',

};

这是 GitHub 存储库.

This the GitHub repository.

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

希望这会有所帮助.

这篇关于如何配置量角器以使用 Cucumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆