fbpx
Wikipedia

Capybara (software)

Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language.

Capybara
Developer(s)Thomas Walpole
Stable release
3.39.2[1]  / 10 June 2023; 6 months ago (10 June 2023)
Repository
  • github.com/teamcapybara/capybara
Written inRuby
Operating systemCross-platform
TypeBehavior driven development framework / Test tool
LicenseMIT License
Websiteteamcapybara.github.io/capybara/

Capybara can mimic actions of real users interacting with web-based applications. It can receive pages, parse the HTML and submit forms.[2]

Background and motivation edit

During the software development process (especially in the Agile and Test-driven Development environments), as the size of the tests increase, it becomes difficult to manage tests which are complex and not modular.[2]

By extending the human-readable behavior-driven development style of frameworks such as Cucumber and RSpec into the automation code itself, Capybara aims to develop simple web-based automated tests.[3]

Anatomy of Capybara edit

Capybara is a Ruby library (also referred to as a gem) that is used with an underlying web-based driver. It consists of a user-friendly DSL (Domain Specific Language) which describe actions that are executed by the underlying web driver.[4]

When the page is loaded using the DSL (and underlying web driver), Capybara will attempt to locate the relevant element in the DOM (Document Object Model) and execute an action such as click button, link, etc.

Drivers edit

By default, Capybara uses the :rack_test driver which does not have any support for executing JavaScript. Drivers can be switched in Before and After blocks. Some of the web drivers supported by Capybara are mentioned below.

RackTest edit

Written in Ruby, Capybara's default driver RackTest does not require a server to be started since it directly interacts with Rack interfaces. Consequently, it can only be used for Rack applications.

Selenium edit

Selenium-webdriver, which is mostly used in web-based automation frameworks, is supported by Capybara. Unlike Capybara's default driver, it supports JavaScript, can access HTTP resources outside of application and can also be set up for testing in headless mode which is especially useful for CI scenarios.[4]

Capybara-webkit edit

Capybara-webkit driver (a gem) is used for true headless browser testing with JavaScript support. It uses QtWebKit and it is significantly faster than Selenium as it does not load the entire browser.

Matchers edit

Capybara locates an element either using Domain-specific language or XPath/CSS Selectors. Partial matches can lead to unexpected results. Two or more matches can even result in a failure with an Ambiguous match error. The following are the matching strategies supported by Capybara:[4]

first: Pick the first element which matches. Not advisable to use.

one: Allow only one element match. Error raised if more than one match.

smart: If Capybara.exact is true, it behaves like the above option (one). If Capybara.exact is false, it will first try to find an exact match. Ambiguous exception is raised if more than one match is found. If no element is found, a new search for inexact matches is commenced. Again, an ambiguous exception is raised if more than one match is found.

prefer_exact: Finds all matching (exact and which are not exact) elements. If multiple matches are found then the first exactly matching element is returned discarding other matches.

Usage edit

User-registration process edit

Here is an example of how user registration test is done using Capybara. There is a test to see if the user can continue with the registration process or if there are any holds on him. If he has the requisite credentials, he will be registered and then redirected to the 'Welcome' page.[5]

 describe 'UserRegistration' do  it 'allows a user to register' do  visit new_user_registration_path  fill_in 'First name', :with => 'New'  fill_in 'Last name', :with => 'User'  fill_in 'Email', :with => 'newuser@example.com'  fill_in 'Password', :with => 'userpassword'  fill_in 'Password Confirmation', :with => 'userpassword'  click_button 'Register'  page.should have_content 'Welcome'  end  end 

Capybara with Cucumber edit

An example of a Capybara feature used with Cucumber:

When /^I want to add/ do  fill_in 'a', :with => 100  fill_in 'b', :with => 100  click_button 'Add' end 

Capybara with RSpec edit

Some minute integration is required in order to use Capybara with RSpec[4][6]

describe 'go to home page' do  it 'opens the home page' do  visit (get_homepage)  expect(page).to have_content('Welcome')  end end 

Similar tools edit

See also edit

References edit

  1. ^ "Release 3.39.2". 10 June 2023. Retrieved 29 June 2023.
  2. ^ a b Engineering Software as a Service: An Agile Approach Using Cloud Computing. ISBN 9780984881246.
  3. ^ Application Testing with Capybara. ISBN 9781783281268.
  4. ^ a b c d "The Basics of Capybara and Improving Your Tests". SitePoint. Retrieved 2016-02-08.
  5. ^ . garyrafferty.com. Archived from the original on 2016-01-21. Retrieved 2016-02-16.
  6. ^ Liss, Jo. "Capybara (and Selenium) with RSpec & Rails 3: quick tutorial". www.opinionatedprogrammer.com. Retrieved 2016-02-08.

