Understanding Capybara Setup
Let’s understand the Capybara Setup. Capybara requires Ruby 1.9.3 or later. However, it can be used in two modes
- Firstly, UI
- Subsequently, Headless
So, to install, add this line to your Gemfile and run bundle install:
gem ‘capybara’
In addition, if the application that you are testing is a Rails app, add this line to your test helper file:
require ‘capybara/rails’
Not to mention, in Rails 4.0/4.1 the default test environment (config/environments/test.rb) is not threadsafe. So, if you experience random errors about missing constants, add config.allow_concurrency = false to config/environments/test.rb.
However, if the application that you are testing is a Rack app, but not Rails, set Capybara.app to your Rack app:
Capybara.app = MyRackApp
If you need to test JavaScript, or if your app interacts with (or is located at) a remote URL, you’ll need to use a different driver.
In UI mode, add the following to the Gemfile:
gem install capybara
gem install #{web_driver_on_which_capybara_runs}
For Headless mode
gem install capybara
gem install #{web_driver_on_which_capybara_runs}
apt-get install firefox
apt-get install xvfb
gem install selenium-webdriver # if using selenium-webdriver
gem install capybara-webkit # if using capybara-webkit
apt-get install libqtwebkit-dev # if using capybara-webkit
Make your resume stand out and become a Certified Capybara Testing Professional. Try free practice tests here!
A great career is just a certification away. So, practice and validate your skills to become Certified Capybara Testing Professional