Search code examples
ruby-on-rails-3capybarapoltergeist

Capybara Poltergeist/PhantomJS testing - disable javascript on a page


On of my projects is fairly javascript intensive, so I have a <noscript> alert for users that might come in with Javascript disable on their browsers.

I'm trying to write a test for my test suite that just validates this behavior, but I can't figure out how to tell Capybara/Poltergeist (which I use for my feature tests) to disable javascript before making requests. I can't find anything clear in the documentation. Has anyone else run into something like this?


Solution

  • So, I still have no idea how to do this in Poltergeist, but I figured out how to get it set up in Selenium:

    Capybara.register_driver :selenium_firefox_nojs do |app|
      profile = Selenium::WebDriver::Firefox::Profile.new
      profile["javascript.enabled"] = false
      Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
    end