Search code examples
ruby-on-railsseleniumselenium-webdriverpoltergeist

How to use selenium and poltergeist together in RSpec?


I have a rich frontend in my application. Some of my tests not works well with poltergeist, because of animations and AJAX requests, but works fine with selenium.

How can i use them together in one project and in one test session?


Solution

  • If you're using the standard RSpec configuration with Capybara (require 'capybara/rspec') then you can override the normal driver that would be used for a given test with :driver metadata

    it "should do something", driver: :selenium do
      # will use the selenium driver for this test
    end
    
    it "should do something else", driver: :poltergeist do
      # will use the poltergeist driver for this test
    end
    

    that could also be specified on the enclosing feature if you want the whole feature to use a specific driver

    feature "blah balh", driver: :selenium do
      # all scenarios here would use the selenium driver unless overridden with their own :driver metadata