Running Selenium/PhantomJS inside a Vagrant box

phantomjs, selenium, vagrant

Solution

I just had the same problem with the `Can not connect to GhostDriver` error. When trying `phantomjs --help`, I got the error

[WARNING] Unable to load library icui18n "Cannot load library icui18n: (libicui18n.so.48: cannot open shared object file: No such file or directory)"

After installing libicu48 (Ubuntu package), `phantomjs --help` gave me

[WARNING] phantomjs: cannot connect to X server

This made sense, since I didn't have an X server installed. Then, I discovered that phantomjs <= 1.4 requires an X server, but >= 1.5 is pure headless. So, instead of relying on my distro's phantomjs package, I installed it using `npm`, and now everything works fine.

Problem

I'm trying to set up testing for a Web app using behaving, which runs on top of behave and splinter - the latter of which in turn uses Selenium to drive PhantomJS. All of this is inside a VirtualBox-provided Vagrant box running CentOS 6.4. I've installed Selenium via `pip`, and I've installed PhantomJS from the Nux Dextop repo. Trying to run my tests freezes Behave for 30 seconds, then raises: ``` selenium.common.exceptions.WebDriverException: Message: 'Can not connect to GhostDriver' ``` I think I've nailed it down to not being able to open a socket, and indeed, when I try to do this from the Python interactive shell, I can't open any socket to localhost at all. How do I get my tests to run?

Original source