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,
Looks like you have wrong configuration in Gruntfile.js.
Can you paste your Gruntfile.js so I can give you some hint ?