Last Updated: February 25, 2016
· dperezrada

Speed up Selenium

Selenium is a great tool, specially to create automatic test or crawl something. But selenium is really slow :(

If it's slow, why don't you use Phantomjs (it's faster)? For me at less two reasons:
- You already have code written in Selenium
- You use the awesome Link to create really fast base test and export it to your favorite language for tunning and running.

But there is great news, you can have the speed of phantomjs when using selenium. So we will use phantomjs to run our selenium code, using the ghostdriver (a great video about it Link )

So let get started :)

You will need:
- ruby (for our example)
- npm

Go to a folder

mkdir -p /tmp/speed_selenium
cd /tmp/speed_selenium

Download Selenium Server

curl -O

Start the selenium service

java -jar selenium-server-standalone-2.32.0.jar -role hub

Install phantomjs

npm install -g phantomjs

Start phantomjs with ghostdriver

phantomjs --webdriver=8080

Install gem selenium-webdriver

gem install selenium-webdriver

Install gem rspec

gem install rspec

Download the example

curl -O

RUN the example using firefox, this is the normal way (you can choose your movie) (took 22.32 seconds)

DRIVER=firefox MOVIE=sherlock rspec test_rspec_selenium_ghost.rb

RUN the example using phantomjs (took 7.31 seconds)

DRIVER=phantomjs MOVIE=sherlock rspec test_rspec_selenium_ghost.rb

At less 3 times faster for this example.