El Nubro
El Nubro

Reputation: 624

cucumberOpts.tags usage with Protractor + CucumberJs + Gulp

Hello All!

I've the following versions installed:

"protractor": "~2.5.1",
"gulp-protractor": "1.0.0",
"cucumber": "~0.7.0",

I had installed this, because the project has version < 4 of NPM and Protractor 3.0.0 needs that.

And I have the follwing on my protractor.conf.js

  framework: 'cucumber',
    //frameworkPath: require.resolve('protractor-cucumber-framework'),
    cucumberOpts: {
        require: 'features/step_definitions/**/*.js',
        format: 'pretty',
        tags: '@Test',
    },

I've my gulp task looks like this:

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

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

        if (!args.baseUrl) {
            baseUrl = 'http://test.me/frontend-build-tests/';
        } else if (args.baseUrl.match(/^(?:https?\:)?\/\//)) {
            baseUrl = args.baseUrl;
        } else {
            baseUrl = 'http://tests..me/frontend-build-tests/' + 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/page-objects/*.js'
            'e2e/features/*.feature'
        ])
        .pipe(plugins.protractor.protractor({
            configFile: protractorConfig,
            args: [
                '--verbose',
                '--no-stackTrace',
                //'--cucumberOpts.tags', tag,
                '--params.test.config', testConfig,
                '--baseUrl', baseUrl
            ]
        }))
        .on('error', function() {
            done();
            process.exit(1);
        });
    };
};

I run this with a npm run test-e2e command, which runs an script that only contains these 2 lines

#!/bin/bash -ex

gulp test-e2e "$@"

On the above configuration you may notice that I had commented out the --cucumberOpts.tags option, because I could not get it to work, when I run the test using the parameter npm run test-e2e -- --baseUrl http://local.me --tag "@Test" it's like it does not hear that parameter, because I can see that it executes all the tests and not the tagged ones.....

So... what am I doing wrong here?

Upvotes: 3

Views: 5971

Answers (1)

El Nubro
El Nubro

Reputation: 624

I'm Leaving the answer to my own post in case someone runs into the same proble, had found that modify as follow, I got it to work, apparently the order of the parameters was wrong, as well that we don't need to enclose with quotes the @ANYTHING...

gulp task:

  var protractorConfig = '',
        testConfig = '',
        environment = args.environment || 'devel',
        tag = args.tag || '@Sanity',
        baseUrl;

gulp task:

 .pipe(plugins.protractor.protractor({
            configFile: protractorConfig,
            args: [
                '--verbose',
                '--no-stackTrace',
                '--params.test.config', testConfig,
                '--baseUrl', baseUrl,
                '--cucumberOpts.tags', tag
            ]
        }))

Protractor config file:

framework: 'cucumber',
//frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
    require: 'features/step_definitions/**/*.js',
    format: 'pretty'
},

And the command should look like

npm run test-e2e -- --baseUrl http://local.me/e2e/cases/devel/ --tag @Sanity

Upvotes: 2

Related Questions