Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Rspec Essentials

You're reading from   Rspec Essentials Develop testable, modular, and maintainable Ruby software for the real world using RSpec

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781784395902
Length 222 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Tadayon Tadayon
Author Profile Icon Tadayon
Tadayon
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

RSpec Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Exploring Testability from Unit Tests to Behavior-Driven Development 2. Specifying Behavior with Examples and Matchers FREE CHAPTER 3. Taking Control of State with Doubles and Hooks 4. Setting Up and Cleaning Up 5. Simulating External Services 6. Driving a Web Browser with Capybara 7. Building an App from the Outside In with Behavior-Driven Development 8. Tackling the Challenges of End-to-end Testing 9. Configurability 10. Odds and Ends Index

Getting started with Capybara and Selenium


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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime
Visually different images
Modal Close icon
Modal Close icon