Last Updated: February 25, 2016
·
2.488K
· 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 https://selenium.googlecode.com/files/selenium-server-standalone-2.32.0.jar

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 https://gist.github.com/dperezrada/5379732/raw/bfb8898ddfb37a8f7072bbe963f687cfc17d16f3/test_rspec_selenium_ghost.rb

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.