词条 | Capybara (software) |
释义 |
| name = Capybara | logo = | screenshot = | caption = | developer =Thomas Walpole | programming language = Ruby | genre = Behavior driven development framework / Test tool | license = MIT License | website = {{URL|https://teamcapybara.github.io/capybara/}} | latest_release_version = 3.11.1 | latest_release_date = {{Start date and age|2018|11|16}}[1] | operating_system = Cross-platform }}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 can mimic actions of real users interacting with web-based applications. It can receive pages, parse the HTML and submit forms.[2] Background and MotivationDuring 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 CapybaraCapybara 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. DriversBy default, Capybara uses the RackTestWritten 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. SeleniumSelenium-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-webkitCapybara-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. MatchersCapybara 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. UsageUser-Registration Process[5]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. 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 CucumberAn 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 RSpecSome 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
See also{{Portal|Software Testing|Free and open-source software}}
References1. ^{{cite web|url=https://github.com/teamcapybara/capybara/releases|title=Releases - teamcapybara/capybara|accessdate=21 November 2018|via=GitHub}} 2. ^1 {{Cite book|title = Engineering Software as a Service: An Agile Approach Using Cloud Computing|last = |first = |publisher = |year = |isbn = 9780984881246|location = |pages = }} 3. ^{{Cite book|title = Application Testing with Capybara|last = |first = |publisher = |year = |isbn = 9781783281268|location = |pages = }} 4. ^1 2 3 {{Cite web|title = The Basics of Capybara and Improving Your Tests|url = http://www.sitepoint.com/basics-capybara-improving-tests/|website = SitePoint|access-date = 2016-02-08|language = en-US}} 5. ^{{Cite web|title = Integration testing Devise with RSpec and Capybara|url = http://garyrafferty.com/2011/09/29/Testing-devise-with-rspec-and-capybara.html|website = garyrafferty.com|access-date = 2016-02-16}} 6. ^{{Cite web|title = Capybara (and Selenium) with RSpec & Rails 3: quick tutorial|url = http://www.opinionatedprogrammer.com/2011/02/capybara-and-selenium-with-rspec-and-rails-3/|website = www.opinionatedprogrammer.com|access-date = 2016-02-08|first = Jo|last = Liss}} 7 : Software testing tools|Software using the MIT license|Graphical user interface testing|Load testing tools|Unit testing frameworks|Web development software|Web scraping |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。