Last Updated: February 25, 2016
·
2.255K
· rondale-sc

Prevent Phantom/Capybara from requesting images

Recently ran into an issue where my cucumber suite was throwing a timeout error. The error was thrown because an image hosted externally wasn't rendering.

Luckily Phantomjs has some amazing Command Line Options available to help us along. On of which is --load-images which allows us to prevent phantom from making the image request.

Let's setup poltergeist (Phantomjs' capybara driver) to accept these options...

Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
  options = { 
    phantomjs_options: ['--load-images=no'] 
   }
  Capybara::Poltergeist::Driver.new(app,options)                                                                                                              end

As you can see we can specify a list of the CLI options and they'll be set when we run our suite. And there you have it, prevent phantomjs from requesting images!

Thanks for reading!