capybara, software, other, uses, capybara, disambiguation, capybara, based, test, automation, software, that, simulates, scenarios, user, stories, automates, application, testing, behavior, driven, software, development, written, ruby, programming, language, c. For other uses see Capybara disambiguation Capybara is a web based test automation software that simulates scenarios for user stories and automates web application testing for behavior driven software development It is written in the Ruby programming language CapybaraDeveloper s Thomas WalpoleStable release3 39 2 1 10 June 2023 6 months ago 10 June 2023 Repositorygithub wbr com wbr teamcapybara wbr capybaraWritten inRubyOperating systemCross platformTypeBehavior driven development framework Test toolLicenseMIT LicenseWebsiteteamcapybara wbr github wbr io wbr capybara wbr Capybara can mimic actions of real users interacting with web based applications It can receive pages parse the HTML and submit forms 2 Contents 1 Background and motivation 2 Anatomy of Capybara 2 1 Drivers 2 1 1 RackTest 2 1 2 Selenium 2 1 3 Capybara webkit 3 Matchers 4 Usage 4 1 User registration process 4 2 Capybara with Cucumber 4 3 Capybara with RSpec 5 Similar tools 6 See also 7 ReferencesBackground and motivation editDuring the software development process especially in the Agile and Test driven Development environments as the size of the tests increase it becomes difficult to manage tests which are complex and not modular 2 By extending the human readable behavior driven development style of frameworks such as Cucumber and RSpec into the automation code itself Capybara aims to develop simple web based automated tests 3 Anatomy of Capybara editCapybara is a Ruby library also referred to as a gem that is used with an underlying web based driver It consists of a user friendly DSL Domain Specific Language which describe actions that are executed by the underlying web driver 4 When the page is loaded using the DSL and underlying web driver Capybara will attempt to locate the relevant element in the DOM Document Object Model and execute an action such as click button link etc Drivers edit By default Capybara uses the rack test driver which does not have any support for executing JavaScript Drivers can be switched in Before and After blocks Some of the web drivers supported by Capybara are mentioned below RackTest edit Written in Ruby Capybara s default driver RackTest does not require a server to be started since it directly interacts with Rack interfaces Consequently it can only be used for Rack applications Selenium edit Selenium webdriver which is mostly used in web based automation frameworks is supported by Capybara Unlike Capybara s default driver it supports JavaScript can access HTTP resources outside of application and can also be set up for testing in headless mode which is especially useful for CI scenarios 4 Capybara webkit edit Capybara webkit driver a gem is used for true headless browser testing with JavaScript support It uses QtWebKit and it is significantly faster than Selenium as it does not load the entire browser Matchers editCapybara locates an element either using Domain specific language or XPath CSS Selectors Partial matches can lead to unexpected results Two or more matches can even result in a failure with an Ambiguous match error The following are the matching strategies supported by Capybara 4 first Pick the first element which matches Not advisable to use one Allow only one element match Error raised if more than one match smart If Capybara exact is true it behaves like the above option one If Capybara exact is false it will first try to find an exact match Ambiguous exception is raised if more than one match is found If no element is found a new search for inexact matches is commenced Again an ambiguous exception is raised if more than one match is found prefer exact Finds all matching exact and which are not exact elements If multiple matches are found then the first exactly matching element is returned discarding other matches Usage editUser registration process editHere is an example of how user registration test is done using Capybara There is a test to see if the user can continue with the registration process or if there are any holds on him If he has the requisite credentials he will be registered and then redirected to the Welcome page 5 describe UserRegistration do it allows a user to register do visit new user registration path fill in First name with gt New fill in Last name with gt User fill in Email with gt newuser example com fill in Password with gt userpassword fill in Password Confirmation with gt userpassword click button Register page should have content Welcome end end Capybara with Cucumber editAn example of a Capybara feature used with Cucumber When I want to add do fill in a with gt 100 fill in b with gt 100 click button Add end Capybara with RSpec edit Some minute integration is required in order to use Capybara with RSpec 4 6 describe go to home page do it opens the home page do visit get homepage expect page to have content Welcome end endSimilar tools editWatir Selenium software See also edit nbsp Free and open source software portalAcceptance testing Acceptance test driven development Behavior driven development Test automation HtmlUnit List of web testing tools Regression testing Given When ThenReferences edit Release 3 39 2 10 June 2023 Retrieved 29 June 2023 a b Engineering Software as a Service An Agile Approach Using Cloud Computing ISBN 9780984881246 Application Testing with Capybara ISBN 9781783281268 a b c d The Basics of Capybara and Improving Your Tests SitePoint Retrieved 2016 02 08 Integration testing Devise with RSpec and Capybara garyrafferty com Archived from the original on 2016 01 21 Retrieved 2016 02 16 Liss Jo Capybara and Selenium with RSpec amp Rails 3 quick tutorial www opinionatedprogrammer com Retrieved 2016 02 08 Retrieved from https en wikipedia org w index php title Capybara software amp oldid 1187152019, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.