1

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!

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
user2490003
  • 10,706
  • 17
  • 79
  • 155

1 Answers1

1

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.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
  • ahh, that's unfortunate. Good to know others have that issue too. That post is from two years ago, so not sure if it's ever going to be supported anytime soon. Looks like I'll just have to use something like `capybara-webkit` for non-js tests. Any recommendations on that versus `selenium` ? – user2490003 Apr 22 '16 at 05:51
  • Not specifically for non-JS testing. In general [I've had better luck with poltergeist than with capybara-webkit](http://stackoverflow.com/questions/23951381/how-do-poltergeist-phantomjs-and-capybara-webkit-differ), but others have had different experiences. I've less experience with Selenium. – Dave Schweisguth Apr 22 '16 at 12:45