Debugging integration is still a pain with headless driver like poltergeist. In this tutorial I’ll show you a good tip how to switch to selenium for debugging with Firefox.
Testing with selenium-webdriver is always slower than headless poltergeist, abeit easier to debug. Debugging with selenium brings up Firefox browser window with CSS and JS correctly loaded whilst it’s not the same case with poltergeist.
I am going to show you to have both of drivers in same Rails app and you could switch to selenium for debugging easily!
First thing is to add into your
1 2 3 4 5
I want to point out that we explicitly set
reauire: false so that capybara won’t load any driver.
This help avoid conflicts when two drivers are loaded at same time.
Please make sure you run ‘bundle install’ before moving to the next step.
Now I assume that you are using default RSpec’s helper
spec/spec_helper for your integration test. Please ensure
that this line is in your file:
1 2 3
The above line tells RSpec to pick up any extensions/helpers that we place under
Next we create new
spec/support/feature_spec_extensions.rb with content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
The above RSpec helper sets default driver to poltergeist and should ENV variable FF is set, it will switch to selenium-webdriver.
So to run a feature spec in poltergeist, we do:
and to test with selenium-webdriver, we do:
I also provide a helper method
hang which will hang the page. Simply place it to the line
that you want and Firefox browser will open up if selenium is used. Eg:
1 2 3 4 5 6 7
That’s it for now folks. Credits to Nikolai Nemshilov, my ex-colleague who came up with this brilliant hybrid idea.