user2490003
user2490003

Reputation: 11890

Disabling JavaScript when using Poltergeist and Capybara's default driver

My setup is using poltergeist as the Capybara driver for all my tests, both JS and non-JS.

# spec/rails_helper.rb
require "capybara/poltergeist"

# ...
# ...

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, js_errors: true)
end

Capybara.configure do |config|
  config.ignore_hidden_elements = true
  Capybara.default_driver = :poltergeist
  Capybara.javascript_driver = :poltergeist
end

I have some tests where I confirm that certain features on my app are still working even with javascript disabled. For those tests, I of course disable javascript with js: false.

describe "accessibility" do
  describe "JavaScript disabled", js: false do
    before(:each) { visit root_path }

    it "user can still log in" do
      # ...
    end
  end
end

However, I'm noticing that these js:false tests still use JavaScript. I can confirm this by printing debug statements to the console log in JavaScript.

Is there a way to disable JavaScript when using poltergeist? Or is it always enabled? Is it even valid to use poltergeist as a non-JS driver?

Thanks!

Upvotes: 1

Views: 752

Answers (1)

Dave Schweisguth
Dave Schweisguth

Reputation: 37607

No, there doesn't seem to be a way to use poltergeist without Javascript (unless you modify poltergeist yourself). According to this Github issue it would require support in phantomjs, which is available in a patch but not in master.

Upvotes: 1

Related Questions