Exception while running Selenium on AWS EC2 instance

amazon ec2amazon-web-servicesfirefoxselenium

I am facing this exception when I run a Selenium test case using the Firefox driver on the AWS EC2 instance which is the headless server. I installed Firefox and all the necessary changes for it

org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/opt/firefox/firefox-bin) on port 7055; process output follows:
�*** e = [Exception… "Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]" nsresult: "0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)" location: "JS frame :: chrome://browser/content/utilityOverlay.js :: getShellService :: line 339" data: no]

Please can anyone help me with this exception?

Best Answer

First install xvfb which will allow you to run it with a "virtual screen".

sudo yum -y install xorg-x11-server-Xvfb 

Then you should check out this helpful post which will help you get firefox installed on amazon EC2. This is because you can't just do sudo yum install firefox on EC2. So, basically you create a file (I used this gist) on the EC2 instance that he provides and then run it to install firefox and all of it's dependancies. http://joekiller.com/2012/06/03/install-firefox-on-amazon-linux-x86_64-compiling-gtk/

When the script runs it will install firefox in

/usr/local/bin/firefox

by default I believe.

Once it has installed you probably then need to add it to your path as the above link also explains. But you should also add the DISPLAY system variable though so do something like this...

cat << EOF >> ~/.bashrc
PATH=/usr/local/bin:\$PATH
DISPLAY=:99
export PATH
export DISPLAY
EOF

Then you have to kick off xvfb for screen 99 so it will be able to run firefox on it's "virtual screen". Like so...

Xvfb :99 -screen 0 1024x768x16 &

Then hopefully when you re-run your selenium tests it will find firefox on the path and run it in the correct "virtualised" screen on that EC2 instance.

As a side note - I am not by any means an expert of any type in amazon linux so... Goodluck.

Alternatively, you could investigate running against selenium server which you could fire up on an amazon EC2 ubuntu micro instance, which you can easily setup to have a GUI.

Related Topic