Nickolay Platonov
13 November 2012

Siesta tip: Integrating PhantomJS with your IDE

In this post we would like to share a simple tip that will allow you to speed up your work […]

In this post we would like to share a simple tip that will allow you to speed up your work when writing or debugging your Siesta tests. A common scenario is to find that you need to change only few characters in your code, and re-run some test. Sometimes you just want to experiment, like comment out one line and see the results. You can do this without leaving your IDE, by just pressing a hot-key.

To enable this, you need to create an “external command” in your IDE. This is supported by all modern IDEs these days and is very simple to setup. The command should launch an external command line script and display the output from it in the IDE console window.


If you are using WebStorm:

  1. Open preferences -> External tools
  2. Hit + to create a new tool, name it ‘Siesta’
  3. In the Program field, enter the path to your phantomjs script
  4. In the Parameters field, enter the path to the ‘index.html’ of your test suite, and — include $FileName$, to enable launching only the test you’re currently working on.
  5. Now, open Preferences -> KeyMap, and map your favorite keyboard shortcut to be able to launch the test quickly.

External Tools in WebStorm

After running this command on a Siesta test, you should see something like this in the WebStorm console window.


For Eclipse users:

1. In the top menu, select “Run -> External tools -> External tools configuration”. Then click “add new” and enter the configuration values like this:

Here we’ve specified the path to the PhantomJS launcher (it will be different for you of course) and we use two variables: ${project_name} and ${selected_resource_name}. ${project_name} is necessary if you (like us) are working on multiple projects. If you are working on a single project you can just hardcode the harness URL. ${selected_resource_name} value contains the name of the currently selected file and is being passed to the “–include” switch.

2. Now, when editing a test file you can launch this command and should see something like this:

3. Finally you can open your Eclipse key bindings and specify a hot-key for “Runs the last launched external Tool” action, which allows you to launch the test rapidly.

Do you have any tips of your own on how to be productive while writing tests? Let us know!

Happy testing!

Tips 'n tricks