We'll talk about why Capybara is useful and how we're going to use it in our tests in some depth. First, let's see how we can use it to control a browser to interact with a web page. We'll do this from irb
, the Ruby console.
We'll need to install the Capybara and Selenium/WebDriver gems first:
$ gem install capybara selenium-webdriver
The above may take a couple of minutes, since there are a few dependencies for each gem. We'll also need to make sure Mozilla Firefox is installed on our system. Now we can go into irb
and control Firefox with Ruby code!
We first require the Capybara gem, then we set the driver to use Selenium, since the default driver, Rack::Test
, cannot control a real browser. Finally, we use the Capybara.visit
method to browse to http://si.edu, the website for the Smithsonian Institution in Washington, DC. If all goes well, after you hit Enter for that last command, Firefox should launch and load the URL. You should see a page like...