This Gist shows how to start and stop Xvfb from a Grunt script as part of your build. This is useful if you want to run unit tests in a browser in a headless setting.
- Make sure that Xvfb is installed on your system, e.g. through your Linux distribution's package manager.
- Make sure that the Xvfb executable is on your PATH.
Install the following packages:
npm install --save-dev grunt-env
npm install --save-dev grunt-shell-spawn
The first is required for setting the required DISPLAY environment variable, the second for starting/stopping Xvfb.
In your Gruntfile, set up the configurations for the two plugins and create a task for starting Xvfb before running your tests, and then stopping it when your tests have run.
The below example Gruntfile.js
contains a standard configuration for running the tests using Protractor. Adjust as necessary.
Xvfb will be started in asynchronous mode in order to keep it running while the tests are executed.
To run the tests without Xvfb, e.g. on your local machine, simply run
grunt protractor:run
To run the tests with Xvfb, e.g. on your headless build server, run the following instead:
grunt protractor-xvfb
Hi,
I'm trying to use grunt with protractor and xvfb, but when I used "grunt protractor-xvfb":
Running tasks: protractor-xvfb
Running "protractor-xvfb" task
Warning: Task "shell" not found. Use --force to continue.
My grunt version:
grunt-cli v0.1.13
grunt v0.4.5
My protractor version:
Version 2.1.0
I have Xvfb installed already
And I installed grunt-env and grunt-shell-spawn like you said.
Do you know what can be ?