0

Below is my gruntfile.js . I can run the protractor tests on UI using 'grunt protractor:run command.

However, when i try running command ' grunt protractor-xvfb' so that i can run my tests in headless mode, the browser still launches and tests execute in the same way as using grunt protractor:run command.

What i am expecting is that the tests run in background.

module.exports = function (grunt) {

require('load-grunt-tasks')(grunt);

  grunt.initConfig({
      protractor: {
      options: {
          keepAlive: true,
          configFile: "../spike-protractor/app/Conf/conf.js",
          noColor: false,
          args: {
            baseUrl: 'https://xxx/xxx/'
          }
      },
      run: {}
  },
  shell: {
      xvfb: {
          command: 'Xvfb :99 -ac -screen 0 1600x1200x24',
          options: {
              async: true

          }
      }
  },
  env: {
      xvfb: {
          DISPLAY: ':99'
      }
  }
  });

  grunt.loadNpmTasks('grunt-protractor-runner');
  grunt.loadNpmTasks('grunt-shell-spawn');
  grunt.loadNpmTasks('grunt-env');
  grunt.loadNpmTasks('grunt-protractor-webdriver');
  grunt.registerTask('protractor-chrome', ['protractor:chrome']);

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

}

I tried commenting out line code 'protractor:run'from grunt.registerTask and running grunt protractor-xvfb gives me the below output which is correct as per code. This executes so fast as if nothing happened. i think there is something that i am missing in config/code to achieve headless testing .

Running "shell:xvfb" (shell) task

Running "env:xvfb" (env) task

Running "shell:xvfb:kill" (shell) task

Done.

how do i actually proceed on doing headless testing using xvfb + grunt+ protractor ?

3 Answers3

0

Is probably more practical for your use case to go with Zalenium if you want headless Chrome or Firefox testing, video recording, VNC live preview, local dashboard.html among other features.

You can get started with the one-liner:

curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start

And/or also watch the presentation:

https://www.youtube.com/watch?v=W5qMsVrob6I

Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110
0

You did not specify to run your conf.js properly. Remove the part

    grunt.registerTask('protractor-chrome', ['protractor:chrome']);

from your gruntfile.js specified in your question. Edit your gruntfile.js and add below:

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

Once you add it if you want to run without xvfb use command "grunt protractor:run".

If you want to run using xvfb then use command "grunt protractor-xvfb"

learner
  • 475
  • 3
  • 9
  • 23
0

I found a workaround for this to use the below command and specify conf.js -

xvfb-run --server-args='-screen 0, 1600x1200x24' protractor app/Conf/conf.js

Doing this allows to me run my tests in headless mode.

Even if you are not using Grunt in your project, you can directly do npm install xvfb and use this command... pass it to teamcity command line parameters and it will work there as well.