0
votes

Poltergeist accepts a blacklist and whitelist while configuring it as a driver for Capybara. The documentation states:

Poltergeist supports URL blacklisting, which allows you to prevent scripts from running on designated domains.

While this is great, it doesn't help my issue where I would like to block certain assets from being requested/loaded as it is causing issues in my Travis-CI where those assets are returning as 500 Server Errors and causing my tests to fail even though they should be green.

URIs should be blocked as: ['/stylesheet/*', 'some-image-name.jpg']

Is this possible to do with Poltergeist? Or is there a way to have a Capybara cucumber test not fail just because an asset returned a 500 server error?

Capybara.register_driver :poltergeist do |app|
  poltergeist_opts = {
    window_size: [1280, 1024],
    url_blacklist: ['/stylesheets/select_box_arrow.gif', '/stylesheets/ui-icons_ffffff_256x240.png']
  }

  Capybara::Poltergeist::Driver.new(app, poltergeist_opts)
end
1

1 Answers

1
votes

Poltergeist blacklists are specified as wildcard strings (* and . as special characters) that are substring matched to the full urls being requested, so yes you can block the specific things you want by specifying exactly what you've shown in your question in the url_blacklist array. However, if the 500 error is coming from your app you'd be much better off just fixing your app/test setup so that it doesn't return a server error when requesting valid assets (fix asset deploy on travis, etc).

The other option is to prevent Capybara from failing tests on server errors - Capybara.raise_server_errors = false - however that could possibly hide server errors you care about.