Your SlideShare is downloading. ×
0
Capybaraby:- Omnia Gamal El-Deenemail :- omnia.gamal1988@gmail.comtwitter @Omnia_G
Capybara           Go away           Im busy           NOW
Why Capybara
SetupInstall :   sudo gem install capybaraOr Gemfile   gem "capybara", :group => :test
Using Capybara with RSpec● spec/spec_helper.rb  require capybara/rails  require capybara/rspec● create test directory /spe...
Testtest_file.rb  require spec_helper  describe "home page" do      before :each do          # ......      end     it "dis...
The DSL●   navigating (visit)●   matcher (page.should)●   clicks (click_link - click_button)●   action (fill_in)●   finder...
Example
Drivers● Driver agnostic● Support :    ○ RackTest    ○ Selenium    ○ Capybara-webkit●   Default:       rack_test driver
RackTest● Its pure Ruby, So it interacts directly with Rack    interfaces●   It does not require a server to be startedBut...
Selenium● Runs tests in a real browser● Supports any Javascript your browser supports, just like  real users● Easy to set ...
CAPYBARA-WEBKIT●   Fast●   No browser UI●   Using webkit engine●   console.log output●   Errors in standard output
Setup capybara-webkit:Gemfile  gem "capybara-webkit", :group => :test   ○ You didnt need capybara itself anymore   ○ You w...
Spec_helper.rbENV["RAILS_ENV"] ||= testrequire File.expand_path("../../config/environment", __FILE__)require rspec/railsre...
DatabaseCleaner configurationRSpec.configure do |config|   #...   config.use_transactional_fixtures = false    config.befo...
Reference :●   Example@github OmniaGM/learn-capybara●   Browser testing●   Capybara●   Capybara Cheat Sheet
Capybara with Rspec
Upcoming SlideShare
Loading in...5
×

Capybara with Rspec

7,220

Published on

Learning how to use capybara and capybara-webkit with rspec.
Example :- https://github.com/OmniaGM/learn-capybara

Published in: Technology

Transcript of "Capybara with Rspec"

  1. 1. Capybaraby:- Omnia Gamal El-Deenemail :- omnia.gamal1988@gmail.comtwitter @Omnia_G
  2. 2. Capybara Go away Im busy NOW
  3. 3. Why Capybara
  4. 4. SetupInstall : sudo gem install capybaraOr Gemfile gem "capybara", :group => :test
  5. 5. Using Capybara with RSpec● spec/spec_helper.rb require capybara/rails require capybara/rspec● create test directory /spec/requests● add capybara dsl to RSpec.configure in spec_helper.rb RSpec.configure do |config| config.include Capybara::DSL, :type => :request
  6. 6. Testtest_file.rb require spec_helper describe "home page" do before :each do # ...... end it "displays greeting" do # ......... end end
  7. 7. The DSL● navigating (visit)● matcher (page.should)● clicks (click_link - click_button)● action (fill_in)● finders (find)● scope (within)● Scripting (page.execute_script)● debugger (page.htm - save_and_open_page) ○ NOTE : Youll need to install launchy (gem launchy, : group => :test)and make sure its available to open pages with save_and_open_page
  8. 8. Example
  9. 9. Drivers● Driver agnostic● Support : ○ RackTest ○ Selenium ○ Capybara-webkit● Default: rack_test driver
  10. 10. RackTest● Its pure Ruby, So it interacts directly with Rack interfaces● It does not require a server to be startedBut● Not used to test a remote application, or to access remote URLs (e.g., redirects to external sites, external APIs, or OAuth services)● Dumb● Its not have any support for executing JavaScript
  11. 11. Selenium● Runs tests in a real browser● Supports any Javascript your browser supports, just like real users● Easy to set up with capybaraBut● Slow● GUI browser adds a lot of cruft you don’t want● Unfriendly ○ No console.log output ○ invisible javascript errors
  12. 12. CAPYBARA-WEBKIT● Fast● No browser UI● Using webkit engine● console.log output● Errors in standard output
  13. 13. Setup capybara-webkit:Gemfile gem "capybara-webkit", :group => :test ○ You didnt need capybara itself anymore ○ You will need database_cleaner because database transactions aren’ t compatible with rspec drivers besides Rack::Test gem database_cleaner, :group => :test
  14. 14. Spec_helper.rbENV["RAILS_ENV"] ||= testrequire File.expand_path("../../config/environment", __FILE__)require rspec/railsrequire capybara/rspecrequire capybara-webkitCapybara.javascript_driver = :webkit#...
  15. 15. DatabaseCleaner configurationRSpec.configure do |config| #... config.use_transactional_fixtures = false config.before(:suite) do DatabaseCleaner.strategy = :truncation end config.before(:each) do DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean endend
  16. 16. Reference :● Example@github OmniaGM/learn-capybara● Browser testing● Capybara● Capybara Cheat Sheet
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×