Grunt + Protractor - Task "shell:xvfb" not found

627 views Asked by At

I'm trying to use grunt to run Xvfb and my protractor tests, but when I executed my Task protractor-xvfb, I've got this return:

Running tasks: protractor-xvfb Warning: Task "protractor-xvfb" not found. Use --force to continue.

Aborted due to warnings.

My Gruntfile.js:

module.exports = function(grunt) {


    grunt.initConfig({
        protractor: {
            options: {
                keepAlive: true,
                configFile: "protractor.conf.js"
            },
            run: {}
        },

        shell: {
            xvfb: {
                command: 'Xvfb :99 -ac -screen 0 1600x1200x24',
                options: {
                    async: true
                }
            }
        },
        env: {
            xvfb: {
                DISPLAY: ':99'
            }
        }

});


    grunt.registerTask('protractor-xvfb',[
        'shell:xvfb',
        'env:xvfb',
        'protractor:run',
        'shell:xvfb:kill'
        ]);

// assim funciona
    grunt.registerTask('test', 'Test task.', function() {
        grunt.log.writeln('Lorem ipsum dolor sit amet.');
    });

}

When I executed my Task test, it is sucessful and I've got this return:

Running tasks: test

Running "test" task Lorem ipsum dolor sit amet.

Done, without errors.

OBS: My tests with protractor without grunt is working fine. Return:

Finished in 24.753 seconds

9 tests, 5 assertions, 0 failures

OBS2: I'm following this example: Running Xvfb from Grunt

2

There are 2 answers

0
Rfranca On BEST ANSWER

I solved my problem !

First of all My Gruntfile.js wasn't on my project root directory and I need it in project root directory close to package.json to load my plugins to run those tests. When my Gruntfile.js was on the wrong path when I added those plugin to load my test fails:

 grunt.loadNpmTasks('grunt-shell-spawn');
 grunt.loadNpmTasks('grunt-env');
 grunt.loadNpmTasks('grunt-protractor-runner');

Fail message:

Registering "grunt-shell-spawn" local Npm module tasks.
>> Local Npm module "grunt-shell-spawn" not found. Is it installed?

Registering "grunt-env" local Npm module tasks.
>> Local Npm module "grunt-env" not found. Is it installed?

Registering "grunt-protractor-runner" local Npm module tasks.
>> Local Npm module "grunt-protractor-runner" not found. Is it installed?
Loading "Gruntfile.js" tasks...OK

I removed all my grunt stuff that I had install and installed again.

With my Gruntfile in the right path I could be able to load my plugins and run my tests with Grunt + Xvfb + Protractor.

1
Nathan Thompson On

I'm not sure if this is the core issue, but you have shell.xvfb.command set to an array containing a string in your code, whereas as the example you linked only has a single string.