Skip to content

PhantomJs

Please note: From June 2019, Wallaby.js no longer uses PhantomJs as its default test runner. Additionally, Wallaby.js will no longer ship with PhantomJs version 2.1.1. If you would like to use PhantomJs, you must configure to use it explicitly by providing the env.kind setting. If you rely on the PhantomJs version that ships with Wallaby.js, you will need to configure your project to include PhantomJs as a dependency.

While we support the use of PhantomJs, PhantomJs has been deprecated in favor of headless chrome. We recommend changing your Wallaby configuration to use Google Chrome (headless) instead of PhantomJs for browser-based tests.

If you need to use PhantomJs, you can add it to your project using:

npm install phantomjs-prebuilt --save-dev

After installing PhantomJs in your project, you will need to update your wallaby configuration:

module.exports = function () {
return {
...
env: {
kind: 'phantomjs'
}
...
};
};

If you have another version of PhantomJs installed in your project’s node_modules and have specified phantomjs in your configuration’s env.kind setting, then no further configuration is required.

If you are not using the latest version of Wallaby, or would like to use a system-level PhantomJs, you may use the env.runner setting to specify the path to it.

Relative path is supported, so if you have an NPM module that installs platform-specific PhantomJs version, for example phantomjs-prebuilt), you may just reference PhantomsJs 2 like so:

npm install phantomjs-prebuilt --save-dev
module.exports = function () {
return {
files: [
...
],
tests: [
...
],
env: {
type: 'browser',
kind: 'phantomjs',
runner: require('phantomjs-prebuilt').path
}
};
};

You may also use absolute path or even just phantomjs if you have it in PATH:

module.exports = function () {
return {
files: [
'lib/**/*.js'
],
tests: [
'test/**/*Spec.js'
],
env: {
type: 'browser',
kind: 'phantomjs',
runner: '/Users/user/Downloads/phantomjs-2.1.1-macosx/bin/phantomjs'
// or
// runner: 'C:\\Tmp\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe'
// or (if you have phantomjs 2 path set in your system environment) just
// runner: 'phantomjs'
}
};
};

PhantomJs 1.9.8

Previously, wallaby.js was using PhantomJs 1.9.8. If you would like to switch back to this version, you may do this:

npm install phantomjs@1.9 --save-dev
module.exports = function () {
return {
files: [
...
],
tests: [
...
],
env: {
type: 'browser',
kind: 'phantomjs',
runner: require('phantomjs').path
}
};
};

Or, if you have PhantomJs 1.9.8 path set in your system environment, you may just do:

module.exports = function () {
return {
files: [
...
],
tests: [
...
],
env: {
type: 'browser',
kind: 'phantomjs',
runner: 'phantomjs'
}
};
};

You may also specify a relative or absolute path to the PhantomJs 1.9.8 executable.

Passing PhantomJs params

You may pass PhantomJs params, for example --local-to-remote-url-access=true, via env.params.runner.