Running Capybara Under Chrome, Poltergeist or Firefox

As a default Capybara runs under Firefox but if you want to change your driver you have to change your javascript driver to your new driver. But you also must define your driver as registered Capybara driver. For example if you want to run with Chrome and change your driver to chrome but not define it, it gives some errors like following
irb(main):007:0> visit ""
Capybara::DriverNotFoundError: no driver called :chrome was found, available drivers: :rack_test, :selenium, :poltergeist
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/session.rb:77:in `driver'
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/session.rb:226:in `visit'
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/dsl.rb:51:in `block (2 levels) in '
if you add the following line into your env.rb module, you will successfully run under Chrome driver.
Capybara.register_driver :chrome do |app|, :browser => :chrome)

If you want to run via terminal under Chrome driver, you must define Capybara configuration otherwise it will give the following error:
irb(main):011:0* visit "htpp://"
ArgumentError: rack-test requires a rack application, but none was given
from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/rack_test/driver.rb:16:in `initialize'
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/Capybara.rb:372:in `new'
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/Capybara.rb:372:in `block in '
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/session.rb:79:in `call'
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/session.rb:79:in `  driver'
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/session.rb:226:in `visit'
  from /Library/Ruby/Gems/2.0.0/gems/capybara-2.4.1/lib/capybara/dsl.rb:51:in `block (2 levels) in '
If you add the following lines to terminal, you will successfully run Chrome driver via terminal:
Capybara.configure do |config|
     config.run_server = false
     Capybara.default_driver = :chrome
     config.app_host = ''

If you want to run under Poltergeist mode, add the following codes into your environment file:
Capybara.register_driver :poltergeist do |app|
   options = {
      :js_errors => false ,
      :timeout => 120,
      :debug => false,
      :phantomjs_options => ['--load-images=no', '--disk-cache=false'],
      :inspector => true,
   }, options)

Finally select your driver in env.rb and then enjoy it :)
#apybara.default_driver = :selenium
Capybara.javascript_driver = :poltergeist
#Capybara.javascript_driver = :chrome


Popular posts from this blog

Selenium Error "Element is not currently interactable and may not be manipulated"

Change Default Timeout and Wait Time of Capybara

Page-Object Pattern for Selenium Test Automation with Python

Performance Testing on CI: Locust is running on Jenkins

How to Set Shared Preferences in Espresso Test for Kotlin and Java