首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >吞角量角器与黄瓜的集成

吞角量角器与黄瓜的集成
EN

Stack Overflow用户
提问于 2016-05-12 14:50:13
回答 2查看 632关注 0票数 1

所以,我一直在用量角器(茉莉2)编写非常好的e2e测试,但是现在我的要求已经改变了:我需要从Jasmine2切换到Cucumber。到目前为止,黄瓜不再直接由量角器支持。我尝试了自定义框架安装=>不成功。如前所述,我使用的是吞咽角量角器,它为我提供了一个很好的、简单的工作环境(在运行测试时打开/关闭webdriver、gulp命令等),我仍然想保留它。

这是我的配置:

package.json

代码语言:javascript
复制
...

  "devDependencies": {
    "angular-mocks": "^1.5.1",
    "browser-sync": "^2.10.0",
    "cucumber": "^0.10.2",
    "del": "^2.1.0",
    "gulp": "^3.9.1",
    "gulp-angular-protractor": "^0.1.1",
...

gulpfile.js:

代码语言:javascript
复制
gulp.task('e2e', function(callback) {
    gulp
        .src(['./dist/**/*.e2e.js'])
        .pipe(gulpProtractorAngular({
            'configFile': 'protractor.conf.js',
            'debug': false,
            'autoStartStopServer': true
        }))
        .on('error', function(e) {
            console.log(e);
        })
        .on('end', callback);
});

protractor.conf.js

代码语言:javascript
复制
    exports.config = {
    baseUrl: 'http://localhost:3000',
    specs: ['dist/**/*.feature'],
    directConnect: true,
    exclude: [],
    multiCapabilities: [{
        browserName: 'chrome'
    }],
    allScriptsTimeout: 110000,
    getPageTimeout: 100000,

    framework: 'custom',
    frameworkPath: require.resolve('cucumber'),
    cucumberOpts: {
        require: 'dist/**/*steps.js',
        format: 'pretty'
    },

    /**
     * ng2 related configuration
     *
     * useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching
     * `rootEl`
     *
     */
     useAllAngular2AppRoots: true
};

虚拟测试:

world.js

代码语言:javascript
复制
module.exports = function() {

  this.World = function World(callback) {
    this.prop = "Hello from the World!"; // this property will be available in step definitions

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

    callback(); // tell Cucumber we're finished and to use 'this' as the world instance
  };
}

login.component.feature

代码语言:javascript
复制
Feature: Sample

Scenario: First sample
Given this is the first sample

Scenario: Second sample
Given this is the second sample

login.component.steps.js

代码语言:javascript
复制
    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;

项目文件夹树如下所示:

问题:当我运行gulp e2e时,我得到:

代码语言:javascript
复制
launcher] Error: TypeError: require(...).run is not a function

在C:\Users\Documents\dev\node_modules\gulp-angular-protractor\node_m dules\gulp-protractor\node_modules\protractor\lib\runner.js:337:35 at _fulfilled (C:\Users\Documents\dev\node_modules\gulp-angular-protr ctor\node_modules\gulp-protractor\node_modules\protractor\node_modules\q\q.js:7 7:54)在self.promiseDispatch.done (C:\Users\Documents\dev\node_modules\-angular-protractor\node_modules\gulp-protractor\node_modules\protractor\node_m dules\q\q.js:826:30( Promise.promise.promiseDispatch (C:\Users\Documents\dev\node_modul ode_modules\q\q.js:759:13) at C:\Users\Documents\dev\node_modules\gulp-angular-protractor\node_m dules\gulp )-protractor\node_modules\protractor\node_modules\q\q.js:525:49在同步器(C:\Users\Documents\dev\node_modules\gulp-angular-protractor node_modules\gulp-protractor\node_modules\protractor\node_modules\q\q.js:108:17

知道我做错什么了吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-16 17:25:13

首先,你为什么要说脯氨酸不支持黄瓜?我的意思是,您需要使用它作为一个自定义的FW,您需要对您的配置文件执行以下操作才能使用Protractor CucumberJS.

代码语言:javascript
复制
   framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),
    specs: [
        'e2e/features/*.feature'
    ],
    cucumberOpts: {
        require: './e2e/features/*/*.js',
        format: 'pretty',
        keepAlive: true
    }

关于吞咽任务,我一直在使用:

代码语言:javascript
复制
"gulp-protractor": "^2.1.0",

具有如下配置的任务:

代码语言:javascript
复制
/**
 * run protractor
 */


var args = require('yargs').argv;

module.exports = function(gulp, plugins) {
    return function (done) {
        var protractorConfig = '',
            testConfig = '',
            environment = args.environment || 'devel',
            tag = args.tag || '@Sanity',
            baseUrl;

        if (!args.baseUrl) {
            baseUrl = 'XXXXXXXX';
        } else if (args.baseUrl.match(/^(?:https?\:)?\/\//)) {
            baseUrl = args.baseUrl;
        } else {
            baseUrl = 'XXXXXXXX' + args.baseUrl + '/';
        }

        switch(environment) {
            case 'devel' :
                protractorConfig = 'e2e/protractor.config.devel.js';
                testConfig = '../config/devel';
                break;
            case 'live'  :
                protractorConfig = 'e2e/protractor.config.live.js';
                testConfig = '../config/live';
                break;
            case 'remote' :
                protractorConfig = 'e2e/protractor.config.remote.js';
                testConfig = '../config/live';
                break;
            default:
            case 'build' :
                protractorConfig = 'e2e/protractor.config.build.js';
                testConfig = '../config/build';
                break;
        }

        gulp.src([
            'e2e/features/*.feature'
        ])
            .pipe(plugins.protractor.protractor({
                configFile: protractorConfig,
                args: [
                    '--verbose',
                    '--no-stackTrace',
                    '--params.test.config', testConfig,
                    '--baseUrl', baseUrl,
                    '--cucumberOpts.tags', tag
                ]
            }))
            .on('error', function() {
                done();
                process.exit(1);

            });
    };
};

希望这能帮上忙

票数 0
EN

Stack Overflow用户

发布于 2016-05-23 20:07:18

我的意思是:量角器不再是现成的黄瓜了。我按照建议使用“量角器-黄瓜骨架”使其工作。这是我的protractor.conf:

代码语言:javascript
复制
exports.config = {
    baseUrl: 'http://localhost:3000',
    specs: ['dist/**/*.feature'],
    directConnect: true,
    exclude: [],
    multiCapabilities: [{
        browserName: 'chrome'
    }],
    allScriptsTimeout: 110000,
    getPageTimeout: 100000,

    framework: 'custom',
    frameworkPath: require.resolve('protractor-cucumber-framework'),
    cucumberOpts: {
        require: 'dist/**/*steps.js',
        format: 'pretty',
        tags: '@Login',
        keepAlive: false
    },
//     cucumberOpts: {
//     require: 'dist/**/steps.js',
//     tags: '@dev',
//     format: 'progress',
//     profile: false,
//     'no-source': true
//   }

    /**
     * ng2 related configuration
     *
     * useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching
     * `rootEl`
     *
     */
     useAllAngular2AppRoots: true
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37190461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档