.\r\n- Rewrite the `Capybara.configure` method doc because it's broken in Markdown style.\r\n- Fix `Capybara::Selector` doc in markdown style\r\n","sha":"2f3aa8f8298e8fa1f740b713e73912a3596cedf1","created_at":"2019-05-28 20:17","time_from_now":"5年前","created_at_unix":1559045858}},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","sha":"ab7b1cbd400943d64cca005cae3ef77d283e219b","type":"file","submodule_git_url":null,"size":2125,"is_readme_file":0,"content":null,"target":null,"commit":{"message":"Fix typo in CONTRIBUTING.md\n\nSimple typo fix","sha":"2041e3e5f2d6bedfd6b3b14ec4a45d5b46769a7f","created_at":"2022-11-02 16:45","time_from_now":"2年前","created_at_unix":1667378716}},{"name":"Gemfile","path":"Gemfile","sha":"b842c217f443533c5e0cd42363be62e3e2a12c3b","type":"file","submodule_git_url":null,"size":235,"is_readme_file":null,"content":null,"target":null,"commit":{"message":"When using rack-test 2, we no longer need to send NilUploadedFile to trigger multipart\n","sha":"a3ff5514f40f3af0ec6655354d3596f6d9ea8964","created_at":"2022-06-13 02:05","time_from_now":"2年前","created_at_unix":1655057122}},{"name":"History.md","path":"History.md","sha":"ce0ff426a6a57c28f70dd8be325b918f980c560c","type":"file","submodule_git_url":null,"size":78836,"is_readme_file":0,"content":null,"target":null,"commit":{"message":"Bump Selenium requirement to 4.8+ (#2676)\n\n","sha":"0be79d61b33c9952209e890de11918a35b7589dd","created_at":"2023-06-11 02:13","time_from_now":"1年前","created_at_unix":1686420784}},{"name":"License.txt","path":"License.txt","sha":"fdbc7b5c18c435c36f113cb79c7fb5c0c3a359ab","type":"file","submodule_git_url":null,"size":1097,"is_readme_file":null,"content":null,"target":null,"commit":{"message":"Update license file\n","sha":"4908f8d5535f5d7f078ecc7322caec2136c15c9f","created_at":"2018-10-17 03:00","time_from_now":"6年前","created_at_unix":1539716405}},{"name":"README.md","path":"README.md","sha":"7a2d8c561500976ce3484b311c48cb0cab279b56","type":"file","submodule_git_url":null,"size":39246,"is_readme_file":true,"content":null,"target":null,"commit":{"message":"Don't have time to keep up to date - people should just use selenium","sha":"0b43cb90ae633ce9b2008e07b997c76833fa570e","created_at":"2023-09-07 10:11","time_from_now":"1年前","created_at_unix":1694052672}},{"name":"Rakefile","path":"Rakefile","sha":"9ae6223e4ddd6468e2e0301abc3c3a6f3ea79f98","type":"file","submodule_git_url":null,"size":2803,"is_readme_file":null,"content":null,"target":null,"commit":{"message":"Code cleanup\n","sha":"5d28453d8fe3d30f5a69ed984a28e9357e55f070","created_at":"2022-12-27 03:13","time_from_now":"2年前","created_at_unix":1672081989}},{"name":"UPGRADING.md","path":"UPGRADING.md","sha":"44851cc7e4f1413ca450e6b2b54f3af77aa174fb","type":"file","submodule_git_url":null,"size":1891,"is_readme_file":0,"content":null,"target":null,"commit":{"message":"Update UPGRADING.md [ci skip]\n","sha":"649d7ba4ca8593131d2fc490640b703f0596e214","created_at":"2018-04-10 02:29","time_from_now":"6年前","created_at_unix":1523298541}},{"name":"appveyor.yml.outdated","path":"appveyor.yml.outdated","sha":"d9b6b910a8f48fdf854ff78ef3150dd387bd16cf","type":"file","submodule_git_url":null,"size":1531,"is_readme_file":null,"content":null,"target":null,"commit":{"message":"Update CI build matrix\n","sha":"66f43064fc7347aedbe3c452e24716caf1f9d4c9","created_at":"2023-04-03 09:46","time_from_now":"1年前","created_at_unix":1680486415}},{"name":"capybara.gemspec","path":"capybara.gemspec","sha":"ea99201f1407ce302138e539b684ef2da3ae1ab4","type":"file","submodule_git_url":null,"size":3089,"is_readme_file":null,"content":null,"target":null,"commit":{"message":"Bump Selenium requirement to 4.8+ (#2676)\n\n","sha":"0be79d61b33c9952209e890de11918a35b7589dd","created_at":"2023-06-11 02:13","time_from_now":"1年前","created_at_unix":1686420784}},{"name":"docker-compose.yml","path":"docker-compose.yml","sha":"c1bdd3c44aac97b64c13bf4408d72480a9e2005b","type":"file","submodule_git_url":null,"size":369,"is_readme_file":null,"content":null,"target":null,"commit":{"message":"Move waiting for Selenium docker instances into ruby code\n","sha":"3ecc48b93d1739fb236fb752799bc7fe74baa422","created_at":"2018-06-29 01:18","time_from_now":"6年前","created_at_unix":1530206330}},{"name":"gem-public_cert.pem","path":"gem-public_cert.pem","sha":"0722498e6324a5f25e1246840ba3c82fa3814b75","type":"file","submodule_git_url":null,"size":1184,"is_readme_file":null,"content":null,"target":null,"commit":{"message":"Add public key","sha":"315d6c6e6ee2274311e62c1ed490a9595a545b0d","created_at":"2013-02-16 06:10","time_from_now":"12年前","created_at_unix":1360966237}}]},"projectMenu":[{"menu_name":"home"},{"menu_name":"code"},{"menu_name":"issues"},{"menu_name":"pulls"},{"menu_name":"devops"},{"menu_name":"versions"},{"menu_name":"wiki"},{"menu_name":"resources"},{"menu_name":"activity"}],"projectReadMe":"%7B%22type%22%3A%22file%22%2C%22encoding%22%3A%22base64%22%2C%22size%22%3A39246%2C%22name%22%3A%22README.md%22%2C%22path%22%3A%22README.md%22%2C%22content%22%3A%22%23%20Capybara%5Cn%5Cn%5B!%5BBuild%20Status%5D(https%3A%2F%2Fgithub.com%2Fteamcapybara%2Fcapybara%2Factions%2Fworkflows%2Fbuild.yml%2Fbadge.svg)%5D(https%3A%2F%2Fgithub.com%2Fteamcapybara%2Fcapybara%2Factions%2Fworkflows%2Fbuild.yml)%5Cn%5B!%5BCode%20Climate%5D(https%3A%2F%2Fcodeclimate.com%2Fgithub%2Fteamcapybara%2Fcapybara.svg)%5D(https%3A%2F%2Fcodeclimate.com%2Fgithub%2Fteamcapybara%2Fcapybara)%5Cn%5B!%5BCoverage%20Status%5D(https%3A%2F%2Fcoveralls.io%2Frepos%2Fgithub%2Fteamcapybara%2Fcapybara%2Fbadge.svg%3Fbranch%3Dmaster)%5D(https%3A%2F%2Fcoveralls.io%2Fgithub%2Fteamcapybara%2Fcapybara%3Fbranch%3Dmaster)%5Cn%5CnCapybara%20helps%20you%20test%20web%20applications%20by%20simulating%20how%20a%20real%20user%20would%5Cninteract%20with%20your%20app.%20It%20is%20agnostic%20about%20the%20driver%20running%20your%20tests%20and%5Cncomes%20with%20Rack%3A%3ATest%20and%20Selenium%20support%20built%20in.%20WebKit%20is%20supported%5Cnthrough%20an%20external%20gem.%5Cn%5Cn%23%23%20Support%20Capybara%5Cn%5CnIf%20you%20and%2For%20your%20company%20find%20value%20in%20Capybara%20and%20would%20like%20to%20contribute%20financially%20to%20its%20ongoing%20maintenance%20and%20development%2C%20please%20visit%5Cn%3Ca%20href%3D%5C%22https%3A%2F%2Fwww.patreon.com%2Fcapybara%5C%22%3EPatreon%3C%2Fa%3E%5Cn%5Cn%5Cn**Need%20help%3F**%20Ask%20on%20the%20discussions%20(please%20do%20not%20open%20an%20issue)%3A%20https%3A%2F%2Fgithub.com%2Forgs%2Fteamcapybara%2Fdiscussions%2Fcategories%2Fq-a%5Cn%5Cn%23%23%20Table%20of%20contents%5Cn%5Cn-%20%5BKey%20benefits%5D(%23key-benefits)%5Cn-%20%5BSetup%5D(%23setup)%5Cn-%20%5BUsing%20Capybara%20with%20Cucumber%5D(%23using-capybara-with-cucumber)%5Cn-%20%5BUsing%20Capybara%20with%20RSpec%5D(%23using-capybara-with-rspec)%5Cn-%20%5BUsing%20Capybara%20with%20Test%3A%3AUnit%5D(%23using-capybara-with-testunit)%5Cn-%20%5BUsing%20Capybara%20with%20Minitest%5D(%23using-capybara-with-minitest)%5Cn-%20%5BUsing%20Capybara%20with%20Minitest%3A%3ASpec%5D(%23using-capybara-with-minitestspec)%5Cn-%20%5BDrivers%5D(%23drivers)%5Cn%20%20%20%20-%20%5BSelecting%20the%20Driver%5D(%23selecting-the-driver)%5Cn%20%20%20%20-%20%5BRackTest%5D(%23racktest)%5Cn%20%20%20%20-%20%5BSelenium%5D(%23selenium)%5Cn-%20%5BThe%20DSL%5D(%23the-dsl)%5Cn%20%20%20%20-%20%5BNavigating%5D(%23navigating)%5Cn%20%20%20%20-%20%5BClicking%20links%20and%20buttons%5D(%23clicking-links-and-buttons)%5Cn%20%20%20%20-%20%5BInteracting%20with%20forms%5D(%23interacting-with-forms)%5Cn%20%20%20%20-%20%5BQuerying%5D(%23querying)%5Cn%20%20%20%20-%20%5BFinding%5D(%23finding)%5Cn%20%20%20%20-%20%5BScoping%5D(%23scoping)%5Cn%20%20%20%20-%20%5BWorking%20with%20windows%5D(%23working-with-windows)%5Cn%20%20%20%20-%20%5BScripting%5D(%23scripting)%5Cn%20%20%20%20-%20%5BModals%5D(%23modals)%5Cn%20%20%20%20-%20%5BDebugging%5D(%23debugging)%5Cn-%20%5BMatching%5D(%23matching)%5Cn%20%20%20%20-%20%5BExactness%5D(%23exactness)%5Cn%20%20%20%20-%20%5BStrategy%5D(%23strategy)%5Cn-%20%5BTransactions%20and%20database%20setup%5D(%23transactions-and-database-setup)%5Cn-%20%5BAsynchronous%20JavaScript%20(Ajax%20and%20friends)%5D(%23asynchronous-javascript-ajax-and-friends)%5Cn-%20%5BUsing%20the%20DSL%20elsewhere%5D(%23using-the-dsl-elsewhere)%5Cn-%20%5BCalling%20remote%20servers%5D(%23calling-remote-servers)%5Cn-%20%5BUsing%20sessions%5D(%23using-sessions)%5Cn%20%20%20%20-%20%5BNamed%20sessions%5D(%23named-sessions)%5Cn%20%20%20%20-%20%5BUsing%20sessions%20manually%5D(%23using-sessions-manually)%5Cn-%20%5BXPath%2C%20CSS%20and%20selectors%5D(%23xpath-css-and-selectors)%5Cn-%20%5BBeware%20the%20XPath%20%2F%2F%20trap%5D(%23beware-the-xpath--trap)%5Cn-%20%5BConfiguring%20and%20adding%20drivers%5D(%23configuring-and-adding-drivers)%5Cn-%20%5BGotchas%3A%5D(%23gotchas)%5Cn-%20%5B%5C%22Threadsafe%5C%22%20mode%5D(%23threadsafe-mode)%5Cn-%20%5BDevelopment%5D(%23development)%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22key-benefits%5C%22%3E%3C%2Fa%3EKey%20benefits%5Cn%5Cn-%20**No%20setup**%20necessary%20for%20Rails%20and%20Rack%20application.%20Works%20out%20of%20the%20box.%5Cn-%20**Intuitive%20API**%20which%20mimics%20the%20language%20an%20actual%20user%20would%20use.%5Cn-%20**Switch%20the%20backend**%20your%20tests%20run%20against%20from%20fast%20headless%20mode%5Cn%20%20to%20an%20actual%20browser%20with%20no%20changes%20to%20your%20tests.%5Cn-%20**Powerful%20synchronization**%20features%20mean%20you%20never%20have%20to%20manually%20wait%5Cn%20%20for%20asynchronous%20processes%20to%20complete.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22setup%5C%22%3E%3C%2Fa%3ESetup%5Cn%5CnCapybara%20requires%20Ruby%203.0.0%20or%20later.%20To%20install%2C%20add%20this%20line%20to%20your%5Cn%60Gemfile%60%20and%20run%20%60bundle%20install%60%3A%5Cn%5Cn%60%60%60ruby%5Cngem%20'capybara'%5Cn%60%60%60%5Cn%5CnIf%20the%20application%20that%20you%20are%20testing%20is%20a%20Rails%20app%2C%20add%20this%20line%20to%20your%20test%20helper%20file%3A%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Frails'%5Cn%60%60%60%5Cn%5CnIf%20the%20application%20that%20you%20are%20testing%20is%20a%20Rack%20app%2C%20but%20not%20Rails%2C%20set%20Capybara.app%20to%20your%20Rack%20app%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.app%20%3D%20MyRackApp%5Cn%60%60%60%5Cn%5CnIf%20you%20need%20to%20test%20JavaScript%2C%20or%20if%20your%20app%20interacts%20with%20(or%20is%20located%20at)%5Cna%20remote%20URL%2C%20you'll%20need%20to%20%5Buse%20a%20different%20driver%5D(%23drivers).%20%20If%20using%20Rails%205.0%2B%2C%20but%20not%20using%20the%20Rails%20system%20tests%20from%205.1%2C%20you'll%20probably%20also%5Cnwant%20to%20swap%20the%20%5C%22server%5C%22%20used%20to%20launch%20your%20app%20to%20Puma%20in%20order%20to%20match%20Rails%20defaults.%5Cn%5Cn%60%60%60ruby%5CnCapybara.server%20%3D%20%3Apuma%20%23%20Until%20your%20setup%20is%20working%5CnCapybara.server%20%3D%20%3Apuma%2C%20%7B%20Silent%3A%20true%20%7D%20%23%20To%20clean%20up%20your%20test%20output%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-cucumber%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Cucumber%5Cn%5CnThe%20%60cucumber-rails%60%20gem%20comes%20with%20Capybara%20support%20built-in.%20If%20you%5Cnare%20not%20using%20Rails%2C%20manually%20load%20the%20%60capybara%2Fcucumber%60%20module%3A%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Fcucumber'%5CnCapybara.app%20%3D%20MyRackApp%5Cn%60%60%60%5Cn%5CnYou%20can%20use%20the%20Capybara%20DSL%20in%20your%20steps%2C%20like%20so%3A%5Cn%5Cn%60%60%60ruby%5CnWhen%20%2FI%20sign%20in%2F%20do%5Cn%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'password'%5Cn%20%20end%5Cn%20%20click_button%20'Sign%20in'%5Cnend%5Cn%60%60%60%5Cn%5CnYou%20can%20switch%20to%20the%20%60Capybara.javascript_driver%60%20(%60%3Aselenium%60%5Cnby%20default)%20by%20tagging%20scenarios%20(or%20features)%20with%20%60%40javascript%60%3A%5Cn%5Cn%60%60%60ruby%5Cn%40javascript%5CnScenario%3A%20do%20something%20Ajaxy%5Cn%20%20When%20I%20click%20the%20Ajax%20link%5Cn%20%20...%5Cn%60%60%60%5Cn%5CnThere%20are%20also%20explicit%20tags%20for%20each%20registered%20driver%20set%20up%20for%20you%20(%60%40selenium%60%2C%20%60%40rack_test%60%2C%20etc).%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-rspec%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20RSpec%5Cn%5CnLoad%20RSpec%203.5%2B%20support%20by%20adding%20the%20following%20line%20(typically%20to%20your%5Cn%60spec_helper.rb%60%20file)%3A%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Frspec'%5Cn%60%60%60%5Cn%5CnIf%20you%20are%20using%20Rails%2C%20put%20your%20Capybara%20specs%20in%20%60spec%2Ffeatures%60%20or%20%60spec%2Fsystem%60%20(only%20works%5Cnif%20%5Byou%20have%20it%20configured%20in%5CnRSpec%5D(https%3A%2F%2Frelishapp.com%2Frspec%2Frspec-rails%2Fv%2F4-0%2Fdocs%2Fdirectory-structure))%5Cnand%20if%20you%20have%20your%20Capybara%20specs%20in%20a%20different%20directory%2C%20then%20tag%20the%5Cnexample%20groups%20with%20%60type%3A%20%3Afeature%60%20or%20%60type%3A%20%3Asystem%60%20depending%20on%20which%20type%20of%20test%20you're%20writing.%5Cn%5CnIf%20you%20are%20using%20Rails%20system%20specs%20please%20see%20%5Btheir%20documentation%5D(https%3A%2F%2Frelishapp.com%2Frspec%2Frspec-rails%2Fdocs%2Fsystem-specs%2Fsystem-spec%23system-specs-driven-by-selenium-chrome-headless)%20for%20selecting%20the%20driver%20you%20wish%20to%20use.%5Cn%5CnIf%20you%20are%20not%20using%20Rails%2C%20tag%20all%20the%20example%20groups%20in%20which%20you%20want%20to%20use%5CnCapybara%20with%20%60type%3A%20%3Afeature%60.%5Cn%5CnYou%20can%20now%20write%20your%20specs%20like%20so%3A%5Cn%5Cn%60%60%60ruby%5Cndescribe%20%5C%22the%20signin%20process%5C%22%2C%20type%3A%20%3Afeature%20do%5Cn%20%20before%20%3Aeach%20do%5Cn%20%20%20%20User.create(email%3A%20'user%40example.com'%2C%20password%3A%20'password')%5Cn%20%20end%5Cn%5Cn%20%20it%20%5C%22signs%20me%20in%5C%22%20do%5Cn%20%20%20%20visit%20'%2Fsessions%2Fnew'%5Cn%20%20%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'password'%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20%20%20expect(page).to%20have_content%20'Success'%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5CnUse%20%60js%3A%20true%60%20to%20switch%20to%20the%20%60Capybara.javascript_driver%60%5Cn(%60%3Aselenium%60%20by%20default)%2C%20or%20provide%20a%20%60%3Adriver%60%20option%20to%20switch%5Cnto%20one%20specific%20driver.%20For%20example%3A%5Cn%5Cn%60%60%60ruby%5Cndescribe%20'some%20stuff%20which%20requires%20js'%2C%20js%3A%20true%20do%5Cn%20%20it%20'will%20use%20the%20default%20js%20driver'%5Cn%20%20it%20'will%20switch%20to%20one%20specific%20driver'%2C%20driver%3A%20%3Aselenium%5Cnend%5Cn%60%60%60%5Cn%5CnCapybara%20also%20comes%20with%20a%20built%20in%20DSL%20for%20creating%20descriptive%20acceptance%20tests%3A%5Cn%5Cn%60%60%60ruby%5Cnfeature%20%5C%22Signing%20in%5C%22%20do%5Cn%20%20background%20do%5Cn%20%20%20%20User.create(email%3A%20'user%40example.com'%2C%20password%3A%20'caplin')%5Cn%20%20end%5Cn%5Cn%20%20scenario%20%5C%22Signing%20in%20with%20correct%20credentials%5C%22%20do%5Cn%20%20%20%20visit%20'%2Fsessions%2Fnew'%5Cn%20%20%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'caplin'%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20%20%20expect(page).to%20have_content%20'Success'%5Cn%20%20end%5Cn%5Cn%20%20given(%3Aother_user)%20%7B%20User.create(email%3A%20'other%40example.com'%2C%20password%3A%20'rous')%20%7D%5Cn%5Cn%20%20scenario%20%5C%22Signing%20in%20as%20another%20user%5C%22%20do%5Cn%20%20%20%20visit%20'%2Fsessions%2Fnew'%5Cn%20%20%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20other_user.email%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20other_user.password%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20%20%20expect(page).to%20have_content%20'Invalid%20email%20or%20password'%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn%60feature%60%20is%20in%20fact%20just%20an%20alias%20for%20%60describe%20...%2C%20type%3A%20%3Afeature%60%2C%5Cn%60background%60%20is%20an%20alias%20for%20%60before%60%2C%20%60scenario%60%20for%20%60it%60%2C%20and%5Cn%60given%60%2F%60given!%60%20aliases%20for%20%60let%60%2F%60let!%60%2C%20respectively.%5Cn%5CnFinally%2C%20Capybara%20matchers%20are%20also%20supported%20in%20view%20specs%3A%5Cn%5Cn%60%60%60ruby%5CnRSpec.describe%20%5C%22todos%2Fshow.html.erb%5C%22%2C%20type%3A%20%3Aview%20do%5Cn%20%20it%20%5C%22displays%20the%20todo%20title%5C%22%20do%5Cn%20%20%20%20assign%20%3Atodo%2C%20Todo.new(title%3A%20%5C%22Buy%20milk%5C%22)%5Cn%5Cn%20%20%20%20render%5Cn%5Cn%20%20%20%20expect(rendered).to%20have_css(%5C%22header%20h1%5C%22%2C%20text%3A%20%5C%22Buy%20milk%5C%22)%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn**Note%3A%20When%20you%20require%20'capybara%2Frspec'%20proxy%20methods%20are%20installed%20to%20work%20around%20name%20collisions%20between%20Capybara%3A%3ADSL%20methods%5Cn%20%20%60all%60%2F%60within%60%20and%20the%20identically%20named%20built-in%20RSpec%20matchers.%20If%20you%20opt%20not%20to%20require%20'capybara%2Frspec'%20you%20can%20install%20the%20proxy%20methods%20by%20requiring%20'capybara%2Frspec%2Fmatcher_proxies'%20after%20requiring%20RSpec%20and%20'capybara%2Fdsl'**%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-testunit%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Test%3A%3AUnit%5Cn%5Cn*%20If%20you%20are%20using%20%60Test%3A%3AUnit%60%2C%20define%20a%20base%20class%20for%20your%20Capybara%20tests%5Cn%20%20like%20so%3A%5Cn%5Cn%20%20%20%20%60%60%60ruby%5Cn%20%20%20%20require%20'capybara%2Fdsl'%5Cn%5Cn%20%20%20%20class%20CapybaraTestCase%20%3C%20Test%3A%3AUnit%3A%3ATestCase%5Cn%20%20%20%20%20%20include%20Capybara%3A%3ADSL%5Cn%5Cn%20%20%20%20%20%20def%20teardown%5Cn%20%20%20%20%20%20%20%20Capybara.reset_sessions!%5Cn%20%20%20%20%20%20%20%20Capybara.use_default_driver%5Cn%20%20%20%20%20%20end%5Cn%20%20%20%20end%5Cn%20%20%20%20%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-minitest%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Minitest%5Cn%5Cn*%20If%20you%20are%20using%20Rails%20system%20tests%20please%20see%20their%20documentation%20for%20information%20on%20selecting%20the%20driver%20you%20wish%20to%20use.%5Cn%5Cn*%20If%20you%20are%20using%20Rails%2C%20but%20not%20using%20Rails%20system%20tests%2C%20add%20the%20following%20code%20in%20your%20%60test_helper.rb%60%5Cn%20%20%20%20file%20to%20make%20Capybara%20available%20in%20all%20test%20cases%20deriving%20from%5Cn%20%20%20%20%60ActionDispatch%3A%3AIntegrationTest%60%3A%5Cn%5Cn%20%20%20%20%60%60%60ruby%5Cn%20%20%20%20require%20'capybara%2Frails'%5Cn%20%20%20%20require%20'capybara%2Fminitest'%5Cn%5Cn%20%20%20%20class%20ActionDispatch%3A%3AIntegrationTest%5Cn%20%20%20%20%20%20%23%20Make%20the%20Capybara%20DSL%20available%20in%20all%20integration%20tests%5Cn%20%20%20%20%20%20include%20Capybara%3A%3ADSL%5Cn%20%20%20%20%20%20%23%20Make%20%60assert_*%60%20methods%20behave%20like%20Minitest%20assertions%5Cn%20%20%20%20%20%20include%20Capybara%3A%3AMinitest%3A%3AAssertions%5Cn%5Cn%20%20%20%20%20%20%23%20Reset%20sessions%20and%20driver%20between%20tests%5Cn%20%20%20%20%20%20teardown%20do%5Cn%20%20%20%20%20%20%20%20Capybara.reset_sessions!%5Cn%20%20%20%20%20%20%20%20Capybara.use_default_driver%5Cn%20%20%20%20%20%20end%5Cn%20%20%20%20end%5Cn%20%20%20%20%60%60%60%5Cn%5Cn*%20If%20you%20are%20not%20using%20Rails%2C%20define%20a%20base%20class%20for%20your%20Capybara%20tests%20like%5Cn%20%20so%3A%5Cn%5Cn%20%20%20%20%60%60%60ruby%5Cn%20%20%20%20require%20'capybara%2Fminitest'%5Cn%5Cn%20%20%20%20class%20CapybaraTestCase%20%3C%20Minitest%3A%3ATest%5Cn%20%20%20%20%20%20include%20Capybara%3A%3ADSL%5Cn%20%20%20%20%20%20include%20Capybara%3A%3AMinitest%3A%3AAssertions%5Cn%5Cn%20%20%20%20%20%20def%20teardown%5Cn%20%20%20%20%20%20%20%20Capybara.reset_sessions!%5Cn%20%20%20%20%20%20%20%20Capybara.use_default_driver%5Cn%20%20%20%20%20%20end%5Cn%20%20%20%20end%5Cn%20%20%20%20%60%60%60%5Cn%5Cn%20%20%20%20Remember%20to%20call%20%60super%60%20in%20any%20subclasses%20that%20override%5Cn%20%20%20%20%60teardown%60.%5Cn%5CnTo%20switch%20the%20driver%2C%20set%20%60Capybara.current_driver%60.%20For%20instance%2C%5Cn%5Cn%60%60%60ruby%5Cnclass%20BlogTest%20%3C%20ActionDispatch%3A%3AIntegrationTest%5Cn%20%20setup%20do%5Cn%20%20%20%20Capybara.current_driver%20%3D%20Capybara.javascript_driver%20%23%20%3Aselenium%20by%20default%5Cn%20%20end%5Cn%5Cn%20%20test%20'shows%20blog%20posts'%20do%5Cn%20%20%20%20%23%20...%20this%20test%20is%20run%20with%20Selenium%20...%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-minitestspec%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Minitest%3A%3ASpec%5Cn%5CnFollow%20the%20above%20instructions%20for%20Minitest%20and%20additionally%20require%20capybara%2Fminitest%2Fspec%5Cn%5Cn%60%60%60ruby%5Cnpage.must_have_content('Important!')%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22drivers%5C%22%3E%3C%2Fa%3EDrivers%5Cn%5CnCapybara%20uses%20the%20same%20DSL%20to%20drive%20a%20variety%20of%20browser%20and%20headless%20drivers.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22selecting-the-driver%5C%22%3E%3C%2Fa%3ESelecting%20the%20Driver%5Cn%5CnBy%20default%2C%20Capybara%20uses%20the%20%60%3Arack_test%60%20driver%2C%20which%20is%20fast%20but%20limited%3A%20it%5Cndoes%20not%20support%20JavaScript%2C%20nor%20is%20it%20able%20to%20access%20HTTP%20resources%20outside%20of%5Cnyour%20Rack%20application%2C%20such%20as%20remote%20APIs%20and%20OAuth%20services.%20To%20get%20around%5Cnthese%20limitations%2C%20you%20can%20set%20up%20a%20different%20default%20driver%20for%20your%20features.%5CnFor%20example%2C%20if%20you'd%20prefer%20to%20run%20everything%20in%20Selenium%2C%20you%20could%20do%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.default_driver%20%3D%20%3Aselenium%20%23%20%3Aselenium_chrome%20and%20%3Aselenium_chrome_headless%20are%20also%20registered%5Cn%60%60%60%5Cn%5CnHowever%2C%20if%20you%20are%20using%20RSpec%20or%20Cucumber%20(and%20your%20app%20runs%20correctly%20without%20JS)%2C%5Cnyou%20may%20instead%20want%20to%20consider%20leaving%20the%20faster%20%60%3Arack_test%60%20as%20the%20__default_driver__%2C%20and%5Cnmarking%20only%20those%20tests%20that%20require%20a%20JavaScript-capable%20driver%20using%20%60js%3A%20true%60%20or%5Cn%60%40javascript%60%2C%20respectively.%20%20By%20default%2C%20JavaScript%20tests%20are%20run%20using%20the%5Cn%60%3Aselenium%60%20driver.%20You%20can%20change%20this%20by%20setting%5Cn%60Capybara.javascript_driver%60.%5Cn%5CnYou%20can%20also%20change%20the%20driver%20temporarily%20(typically%20in%20the%20Before%2Fsetup%20and%5CnAfter%2Fteardown%20blocks)%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.current_driver%20%3D%20%3Aselenium%20%23%20temporarily%20select%20different%20driver%5Cn%23%20tests%20here%5CnCapybara.use_default_driver%20%20%20%20%20%20%20%23%20switch%20back%20to%20default%20driver%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20switching%20the%20driver%20creates%20a%20new%20session%2C%20so%20you%20may%20not%20be%20able%20to%5Cnswitch%20in%20the%20middle%20of%20a%20test.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22racktest%5C%22%3E%3C%2Fa%3ERackTest%5Cn%5CnRackTest%20is%20Capybara's%20default%20driver.%20It%20is%20written%20in%20pure%20Ruby%20and%20does%20not%5Cnhave%20any%20support%20for%20executing%20JavaScript.%20Since%20the%20RackTest%20driver%20interacts%5Cndirectly%20with%20Rack%20interfaces%2C%20it%20does%20not%20require%20a%20server%20to%20be%20started.%5CnHowever%2C%20this%20means%20that%20if%20your%20application%20is%20not%20a%20Rack%20application%20(Rails%2C%5CnSinatra%20and%20most%20other%20Ruby%20frameworks%20are%20Rack%20applications)%20then%20you%20cannot%5Cnuse%20this%20driver.%20Furthermore%2C%20you%20cannot%20use%20the%20RackTest%20driver%20to%20test%20a%5Cnremote%20application%2C%20or%20to%20access%20remote%20URLs%20(e.g.%2C%20redirects%20to%20external%5Cnsites%2C%20external%20APIs%2C%20or%20OAuth%20services)%20that%20your%20application%20might%20interact%5Cnwith.%5Cn%5Cn%5Bcapybara-mechanize%5D(https%3A%2F%2Fgithub.com%2Fjeroenvandijk%2Fcapybara-mechanize)%5Cnprovides%20a%20similar%20driver%20that%20can%20access%20remote%20servers.%5Cn%5CnRackTest%20can%20be%20configured%20with%20a%20set%20of%20headers%20like%20this%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.register_driver%20%3Arack_test%20do%20%7Capp%7C%5Cn%20%20Capybara%3A%3ARackTest%3A%3ADriver.new(app%2C%20headers%3A%20%7B%20'HTTP_USER_AGENT'%20%3D%3E%20'Capybara'%20%7D)%5Cnend%5Cn%60%60%60%5Cn%5CnSee%20the%20section%20on%20adding%20and%20configuring%20drivers.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22selenium%5C%22%3E%3C%2Fa%3ESelenium%5Cn%5CnCapybara%20supports%20%5BSelenium%203.5%2B%5Cn(Webdriver)%5D(https%3A%2F%2Fwww.seleniumhq.org%2Fprojects%2Fwebdriver%2F).%5CnIn%20order%20to%20use%20Selenium%2C%20you'll%20need%20to%20install%20the%20%60selenium-webdriver%60%20gem%2C%5Cnand%20add%20it%20to%20your%20Gemfile%20if%20you're%20using%20bundler.%5Cn%5CnCapybara%20pre-registers%20a%20number%20of%20named%20drivers%20that%20use%20Selenium%20-%20they%20are%3A%5Cn%5Cn%20%20*%20%3Aselenium%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%3E%20Selenium%20driving%20Firefox%5Cn%20%20*%20%3Aselenium_headless%20%20%20%20%20%20%20%20%3D%3E%20Selenium%20driving%20Firefox%20in%20a%20headless%20configuration%5Cn%20%20*%20%3Aselenium_chrome%20%20%20%20%20%20%20%20%20%20%3D%3E%20Selenium%20driving%20Chrome%5Cn%20%20*%20%3Aselenium_chrome_headless%20%3D%3E%20Selenium%20driving%20Chrome%20in%20a%20headless%20configuration%5Cn%5CnThese%20should%20work%20(with%20relevant%20software%20installation)%20in%20a%20local%20desktop%20configuration%20but%20you%20may%5Cnneed%20to%20customize%20them%20if%20using%20in%20a%20CI%20environment%20where%20additional%20options%20may%20need%20to%20be%20passed%5Cnto%20the%20browsers.%20%20See%20the%20section%20on%20adding%20and%20configuring%20drivers.%5Cn%5Cn%5Cn**Note**%3A%20drivers%20which%20run%20the%20server%20in%20a%20different%20thread%20may%20not%20share%20the%5Cnsame%20transaction%20as%20your%20tests%2C%20causing%20data%20not%20to%20be%20shared%20between%20your%20test%5Cnand%20test%20server%2C%20see%20%5BTransactions%20and%20database%20setup%5D(%23transactions-and-database-setup)%20below.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22the-dsl%5C%22%3E%3C%2Fa%3EThe%20DSL%5Cn%5Cn*A%20complete%20reference%20is%20available%20at%5Cn%5Brubydoc.info%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster)*.%5Cn%5Cn**Note%3A%20By%20default%20Capybara%20will%20only%20locate%20visible%20elements.%20This%20is%20because%5Cn%20a%20real%20user%20would%20not%20be%20able%20to%20interact%20with%20non-visible%20elements.**%5Cn%5Cn**Note**%3A%20All%20searches%20in%20Capybara%20are%20*case%20sensitive*.%20This%20is%20because%5CnCapybara%20heavily%20uses%20XPath%2C%20which%20doesn't%20support%20case%20insensitivity.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22navigating%5C%22%3E%3C%2Fa%3ENavigating%5Cn%5CnYou%20can%20use%20the%5Cn%3Ctt%3E%5Bvisit%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23visit-instance_method)%3C%2Ftt%3E%5Cnmethod%20to%20navigate%20to%20other%20pages%3A%5Cn%5Cn%60%60%60ruby%5Cnvisit('%2Fprojects')%5Cnvisit(post_comments_path(post))%5Cn%60%60%60%5Cn%5CnThe%20visit%20method%20only%20takes%20a%20single%20parameter%2C%20the%20request%20method%20is%20**always**%5CnGET.%5Cn%5CnYou%20can%20get%20the%20%5Bcurrent%20path%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23current_path-instance_method)%5Cnof%20the%20browsing%20session%2C%20and%20test%20it%20using%20the%20%5B%60have_current_path%60%5D(http%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FRSpecMatchers%23have_current_path-instance_method)%20matcher%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(page).to%20have_current_path(post_comments_path(post))%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20You%20can%20also%20assert%20the%20current%20path%20by%20testing%20the%20value%20of%5Cn%60current_path%60%20directly.%20However%2C%20using%20the%20%60have_current_path%60%20matcher%20is%5Cnsafer%20since%20it%20uses%20Capybara's%20%5Bwaiting%20behaviour%5D(%23asynchronous-javascript-ajax-and-friends)%5Cnto%20ensure%20that%20preceding%20actions%20(such%20as%20a%20%60click_link%60)%20have%20completed.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22clicking-links-and-buttons%5C%22%3E%3C%2Fa%3EClicking%20links%20and%20buttons%5Cn%5Cn*Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AActions%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FActions)*%5Cn%5CnYou%20can%20interact%20with%20the%20webapp%20by%20following%20links%20and%20buttons.%20Capybara%5Cnautomatically%20follows%20any%20redirects%2C%20and%20submits%20forms%20associated%20with%20buttons.%5Cn%5Cn%60%60%60ruby%5Cnclick_link('id-of-link')%5Cnclick_link('Link%20Text')%5Cnclick_button('Save')%5Cnclick_on('Link%20Text')%20%23%20clicks%20on%20either%20links%20or%20buttons%5Cnclick_on('Button%20Value')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22interacting-with-forms%5C%22%3E%3C%2Fa%3EInteracting%20with%20forms%5Cn%5Cn*Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AActions%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FActions)*%5Cn%5CnThere%20are%20a%20number%20of%20tools%20for%20interacting%20with%20form%20elements%3A%5Cn%5Cn%60%60%60ruby%5Cnfill_in('First%20Name'%2C%20with%3A%20'John')%5Cnfill_in('Password'%2C%20with%3A%20'Seekrit')%5Cnfill_in('Description'%2C%20with%3A%20'Really%20Long%20Text...')%5Cnchoose('A%20Radio%20Button')%5Cncheck('A%20Checkbox')%5Cnuncheck('A%20Checkbox')%5Cnattach_file('Image'%2C%20'%2Fpath%2Fto%2Fimage.jpg')%5Cnselect('Option'%2C%20from%3A%20'Select%20Box')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22querying%5C%22%3E%3C%2Fa%3EQuerying%5Cn%5Cn*Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AMatchers%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FMatchers)*%5Cn%5CnCapybara%20has%20a%20rich%20set%20of%20options%20for%20querying%20the%20page%20for%20the%20existence%20of%5Cncertain%20elements%2C%20and%20working%20with%20and%20manipulating%20those%20elements.%5Cn%5Cn%60%60%60ruby%5Cnpage.has_selector%3F('table%20tr')%5Cnpage.has_selector%3F(%3Axpath%2C%20'.%2F%2Ftable%2Ftr')%5Cn%5Cnpage.has_xpath%3F('.%2F%2Ftable%2Ftr')%5Cnpage.has_css%3F('table%20tr.foo')%5Cnpage.has_content%3F('foo')%5Cn%60%60%60%5Cn%5Cn**Note%3A**%20The%20negative%20forms%20like%20%60has_no_selector%3F%60%20are%20different%20from%20%60not%5Cnhas_selector%3F%60.%20Read%20the%20section%20on%20asynchronous%20JavaScript%20for%20an%20explanation.%5Cn%5CnYou%20can%20use%20these%20with%20RSpec's%20magic%20matchers%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(page).to%20have_selector('table%20tr')%5Cnexpect(page).to%20have_selector(%3Axpath%2C%20'.%2F%2Ftable%2Ftr')%5Cn%5Cnexpect(page).to%20have_xpath('.%2F%2Ftable%2Ftr')%5Cnexpect(page).to%20have_css('table%20tr.foo')%5Cnexpect(page).to%20have_content('foo')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22finding%5C%22%3E%3C%2Fa%3EFinding%5Cn%5Cn_Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AFinders%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FFinders)_%5Cn%5CnYou%20can%20also%20find%20specific%20elements%2C%20in%20order%20to%20manipulate%20them%3A%5Cn%5Cn%60%60%60ruby%5Cnfind_field('First%20Name').value%5Cnfind_field(id%3A%20'my_field').value%5Cnfind_link('Hello'%2C%20%3Avisible%20%3D%3E%20%3Aall).visible%3F%5Cnfind_link(class%3A%20%5B'some_class'%2C%20'some_other_class'%5D%2C%20%3Avisible%20%3D%3E%20%3Aall).visible%3F%5Cn%5Cnfind_button('Send').click%5Cnfind_button(value%3A%20'1234').click%5Cn%5Cnfind(%3Axpath%2C%20%5C%22.%2F%2Ftable%2Ftr%5C%22).click%5Cnfind(%5C%22%23overlay%5C%22).find(%5C%22h1%5C%22).click%5Cnall('a').each%20%7B%20%7Ca%7C%20a%5B%3Ahref%5D%20%7D%5Cn%60%60%60%5Cn%5CnIf%20you%20need%20to%20find%20elements%20by%20additional%20attributes%2Fproperties%20you%20can%20also%20pass%20a%20filter%20block%2C%20which%20will%20be%20checked%20inside%20the%20normal%20waiting%20behavior.%5CnIf%20you%20find%20yourself%20needing%20to%20use%20this%20a%20lot%20you%20may%20be%20better%20off%20adding%20a%20%5Bcustom%20selector%5D(http%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2FCapybara%23add_selector-class_method)%20or%20%5Badding%20a%20filter%20to%20an%20existing%20selector%5D(http%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2FCapybara%23modify_selector-class_method).%5Cn%5Cn%60%60%60ruby%5Cnfind_field('First%20Name')%7B%20%7Cel%7C%20el%5B'data-xyz'%5D%20%3D%3D%20'123'%20%7D%5Cnfind(%5C%22%23img_loading%5C%22)%7B%20%7Cimg%7C%20img%5B'complete'%5D%20%3D%3D%20true%20%7D%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20%60find%60%20will%20wait%20for%20an%20element%20to%20appear%20on%20the%20page%2C%20as%20explained%20in%20the%5CnAjax%20section.%20If%20the%20element%20does%20not%20appear%20it%20will%20raise%20an%20error.%5Cn%5CnThese%20elements%20all%20have%20all%20the%20Capybara%20DSL%20methods%20available%2C%20so%20you%20can%20restrict%20them%5Cnto%20specific%20parts%20of%20the%20page%3A%5Cn%5Cn%60%60%60ruby%5Cnfind('%23navigation').click_link('Home')%5Cnexpect(find('%23navigation')).to%20have_button('Sign%20out')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22scoping%5C%22%3E%3C%2Fa%3EScoping%5Cn%5CnCapybara%20makes%20it%20possible%20to%20restrict%20certain%20actions%2C%20such%20as%20interacting%20with%5Cnforms%20or%20clicking%20links%20and%20buttons%2C%20to%20within%20a%20specific%20area%20of%20the%20page.%20For%5Cnthis%20purpose%20you%20can%20use%20the%20generic%5Cn%3Ctt%3E%5Bwithin%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23within-instance_method)%3C%2Ftt%3E%5Cnmethod.%20Optionally%20you%20can%20specify%20which%20kind%20of%20selector%20to%20use.%5Cn%5Cn%60%60%60ruby%5Cnwithin(%5C%22li%23employee%5C%22)%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%5Cnwithin(%3Axpath%2C%20%5C%22.%2F%2Fli%5B%40id%3D'employee'%5D%5C%22)%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%60%60%60%5Cn%5CnThere%20are%20special%20methods%20for%20restricting%20the%20scope%20to%20a%20specific%20fieldset%2C%5Cnidentified%20by%20either%20an%20id%20or%20the%20text%20of%20the%20fieldset's%20legend%20tag%2C%20and%20to%20a%5Cnspecific%20table%2C%20identified%20by%20either%20id%20or%20text%20of%20the%20table's%20caption%20tag.%5Cn%5Cn%60%60%60ruby%5Cnwithin_fieldset('Employee')%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%5Cnwithin_table('Employee')%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22working-with-windows%5C%22%3E%3C%2Fa%3EWorking%20with%20windows%5Cn%5CnCapybara%20provides%20some%20methods%20to%20ease%20finding%20and%20switching%20windows%3A%5Cn%5Cn%60%60%60ruby%5Cnfacebook_window%20%3D%20window_opened_by%20do%5Cn%20%20click_button%20'Like'%5Cnend%5Cnwithin_window%20facebook_window%20do%5Cn%20%20find('%23login_email').set('a%40example.com')%5Cn%20%20find('%23login_password').set('qwerty')%5Cn%20%20click_button%20'Submit'%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22scripting%5C%22%3E%3C%2Fa%3EScripting%5Cn%5CnIn%20drivers%20which%20support%20it%2C%20you%20can%20easily%20execute%20JavaScript%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.execute_script(%5C%22%24('body').empty()%5C%22)%5Cn%60%60%60%5Cn%5CnFor%20simple%20expressions%2C%20you%20can%20return%20the%20result%20of%20the%20script.%5Cn%5Cn%60%60%60ruby%5Cnresult%20%3D%20page.evaluate_script('4%20%2B%204')%3B%5Cn%60%60%60%5Cn%5CnFor%20more%20complicated%20scripts%20you'll%20need%20to%20write%20them%20as%20one%20expression.%5Cn%5Cn%60%60%60ruby%5Cnresult%20%3D%20page.evaluate_script(%3C%3C~JS%2C%203%2C%20element)%5Cn%20%20(function(n%2C%20el)%7B%5Cn%20%20%20%20var%20val%20%3D%20parseInt(el.value%2C%2010)%3B%5Cn%20%20%20%20return%20n%2Bval%3B%5Cn%20%20%7D)(arguments%5B0%5D%2C%20arguments%5B1%5D)%5CnJS%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22modals%5C%22%3E%3C%2Fa%3EModals%5Cn%5CnIn%20drivers%20which%20support%20it%2C%20you%20can%20accept%2C%20dismiss%20and%20respond%20to%20alerts%2C%20confirms%2C%20and%20prompts.%5Cn%5CnYou%20can%20accept%20or%20dismiss%20alert%20messages%20by%20wrapping%20the%20code%20that%20produces%20an%20alert%20in%20a%20block%3A%5Cn%5Cn%60%60%60ruby%5Cnaccept_alert%20do%5Cn%20%20click_link('Show%20Alert')%5Cnend%5Cn%60%60%60%5Cn%5CnYou%20can%20accept%20or%20dismiss%20a%20confirmation%20by%20wrapping%20it%20in%20a%20block%2C%20as%20well%3A%5Cn%5Cn%60%60%60ruby%5Cndismiss_confirm%20do%5Cn%20%20click_link('Show%20Confirm')%5Cnend%5Cn%60%60%60%5Cn%5CnYou%20can%20accept%20or%20dismiss%20prompts%20as%20well%2C%20and%20also%20provide%20text%20to%20fill%20in%20for%20the%20response%3A%5Cn%5Cn%60%60%60ruby%5Cnaccept_prompt(with%3A%20'Linus%20Torvalds')%20do%5Cn%20%20click_link('Show%20Prompt%20About%20Linux')%5Cnend%5Cn%60%60%60%5Cn%5CnAll%20modal%20methods%20return%20the%20message%20that%20was%20presented.%20So%2C%20you%20can%20access%20the%20prompt%20message%5Cnby%20assigning%20the%20return%20to%20a%20variable%3A%5Cn%5Cn%60%60%60ruby%5Cnmessage%20%3D%20accept_prompt(with%3A%20'Linus%20Torvalds')%20do%5Cn%20%20click_link('Show%20Prompt%20About%20Linux')%5Cnend%5Cnexpect(message).to%20eq('Who%20is%20the%20chief%20architect%20of%20Linux%3F')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22debugging%5C%22%3E%3C%2Fa%3EDebugging%5Cn%5CnIt%20can%20be%20useful%20to%20take%20a%20snapshot%20of%20the%20page%20as%20it%20currently%20is%20and%20take%20a%5Cnlook%20at%20it%3A%5Cn%5Cn%60%60%60ruby%5Cnsave_and_open_page%5Cn%60%60%60%5Cn%5CnYou%20can%20also%20retrieve%20the%20current%20state%20of%20the%20DOM%20as%20a%20string%20using%5Cn%3Ctt%3E%5Bpage.html%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23html-instance_method)%3C%2Ftt%3E.%5Cn%5Cn%60%60%60ruby%5Cnprint%20page.html%5Cn%60%60%60%5Cn%5CnThis%20is%20mostly%20useful%20for%20debugging.%20You%20should%20avoid%20testing%20against%20the%5Cncontents%20of%20%60page.html%60%20and%20use%20the%20more%20expressive%20finder%20methods%20instead.%5Cn%5CnFinally%2C%20in%20drivers%20that%20support%20it%2C%20you%20can%20save%20a%20screenshot%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.save_screenshot('screenshot.png')%5Cn%60%60%60%5Cn%5CnOr%20have%20it%20save%20and%20automatically%20open%3A%5Cn%5Cn%60%60%60ruby%5Cnsave_and_open_screenshot%5Cn%60%60%60%5Cn%5CnScreenshots%20are%20saved%20to%20%60Capybara.save_path%60%2C%20relative%20to%20the%20app%20directory.%5CnIf%20you%20have%20required%20%60capybara%2Frails%60%2C%20%60Capybara.save_path%60%20will%20default%20to%5Cn%60tmp%2Fcapybara%60.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22matching%5C%22%3E%3C%2Fa%3EMatching%5Cn%5CnIt%20is%20possible%20to%20customize%20how%20Capybara%20finds%20elements.%20At%20your%20disposal%5Cnare%20two%20options%2C%20%60Capybara.exact%60%20and%20%60Capybara.match%60.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22exactness%5C%22%3E%3C%2Fa%3EExactness%5Cn%5Cn%60Capybara.exact%60%20and%20the%20%60exact%60%20option%20work%20together%20with%20the%20%60is%60%20expression%5Cninside%20the%20XPath%20gem.%20When%20%60exact%60%20is%20true%2C%20all%20%60is%60%20expressions%20match%20exactly%2C%5Cnwhen%20it%20is%20false%2C%20they%20allow%20substring%20matches.%20Many%20of%20the%20selectors%20built%20into%5CnCapybara%20use%20the%20%60is%60%20expression.%20This%20way%20you%20can%20specify%20whether%20you%20want%20to%5Cnallow%20substring%20matches%20or%20not.%20%60Capybara.exact%60%20is%20false%20by%20default.%5Cn%5CnFor%20example%3A%5Cn%5Cn%60%60%60ruby%5Cnclick_link(%5C%22Password%5C%22)%20%23%20also%20matches%20%5C%22Password%20confirmation%5C%22%5CnCapybara.exact%20%3D%20true%5Cnclick_link(%5C%22Password%5C%22)%20%23%20does%20not%20match%20%5C%22Password%20confirmation%5C%22%5Cnclick_link(%5C%22Password%5C%22%2C%20exact%3A%20false)%20%23%20can%20be%20overridden%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22strategy%5C%22%3E%3C%2Fa%3EStrategy%5Cn%5CnUsing%20%60Capybara.match%60%20and%20the%20equivalent%20%60match%60%20option%2C%20you%20can%20control%20how%5CnCapybara%20behaves%20when%20multiple%20elements%20all%20match%20a%20query.%20There%20are%20currently%5Cnfour%20different%20strategies%20built%20into%20Capybara%3A%5Cn%5Cn1.%20**first%3A**%20Just%20picks%20the%20first%20element%20that%20matches.%5Cn2.%20**one%3A**%20Raises%20an%20error%20if%20more%20than%20one%20element%20matches.%5Cn3.%20**smart%3A**%20If%20%60exact%60%20is%20%60true%60%2C%20raises%20an%20error%20if%20more%20than%20one%20element%5Cn%20%20%20matches%2C%20just%20like%20%60one%60.%20If%20%60exact%60%20is%20%60false%60%2C%20it%20will%20first%20try%20to%20find%5Cn%20%20%20an%20exact%20match.%20An%20error%20is%20raised%20if%20more%20than%20one%20element%20is%20found.%20If%20no%5Cn%20%20%20element%20is%20found%2C%20a%20new%20search%20is%20performed%20which%20allows%20partial%20matches.%20If%5Cn%20%20%20that%20search%20returns%20multiple%20matches%2C%20an%20error%20is%20raised.%5Cn4.%20**prefer_exact%3A**%20If%20multiple%20matches%20are%20found%2C%20some%20of%20which%20are%20exact%2C%5Cn%20%20%20and%20some%20of%20which%20are%20not%2C%20then%20the%20first%20exactly%20matching%20element%20is%5Cn%20%20%20returned.%5Cn%5CnThe%20default%20for%20%60Capybara.match%60%20is%20%60%3Asmart%60.%20To%20emulate%20the%20behaviour%20in%5CnCapybara%202.0.x%2C%20set%20%60Capybara.match%60%20to%20%60%3Aone%60.%20To%20emulate%20the%20behaviour%20in%5CnCapybara%201.x%2C%20set%20%60Capybara.match%60%20to%20%60%3Aprefer_exact%60.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22transactions-and-database-setup%5C%22%3E%3C%2Fa%3ETransactions%20and%20database%20setup%5Cn%5Cn**Note%3A**%20%20Rails%205.1%2B%20%5C%22safely%5C%22%20shares%20the%20database%20connection%20between%20the%20app%20and%20test%20threads.%20%20Therefore%2C%5Cnif%20using%20Rails%205.1%2B%20you%20SHOULD%20be%20able%20to%20ignore%20this%20section.%5Cn%5CnSome%20Capybara%20drivers%20need%20to%20run%20against%20an%20actual%20HTTP%20server.%20Capybara%20takes%5Cncare%20of%20this%20and%20starts%20one%20for%20you%20in%20the%20same%20process%20as%20your%20test%2C%20but%20on%5Cnanother%20thread.%20Selenium%20is%20one%20of%20those%20drivers%2C%20whereas%20RackTest%20is%20not.%5Cn%5CnIf%20you%20are%20using%20a%20SQL%20database%2C%20it%20is%20common%20to%20run%20every%20test%20in%20a%5Cntransaction%2C%20which%20is%20rolled%20back%20at%20the%20end%20of%20the%20test%2C%20rspec-rails%20does%20this%5Cnby%20default%20out%20of%20the%20box%20for%20example.%20Since%20transactions%20are%20usually%20not%5Cnshared%20across%20threads%2C%20this%20will%20cause%20data%20you%20have%20put%20into%20the%20database%20in%5Cnyour%20test%20code%20to%20be%20invisible%20to%20Capybara.%5Cn%5CnCucumber%20handles%20this%20by%20using%20truncation%20instead%20of%20transactions%2C%20i.e.%20they%5Cnempty%20out%20the%20entire%20database%20after%20each%20test.%20You%20can%20get%20the%20same%20behaviour%5Cnby%20using%20a%20gem%20such%20as%20%5Bdatabase_cleaner%5D(https%3A%2F%2Fgithub.com%2FDatabaseCleaner%2Fdatabase_cleaner).%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22asynchronous-javascript-ajax-and-friends%5C%22%3E%3C%2Fa%3EAsynchronous%20JavaScript%20(Ajax%20and%20friends)%5Cn%5CnWhen%20working%20with%20asynchronous%20JavaScript%2C%20you%20might%20come%20across%20situations%5Cnwhere%20you%20are%20attempting%20to%20interact%20with%20an%20element%20which%20is%20not%20yet%20present%5Cnon%20the%20page.%20Capybara%20automatically%20deals%20with%20this%20by%20waiting%20for%20elements%5Cnto%20appear%20on%20the%20page.%5Cn%5CnWhen%20issuing%20instructions%20to%20the%20DSL%20such%20as%3A%5Cn%5Cn%60%60%60ruby%5Cnclick_link('foo')%5Cnclick_link('bar')%5Cnexpect(page).to%20have_content('baz')%5Cn%60%60%60%5Cn%5CnIf%20clicking%20on%20the%20*foo*%20link%20triggers%20an%20asynchronous%20process%2C%20such%20as%5Cnan%20Ajax%20request%2C%20which%2C%20when%20complete%20will%20add%20the%20*bar*%20link%20to%20the%20page%2C%5Cnclicking%20on%20the%20*bar*%20link%20would%20be%20expected%20to%20fail%2C%20since%20that%20link%20doesn't%5Cnexist%20yet.%20However%2C%20Capybara%20is%20smart%20enough%20to%20retry%20finding%20the%20link%20for%20a%5Cnbrief%20period%20of%20time%20before%20giving%20up%20and%20throwing%20an%20error.%20The%20same%20is%20true%20of%5Cnthe%20next%20line%2C%20which%20looks%20for%20the%20content%20*baz*%20on%20the%20page%3B%20it%20will%20retry%5Cnlooking%20for%20that%20content%20for%20a%20brief%20time.%20You%20can%20adjust%20how%20long%20this%20period%5Cnis%20(the%20default%20is%202%20seconds)%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.default_max_wait_time%20%3D%205%5Cn%60%60%60%5Cn%5CnBe%20aware%20that%20because%20of%20this%20behaviour%2C%20the%20following%20two%20statements%20are%20**not**%5Cnequivalent%2C%20and%20you%20should%20**always**%20use%20the%20latter!%5Cn%5Cn%60%60%60ruby%5Cn%23%20Given%20use%20of%20a%20driver%20where%20the%20page%20is%20loaded%20when%20visit%20returns%5Cn%23%20and%20that%20Capybara.predicates_wait%20is%20%60true%60%5Cn%23%20consider%20a%20page%20where%20the%20%60a%60%20tag%20is%20removed%20through%20AJAX%20after%201s%5Cnvisit(some_path)%5Cn!page.has_xpath%3F('a')%20%20%23%20is%20false%5Cnpage.has_no_xpath%3F('a')%20%20%23%20is%20true%5Cn%60%60%60%5Cn%5CnFirst%20expression%3A%5Cn-%20%60has_xpath%3F('a')%60%20is%20called%20right%20after%20%60visit%60%20returns.%20It%20is%20%60true%60%20because%20the%20link%20has%20not%20yet%20been%20removed%5Cn-%20Capybara%20does%20not%20wait%20upon%20successful%20predicates%2Fassertions%2C%20therefore%20**has_xpath%3F%20returns%20%60true%60%20immediately**%5Cn-%20The%20expression%20returns%20%60false%60%20(because%20it%20is%20negated%20with%20the%20leading%20%60!%60)%5Cn%5CnSecond%20expression%3A%5Cn-%20%60has_no_xpath%3F('a')%60%20is%20called%20right%20after%20%60visit%60%20returns.%20It%20is%20%60false%60%20because%20the%20link%20has%20not%20yet%20been%20removed.%5Cn-%20Capybara%20waits%20upon%20failed%20predicates%2Fassertions%2C%20therefore%20**has_no_xpath%3F%20does%20not%20return%20%60false%60%20immediately**%5Cn-%20Capybara%20will%20periodically%20re-check%20the%20predicate%2Fassertion%20up%20to%20the%20%60default_max_wait_time%60%20defined%5Cn-%20after%201s%2C%20the%20predicate%20becomes%20%60true%60%20(because%20the%20link%20has%20been%20removed)%5Cn-%20The%20expression%20returns%20%60true%60%5Cn%5CnCapybara's%20RSpec%20matchers%2C%20however%2C%20are%20smart%20enough%20to%20handle%20either%20form.%5CnThe%20two%20following%20statements%20are%20functionally%20equivalent%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(page).not_to%20have_xpath('a')%5Cnexpect(page).to%20have_no_xpath('a')%5Cn%60%60%60%5Cn%5CnCapybara's%20waiting%20behaviour%20is%20quite%20advanced%2C%20and%20can%20deal%20with%20situations%5Cnsuch%20as%20the%20following%20line%20of%20code%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(find('%23sidebar').find('h1')).to%20have_content('Something')%5Cn%60%60%60%5Cn%5CnEven%20if%20JavaScript%20causes%20%60%23sidebar%60%20to%20disappear%20off%20the%20page%2C%20Capybara%5Cnwill%20automatically%20reload%20it%20and%20any%20elements%20it%20contains.%20So%20if%20an%20AJAX%5Cnrequest%20causes%20the%20contents%20of%20%60%23sidebar%60%20to%20change%2C%20which%20would%20update%5Cnthe%20text%20of%20the%20%60h1%60%20to%20%5C%22Something%5C%22%2C%20and%20this%20happened%2C%20this%20test%20would%5Cnpass.%20If%20you%20do%20not%20want%20this%20behaviour%2C%20you%20can%20set%5Cn%60Capybara.automatic_reload%60%20to%20%60false%60.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-the-dsl-elsewhere%5C%22%3E%3C%2Fa%3EUsing%20the%20DSL%20elsewhere%5Cn%5CnYou%20can%20mix%20the%20DSL%20into%20any%20context%20by%20including%20%3Ctt%3ECapybara%3A%3ADSL%3C%2Ftt%3E%3A%5Cn%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Fdsl'%5Cn%5CnCapybara.default_driver%20%3D%20%3Awebkit%5Cn%5Cnmodule%20MyModule%5Cn%20%20include%20Capybara%3A%3ADSL%5Cn%5Cn%20%20def%20login!%5Cn%20%20%20%20within(%3Axpath%2C%20%5C%22.%2F%2Fform%5B%40id%3D'session'%5D%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'password'%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5CnThis%20enables%20its%20use%20in%20unsupported%20testing%20frameworks%2C%20and%20for%20general-purpose%20scripting.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22calling-remote-servers%5C%22%3E%3C%2Fa%3ECalling%20remote%20servers%5Cn%5CnNormally%20Capybara%20expects%20to%20be%20testing%20an%20in-process%20Rack%20application%2C%20but%20you%5Cncan%20also%20use%20it%20to%20talk%20to%20a%20web%20server%20running%20anywhere%20on%20the%20internet%2C%20by%5Cnsetting%20app_host%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.current_driver%20%3D%20%3Aselenium%5CnCapybara.app_host%20%3D%20'http%3A%2F%2Fwww.google.com'%5Cn...%5Cnvisit('%2F')%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20the%20default%20driver%20(%60%3Arack_test%60)%20does%20not%20support%20running%5Cnagainst%20a%20remote%20server.%20With%20drivers%20that%20support%20it%2C%20you%20can%20also%20visit%20any%5CnURL%20directly%3A%5Cn%5Cn%60%60%60ruby%5Cnvisit('http%3A%2F%2Fwww.google.com')%5Cn%60%60%60%5Cn%5CnBy%20default%20Capybara%20will%20try%20to%20boot%20a%20rack%20application%20automatically.%20You%5Cnmight%20want%20to%20switch%20off%20Capybara's%20rack%20server%20if%20you%20are%20running%20against%20a%5Cnremote%20application%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.run_server%20%3D%20false%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-sessions%5C%22%3E%3C%2Fa%3EUsing%20sessions%5Cn%5CnCapybara%20manages%20named%20sessions%20(%3Adefault%20if%20not%20specified)%20allowing%20multiple%20sessions%20using%20the%20same%20driver%20and%20test%20app%20instance%20to%20be%20interacted%20with.%5CnA%20new%20session%20will%20be%20created%20using%20the%20current%20driver%20if%20a%20session%20with%20the%20given%20name%20using%20the%20current%20driver%20and%20test%20app%20instance%20is%20not%20found.%5Cn%5Cn%23%23%23%20Named%20sessions%5CnTo%20perform%20operations%20in%20a%20different%20session%20and%20then%20revert%20to%20the%20previous%20session%5Cn%5Cn%60%60%60ruby%5CnCapybara.using_session(%5C%22Bob's%20session%5C%22)%20do%5Cn%20%20%20%23do%20something%20in%20Bob's%20browser%20session%5Cnend%5Cn%20%23reverts%20to%20previous%20session%5Cn%60%60%60%5Cn%5CnTo%20permanently%20switch%20the%20current%20session%20to%20a%20different%20session%5Cn%5Cn%60%60%60ruby%5CnCapybara.session_name%20%3D%20%5C%22some%20other%20session%5C%22%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22using-sessions-manually%5C%22%3E%3C%2Fa%3EUsing%20sessions%20manually%5Cn%5CnFor%20ultimate%20control%2C%20you%20can%20instantiate%20and%20use%20a%5Cn%5BSession%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession)%5Cnmanually.%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara'%5Cn%5Cnsession%20%3D%20Capybara%3A%3ASession.new(%3Awebkit%2C%20my_rack_app)%5Cnsession.within(%5C%22form%23session%5C%22)%20do%5Cn%20%20session.fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20session.fill_in%20'Password'%2C%20with%3A%20'password'%5Cnend%5Cnsession.click_button%20'Sign%20in'%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22xpath-css-and-selectors%5C%22%3E%3C%2Fa%3EXPath%2C%20CSS%20and%20selectors%5Cn%5CnCapybara%20does%20not%20try%20to%20guess%20what%20kind%20of%20selector%20you%20are%20going%20to%20give%20it%2C%5Cnand%20will%20always%20use%20CSS%20by%20default.%20%20If%20you%20want%20to%20use%20XPath%2C%20you'll%20need%20to%5Cndo%3A%5Cn%5Cn%60%60%60ruby%5Cnwithin(%3Axpath%2C%20'.%2F%2Ful%2Fli')%20%7B%20...%20%7D%5Cnfind(%3Axpath%2C%20'.%2F%2Ful%2Fli').text%5Cnfind(%3Axpath%2C%20'.%2F%2Fli%5Bcontains(.%2F%2Fa%5B%40href%20%3D%20%5C%22%23%5C%22%5D%2Ftext()%2C%20%5C%22foo%5C%22)%5D').value%5Cn%60%60%60%5Cn%5CnAlternatively%20you%20can%20set%20the%20default%20selector%20to%20XPath%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.default_selector%20%3D%20%3Axpath%5Cnfind('.%2F%2Ful%2Fli').text%5Cn%60%60%60%5Cn%5CnCapybara%20provides%20a%20number%20of%20other%20built-in%20selector%20types.%20The%20full%20list%2C%20along%5Cnwith%20applicable%20filters%2C%20can%20be%20seen%20at%20%5Bbuilt-in%20selectors%5D(https%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2FCapybara%2FSelector)%5Cn%5CnCapybara%20also%20allows%20you%20to%20add%20custom%20selectors%2C%20which%20can%20be%20very%20useful%20if%20you%5Cnfind%20yourself%20using%20the%20same%20kinds%20of%20selectors%20very%20often.%20The%20examples%20below%20are%20very%5Cnsimple%2C%20and%20there%20are%20many%20available%20features%20not%20demonstrated.%20For%20more%20in-depth%20examples%5Cnplease%20see%20Capybaras%20built-in%20selector%20definitions.%5Cn%5Cn%60%60%60ruby%5CnCapybara.add_selector(%3Amy_attribute)%20do%5Cn%20%20xpath%20%7B%20%7Cid%7C%20XPath.descendant%5BXPath.attr(%3Amy_attribute)%20%3D%3D%20id.to_s%5D%20%7D%5Cnend%5Cn%5CnCapybara.add_selector(%3Arow)%20do%5Cn%20%20xpath%20%7B%20%7Cnum%7C%20%5C%22.%2F%2Ftbody%2Ftr%5B%23%7Bnum%7D%5D%5C%22%20%7D%5Cnend%5Cn%5CnCapybara.add_selector(%3Aflash_type)%20do%5Cn%20%20css%20%7B%20%7Ctype%7C%20%5C%22%23flash.%23%7Btype%7D%5C%22%20%7D%5Cnend%5Cn%60%60%60%5Cn%5CnThe%20block%20given%20to%20xpath%20must%20always%20return%20an%20XPath%20expression%20as%20a%20String%2C%20or%5Cnan%20XPath%20expression%20generated%20through%20the%20XPath%20gem.%20You%20can%20now%20use%20these%5Cnselectors%20like%20this%3A%5Cn%5Cn%60%60%60ruby%5Cnfind(%3Amy_attribute%2C%20'post_123')%20%23%20find%20element%20with%20matching%20attribute%5Cnfind(%3Arow%2C%203)%20%23%20find%203rd%20row%20in%20table%20body%5Cnfind(%3Aflash_type%2C%20%3Anotice)%20%23%20find%20element%20with%20id%20of%20'flash'%20and%20class%20of%20'notice'%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22beware-the-xpath--trap%5C%22%3E%3C%2Fa%3EBeware%20the%20XPath%20%2F%2F%20trap%5Cn%5CnIn%20XPath%20the%20expression%20%2F%2F%20means%20something%20very%20specific%2C%20and%20it%20might%20not%20be%20what%5Cnyou%20think.%20Contrary%20to%20common%20belief%2C%20%2F%2F%20means%20%5C%22anywhere%20in%20the%20document%5C%22%20not%20%5C%22anywhere%5Cnin%20the%20current%20context%5C%22.%20As%20an%20example%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.find(%3Axpath%2C%20'%2F%2Fbody').all(%3Axpath%2C%20'%2F%2Fscript')%5Cn%60%60%60%5Cn%5CnYou%20might%20expect%20this%20to%20find%20all%20script%20tags%20in%20the%20body%2C%20but%20actually%2C%20it%20finds%20all%5Cnscript%20tags%20in%20the%20entire%20document%2C%20not%20only%20those%20in%20the%20body!%20What%20you're%20looking%5Cnfor%20is%20the%20.%2F%2F%20expression%20which%20means%20%5C%22any%20descendant%20of%20the%20current%20node%5C%22%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.find(%3Axpath%2C%20'%2F%2Fbody').all(%3Axpath%2C%20'.%2F%2Fscript')%5Cn%60%60%60%5CnThe%20same%20thing%20goes%20for%20within%3A%5Cn%5Cn%60%60%60ruby%5Cnwithin(%3Axpath%2C%20'%2F%2Fbody')%20do%5Cn%20%20page.find(%3Axpath%2C%20'.%2F%2Fscript')%5Cn%20%20within(%3Axpath%2C%20'.%2F%2Ftable%2Ftbody')%20do%5Cn%20%20...%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22configuring-and-adding-drivers%5C%22%3E%3C%2Fa%3EConfiguring%20and%20adding%20drivers%5Cn%5CnCapybara%20makes%20it%20convenient%20to%20switch%20between%20different%20drivers.%20It%20also%20exposes%5Cnan%20API%20to%20tweak%20those%20drivers%20with%20whatever%20settings%20you%20want%2C%20or%20to%20add%20your%20own%5Cndrivers.%20This%20is%20how%20to%20override%20the%20selenium%20driver%20configuration%20to%20use%20chrome%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.register_driver%20%3Aselenium%20do%20%7Capp%7C%5Cn%20%20Capybara%3A%3ASelenium%3A%3ADriver.new(app%2C%20%3Abrowser%20%3D%3E%20%3Achrome)%5Cnend%5Cn%60%60%60%5Cn%5CnHowever%2C%20it's%20also%20possible%20to%20give%20this%20configuration%20a%20different%20name.%5Cn%5Cn%60%60%60ruby%5Cn%23%20Note%3A%20Capybara%20registers%20this%20by%20default%5CnCapybara.register_driver%20%3Aselenium_chrome%20do%20%7Capp%7C%5Cn%20%20Capybara%3A%3ASelenium%3A%3ADriver.new(app%2C%20%3Abrowser%20%3D%3E%20%3Achrome)%5Cnend%5Cn%60%60%60%5Cn%5CnThen%20tests%20can%20switch%20between%20using%20different%20browsers%20effortlessly%3A%5Cn%60%60%60ruby%5CnCapybara.current_driver%20%3D%20%3Aselenium_chrome%5Cn%60%60%60%5Cn%5CnWhatever%20is%20returned%20from%20the%20block%20should%20conform%20to%20the%20API%20described%20by%5CnCapybara%3A%3ADriver%3A%3ABase%2C%20it%20does%20not%20however%20have%20to%20inherit%20from%20this%20class.%5CnGems%20can%20use%20this%20API%20to%20add%20their%20own%20drivers%20to%20Capybara.%5Cn%5CnThe%20%5BSelenium%20wiki%5D(https%3A%2F%2Fgithub.com%2FSeleniumHQ%2Fselenium%2Fwiki%2FRuby-Bindings)%20has%5Cnadditional%20info%20about%20how%20the%20underlying%20driver%20can%20be%20configured.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22gotchas%5C%22%3E%3C%2Fa%3EGotchas%3A%5Cn%5Cn*%20Access%20to%20session%20and%20request%20is%20not%20possible%20from%20the%20test%2C%20Access%20to%5Cn%20%20response%20is%20limited.%20Some%20drivers%20allow%20access%20to%20response%20headers%20and%20HTTP%5Cn%20%20status%20code%2C%20but%20this%20kind%20of%20functionality%20is%20not%20provided%20by%20some%20drivers%2C%5Cn%20%20such%20as%20Selenium.%5Cn%5Cn*%20Access%20to%20Rails%20specific%20stuff%20(such%20as%20%60controller%60)%20is%20unavailable%2C%5Cn%20%20since%20we're%20not%20using%20Rails'%20integration%20testing.%5Cn%5Cn*%20Freezing%20time%3A%20It's%20common%20practice%20to%20mock%20out%20the%20Time%20so%20that%20features%5Cn%20%20that%20depend%20on%20the%20current%20Date%20work%20as%20expected.%20This%20can%20be%20problematic%20on%5Cn%20%20ruby%2Fplatform%20combinations%20that%20don't%20support%20access%20to%20a%20monotonic%20process%20clock%2C%5Cn%20%20since%20Capybara's%20Ajax%20timing%20uses%20the%20system%20time%2C%20resulting%20in%20Capybara%5Cn%20%20never%20timing%20out%20and%20just%20hanging%20when%20a%20failure%20occurs.%20It's%20still%20possible%20to%5Cn%20%20use%20gems%20which%20allow%20you%20to%20travel%20in%20time%2C%20rather%20than%20freeze%20time.%5Cn%20%20One%20such%20gem%20is%20%5BTimecop%5D(https%3A%2F%2Fgithub.com%2Ftravisjeffery%2Ftimecop).%5Cn%5Cn*%20When%20using%20Rack%3A%3ATest%2C%20beware%20if%20attempting%20to%20visit%20absolute%20URLs.%20For%5Cn%20%20example%2C%20a%20session%20might%20not%20be%20shared%20between%20visits%20to%20%60posts_path%60%5Cn%20%20and%20%60posts_url%60.%20If%20testing%20an%20absolute%20URL%20in%20an%20Action%20Mailer%20email%2C%5Cn%20%20set%20%60default_url_options%60%20to%20match%20the%20Rails%20default%20of%5Cn%20%20%60www.example.com%60.%5Cn%5Cn*%20Server%20errors%20will%20only%20be%20raised%20in%20the%20session%20that%20initiates%20the%20server%20thread.%20If%20you%5Cn%20%20are%20testing%20for%20specific%20server%20errors%20and%20using%20multiple%20sessions%20make%20sure%20to%20test%20for%20the%5Cn%20%20errors%20using%20the%20initial%20session%20(usually%20%3Adefault)%5Cn%5Cn*%20If%20WebMock%20is%20enabled%2C%20you%20may%20encounter%20a%20%5C%22Too%20many%20open%20files%5C%22%5Cn%20%20error.%20A%20simple%20%60page.find%60%20call%20may%20cause%20thousands%20of%20HTTP%20requests%5Cn%20%20until%20the%20timeout%20occurs.%20By%20default%2C%20WebMock%20will%20cause%20each%20of%20these%5Cn%20%20requests%20to%20spawn%20a%20new%20connection.%20To%20work%20around%20this%20problem%2C%20you%5Cn%20%20may%20need%20to%20%5Benable%20WebMock's%20%60net_http_connect_on_start%3A%20true%60%5Cn%20%20parameter%5D(https%3A%2F%2Fgithub.com%2Fbblimke%2Fwebmock%2Fblob%2Fmaster%2FREADME.md%23connecting-on-nethttpstart).%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22threadsafe%5C%22%3E%3C%2Fa%3E%5C%22Threadsafe%5C%22%20mode%5Cn%5CnIn%20normal%20mode%20most%20of%20Capybara's%20configuration%20options%20are%20global%20settings%20which%20can%20cause%20issues%5Cnif%20using%20multiple%20sessions%20and%20wanting%20to%20change%20a%20setting%20for%20only%20one%20of%20the%20sessions.%20%20To%20provide%5Cnsupport%20for%20this%20type%20of%20usage%20Capybara%20now%20provides%20a%20%5C%22threadsafe%5C%22%20mode%20which%20can%20be%20enabled%20by%20setting%5Cn%5Cn%60%60%60ruby%5CnCapybara.threadsafe%20%3D%20true%5Cn%60%60%60%5Cn%5CnThis%20setting%20can%20only%20be%20changed%20before%20any%20sessions%20have%20been%20created.%20%20In%20%5C%22threadsafe%5C%22%20mode%20the%20following%5Cnbehaviors%20of%20Capybara%20change%5Cn%5Cn*%20Most%20options%20can%20now%20be%20set%20on%20a%20session.%20%20These%20can%20either%20be%20set%20at%20session%20creation%20time%20or%20after%2C%20and%5Cn%20%20default%20to%20the%20global%20options%20at%20the%20time%20of%20session%20creation.%20%20Options%20which%20are%20NOT%20session%20specific%20are%5Cn%20%20%60app%60%2C%20%60reuse_server%60%2C%20%60default_driver%60%2C%20%60javascript_driver%60%2C%20and%20(obviously)%20%60threadsafe%60.%20%20Any%20drivers%20and%20servers%5Cn%20%20registered%20through%20%60register_driver%60%20and%20%60register_server%60%20are%20also%20global.%5Cn%5Cn%20%20%60%60%60ruby%5Cn%20%20my_session%20%3D%20Capybara%3A%3ASession.new(%3Adriver%2C%20some_app)%20do%20%7Cconfig%7C%5Cn%20%20%20%20config.automatic_label_click%20%3D%20true%20%23%20only%20set%20for%20my_session%5Cn%20%20end%5Cn%20%20my_session.config.default_max_wait_time%20%3D%2010%20%23%20only%20set%20for%20my_session%5Cn%20%20Capybara.default_max_wait_time%20%3D%202%20%23%20will%20not%20change%20the%20default_max_wait%20in%20my_session%5Cn%20%20%60%60%60%5Cn%5Cn*%20%60current_driver%60%20and%20%60session_name%60%20are%20thread%20specific.%20%20This%20means%20that%20%60using_session%60%20and%5Cn%20%20%60using_driver%60%20also%20only%20affect%20the%20current%20thread.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22development%5C%22%3E%3C%2Fa%3EDevelopment%5Cn%5CnTo%20set%20up%20a%20development%20environment%2C%20simply%20do%3A%5Cn%5Cn%60%60%60bash%5Cnbundle%20install%5Cnbundle%20exec%20rake%20%20%23%20run%20the%20test%20suite%20with%20Firefox%20-%20requires%20%60geckodriver%60%20to%20be%20installed%5Cnbundle%20exec%20rake%20spec_chrome%20%23%20run%20the%20test%20suite%20with%20Chrome%20-%20require%20%60chromedriver%60%20to%20be%20installed%5Cn%60%60%60%5Cn%5CnSee%5Cn%5BCONTRIBUTING.md%5D(https%3A%2F%2Fgithub.com%2Fteamcapybara%2Fcapybara%2Fblob%2Fmaster%2FCONTRIBUTING.md)%5Cnfor%20how%20to%20send%20issues%20and%20pull%20requests.%5Cn%22%2C%22sha%22%3A%227a2d8c561500976ce3484b311c48cb0cab279b56%22%2C%22replace_content%22%3A%22%23%20Capybara%5Cn%5Cn%5B!%5BBuild%20Status%5D(https%3A%2F%2Fgithub.com%2Fteamcapybara%2Fcapybara%2Factions%2Fworkflows%2Fbuild.yml%2Fbadge.svg)%5D(https%3A%2F%2Fgithub.com%2Fteamcapybara%2Fcapybara%2Factions%2Fworkflows%2Fbuild.yml)%5Cn%5B!%5BCode%20Climate%5D(https%3A%2F%2Fcodeclimate.com%2Fgithub%2Fteamcapybara%2Fcapybara.svg)%5D(https%3A%2F%2Fcodeclimate.com%2Fgithub%2Fteamcapybara%2Fcapybara)%5Cn%5B!%5BCoverage%20Status%5D(https%3A%2F%2Fcoveralls.io%2Frepos%2Fgithub%2Fteamcapybara%2Fcapybara%2Fbadge.svg%3Fbranch%3Dmaster)%5D(https%3A%2F%2Fcoveralls.io%2Fgithub%2Fteamcapybara%2Fcapybara%3Fbranch%3Dmaster)%5Cn%5CnCapybara%20helps%20you%20test%20web%20applications%20by%20simulating%20how%20a%20real%20user%20would%5Cninteract%20with%20your%20app.%20It%20is%20agnostic%20about%20the%20driver%20running%20your%20tests%20and%5Cncomes%20with%20Rack%3A%3ATest%20and%20Selenium%20support%20built%20in.%20WebKit%20is%20supported%5Cnthrough%20an%20external%20gem.%5Cn%5Cn%23%23%20Support%20Capybara%5Cn%5CnIf%20you%20and%2For%20your%20company%20find%20value%20in%20Capybara%20and%20would%20like%20to%20contribute%20financially%20to%20its%20ongoing%20maintenance%20and%20development%2C%20please%20visit%5Cn%3Ca%20href%3D%5C%22https%3A%2F%2Fwww.patreon.com%2Fcapybara%5C%22%3EPatreon%3C%2Fa%3E%5Cn%5Cn%5Cn**Need%20help%3F**%20Ask%20on%20the%20discussions%20(please%20do%20not%20open%20an%20issue)%3A%20https%3A%2F%2Fgithub.com%2Forgs%2Fteamcapybara%2Fdiscussions%2Fcategories%2Fq-a%5Cn%5Cn%23%23%20Table%20of%20contents%5Cn%5Cn-%20%5BKey%20benefits%5D(%23key-benefits)%5Cn-%20%5BSetup%5D(%23setup)%5Cn-%20%5BUsing%20Capybara%20with%20Cucumber%5D(%23using-capybara-with-cucumber)%5Cn-%20%5BUsing%20Capybara%20with%20RSpec%5D(%23using-capybara-with-rspec)%5Cn-%20%5BUsing%20Capybara%20with%20Test%3A%3AUnit%5D(%23using-capybara-with-testunit)%5Cn-%20%5BUsing%20Capybara%20with%20Minitest%5D(%23using-capybara-with-minitest)%5Cn-%20%5BUsing%20Capybara%20with%20Minitest%3A%3ASpec%5D(%23using-capybara-with-minitestspec)%5Cn-%20%5BDrivers%5D(%23drivers)%5Cn%20%20%20%20-%20%5BSelecting%20the%20Driver%5D(%23selecting-the-driver)%5Cn%20%20%20%20-%20%5BRackTest%5D(%23racktest)%5Cn%20%20%20%20-%20%5BSelenium%5D(%23selenium)%5Cn-%20%5BThe%20DSL%5D(%23the-dsl)%5Cn%20%20%20%20-%20%5BNavigating%5D(%23navigating)%5Cn%20%20%20%20-%20%5BClicking%20links%20and%20buttons%5D(%23clicking-links-and-buttons)%5Cn%20%20%20%20-%20%5BInteracting%20with%20forms%5D(%23interacting-with-forms)%5Cn%20%20%20%20-%20%5BQuerying%5D(%23querying)%5Cn%20%20%20%20-%20%5BFinding%5D(%23finding)%5Cn%20%20%20%20-%20%5BScoping%5D(%23scoping)%5Cn%20%20%20%20-%20%5BWorking%20with%20windows%5D(%23working-with-windows)%5Cn%20%20%20%20-%20%5BScripting%5D(%23scripting)%5Cn%20%20%20%20-%20%5BModals%5D(%23modals)%5Cn%20%20%20%20-%20%5BDebugging%5D(%23debugging)%5Cn-%20%5BMatching%5D(%23matching)%5Cn%20%20%20%20-%20%5BExactness%5D(%23exactness)%5Cn%20%20%20%20-%20%5BStrategy%5D(%23strategy)%5Cn-%20%5BTransactions%20and%20database%20setup%5D(%23transactions-and-database-setup)%5Cn-%20%5BAsynchronous%20JavaScript%20(Ajax%20and%20friends)%5D(%23asynchronous-javascript-ajax-and-friends)%5Cn-%20%5BUsing%20the%20DSL%20elsewhere%5D(%23using-the-dsl-elsewhere)%5Cn-%20%5BCalling%20remote%20servers%5D(%23calling-remote-servers)%5Cn-%20%5BUsing%20sessions%5D(%23using-sessions)%5Cn%20%20%20%20-%20%5BNamed%20sessions%5D(%23named-sessions)%5Cn%20%20%20%20-%20%5BUsing%20sessions%20manually%5D(%23using-sessions-manually)%5Cn-%20%5BXPath%2C%20CSS%20and%20selectors%5D(%23xpath-css-and-selectors)%5Cn-%20%5BBeware%20the%20XPath%20%2F%2F%20trap%5D(%23beware-the-xpath--trap)%5Cn-%20%5BConfiguring%20and%20adding%20drivers%5D(%23configuring-and-adding-drivers)%5Cn-%20%5BGotchas%3A%5D(%23gotchas)%5Cn-%20%5B%5C%22Threadsafe%5C%22%20mode%5D(%23threadsafe-mode)%5Cn-%20%5BDevelopment%5D(%23development)%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22key-benefits%5C%22%3E%3C%2Fa%3EKey%20benefits%5Cn%5Cn-%20**No%20setup**%20necessary%20for%20Rails%20and%20Rack%20application.%20Works%20out%20of%20the%20box.%5Cn-%20**Intuitive%20API**%20which%20mimics%20the%20language%20an%20actual%20user%20would%20use.%5Cn-%20**Switch%20the%20backend**%20your%20tests%20run%20against%20from%20fast%20headless%20mode%5Cn%20%20to%20an%20actual%20browser%20with%20no%20changes%20to%20your%20tests.%5Cn-%20**Powerful%20synchronization**%20features%20mean%20you%20never%20have%20to%20manually%20wait%5Cn%20%20for%20asynchronous%20processes%20to%20complete.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22setup%5C%22%3E%3C%2Fa%3ESetup%5Cn%5CnCapybara%20requires%20Ruby%203.0.0%20or%20later.%20To%20install%2C%20add%20this%20line%20to%20your%5Cn%60Gemfile%60%20and%20run%20%60bundle%20install%60%3A%5Cn%5Cn%60%60%60ruby%5Cngem%20'capybara'%5Cn%60%60%60%5Cn%5CnIf%20the%20application%20that%20you%20are%20testing%20is%20a%20Rails%20app%2C%20add%20this%20line%20to%20your%20test%20helper%20file%3A%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Frails'%5Cn%60%60%60%5Cn%5CnIf%20the%20application%20that%20you%20are%20testing%20is%20a%20Rack%20app%2C%20but%20not%20Rails%2C%20set%20Capybara.app%20to%20your%20Rack%20app%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.app%20%3D%20MyRackApp%5Cn%60%60%60%5Cn%5CnIf%20you%20need%20to%20test%20JavaScript%2C%20or%20if%20your%20app%20interacts%20with%20(or%20is%20located%20at)%5Cna%20remote%20URL%2C%20you'll%20need%20to%20%5Buse%20a%20different%20driver%5D(%23drivers).%20%20If%20using%20Rails%205.0%2B%2C%20but%20not%20using%20the%20Rails%20system%20tests%20from%205.1%2C%20you'll%20probably%20also%5Cnwant%20to%20swap%20the%20%5C%22server%5C%22%20used%20to%20launch%20your%20app%20to%20Puma%20in%20order%20to%20match%20Rails%20defaults.%5Cn%5Cn%60%60%60ruby%5CnCapybara.server%20%3D%20%3Apuma%20%23%20Until%20your%20setup%20is%20working%5CnCapybara.server%20%3D%20%3Apuma%2C%20%7B%20Silent%3A%20true%20%7D%20%23%20To%20clean%20up%20your%20test%20output%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-cucumber%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Cucumber%5Cn%5CnThe%20%60cucumber-rails%60%20gem%20comes%20with%20Capybara%20support%20built-in.%20If%20you%5Cnare%20not%20using%20Rails%2C%20manually%20load%20the%20%60capybara%2Fcucumber%60%20module%3A%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Fcucumber'%5CnCapybara.app%20%3D%20MyRackApp%5Cn%60%60%60%5Cn%5CnYou%20can%20use%20the%20Capybara%20DSL%20in%20your%20steps%2C%20like%20so%3A%5Cn%5Cn%60%60%60ruby%5CnWhen%20%2FI%20sign%20in%2F%20do%5Cn%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'password'%5Cn%20%20end%5Cn%20%20click_button%20'Sign%20in'%5Cnend%5Cn%60%60%60%5Cn%5CnYou%20can%20switch%20to%20the%20%60Capybara.javascript_driver%60%20(%60%3Aselenium%60%5Cnby%20default)%20by%20tagging%20scenarios%20(or%20features)%20with%20%60%40javascript%60%3A%5Cn%5Cn%60%60%60ruby%5Cn%40javascript%5CnScenario%3A%20do%20something%20Ajaxy%5Cn%20%20When%20I%20click%20the%20Ajax%20link%5Cn%20%20...%5Cn%60%60%60%5Cn%5CnThere%20are%20also%20explicit%20tags%20for%20each%20registered%20driver%20set%20up%20for%20you%20(%60%40selenium%60%2C%20%60%40rack_test%60%2C%20etc).%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-rspec%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20RSpec%5Cn%5CnLoad%20RSpec%203.5%2B%20support%20by%20adding%20the%20following%20line%20(typically%20to%20your%5Cn%60spec_helper.rb%60%20file)%3A%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Frspec'%5Cn%60%60%60%5Cn%5CnIf%20you%20are%20using%20Rails%2C%20put%20your%20Capybara%20specs%20in%20%60spec%2Ffeatures%60%20or%20%60spec%2Fsystem%60%20(only%20works%5Cnif%20%5Byou%20have%20it%20configured%20in%5CnRSpec%5D(https%3A%2F%2Frelishapp.com%2Frspec%2Frspec-rails%2Fv%2F4-0%2Fdocs%2Fdirectory-structure))%5Cnand%20if%20you%20have%20your%20Capybara%20specs%20in%20a%20different%20directory%2C%20then%20tag%20the%5Cnexample%20groups%20with%20%60type%3A%20%3Afeature%60%20or%20%60type%3A%20%3Asystem%60%20depending%20on%20which%20type%20of%20test%20you're%20writing.%5Cn%5CnIf%20you%20are%20using%20Rails%20system%20specs%20please%20see%20%5Btheir%20documentation%5D(https%3A%2F%2Frelishapp.com%2Frspec%2Frspec-rails%2Fdocs%2Fsystem-specs%2Fsystem-spec%23system-specs-driven-by-selenium-chrome-headless)%20for%20selecting%20the%20driver%20you%20wish%20to%20use.%5Cn%5CnIf%20you%20are%20not%20using%20Rails%2C%20tag%20all%20the%20example%20groups%20in%20which%20you%20want%20to%20use%5CnCapybara%20with%20%60type%3A%20%3Afeature%60.%5Cn%5CnYou%20can%20now%20write%20your%20specs%20like%20so%3A%5Cn%5Cn%60%60%60ruby%5Cndescribe%20%5C%22the%20signin%20process%5C%22%2C%20type%3A%20%3Afeature%20do%5Cn%20%20before%20%3Aeach%20do%5Cn%20%20%20%20User.create(email%3A%20'user%40example.com'%2C%20password%3A%20'password')%5Cn%20%20end%5Cn%5Cn%20%20it%20%5C%22signs%20me%20in%5C%22%20do%5Cn%20%20%20%20visit%20'%2Fsessions%2Fnew'%5Cn%20%20%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'password'%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20%20%20expect(page).to%20have_content%20'Success'%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5CnUse%20%60js%3A%20true%60%20to%20switch%20to%20the%20%60Capybara.javascript_driver%60%5Cn(%60%3Aselenium%60%20by%20default)%2C%20or%20provide%20a%20%60%3Adriver%60%20option%20to%20switch%5Cnto%20one%20specific%20driver.%20For%20example%3A%5Cn%5Cn%60%60%60ruby%5Cndescribe%20'some%20stuff%20which%20requires%20js'%2C%20js%3A%20true%20do%5Cn%20%20it%20'will%20use%20the%20default%20js%20driver'%5Cn%20%20it%20'will%20switch%20to%20one%20specific%20driver'%2C%20driver%3A%20%3Aselenium%5Cnend%5Cn%60%60%60%5Cn%5CnCapybara%20also%20comes%20with%20a%20built%20in%20DSL%20for%20creating%20descriptive%20acceptance%20tests%3A%5Cn%5Cn%60%60%60ruby%5Cnfeature%20%5C%22Signing%20in%5C%22%20do%5Cn%20%20background%20do%5Cn%20%20%20%20User.create(email%3A%20'user%40example.com'%2C%20password%3A%20'caplin')%5Cn%20%20end%5Cn%5Cn%20%20scenario%20%5C%22Signing%20in%20with%20correct%20credentials%5C%22%20do%5Cn%20%20%20%20visit%20'%2Fsessions%2Fnew'%5Cn%20%20%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'caplin'%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20%20%20expect(page).to%20have_content%20'Success'%5Cn%20%20end%5Cn%5Cn%20%20given(%3Aother_user)%20%7B%20User.create(email%3A%20'other%40example.com'%2C%20password%3A%20'rous')%20%7D%5Cn%5Cn%20%20scenario%20%5C%22Signing%20in%20as%20another%20user%5C%22%20do%5Cn%20%20%20%20visit%20'%2Fsessions%2Fnew'%5Cn%20%20%20%20within(%5C%22%23session%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20other_user.email%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20other_user.password%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20%20%20expect(page).to%20have_content%20'Invalid%20email%20or%20password'%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn%60feature%60%20is%20in%20fact%20just%20an%20alias%20for%20%60describe%20...%2C%20type%3A%20%3Afeature%60%2C%5Cn%60background%60%20is%20an%20alias%20for%20%60before%60%2C%20%60scenario%60%20for%20%60it%60%2C%20and%5Cn%60given%60%2F%60given!%60%20aliases%20for%20%60let%60%2F%60let!%60%2C%20respectively.%5Cn%5CnFinally%2C%20Capybara%20matchers%20are%20also%20supported%20in%20view%20specs%3A%5Cn%5Cn%60%60%60ruby%5CnRSpec.describe%20%5C%22todos%2Fshow.html.erb%5C%22%2C%20type%3A%20%3Aview%20do%5Cn%20%20it%20%5C%22displays%20the%20todo%20title%5C%22%20do%5Cn%20%20%20%20assign%20%3Atodo%2C%20Todo.new(title%3A%20%5C%22Buy%20milk%5C%22)%5Cn%5Cn%20%20%20%20render%5Cn%5Cn%20%20%20%20expect(rendered).to%20have_css(%5C%22header%20h1%5C%22%2C%20text%3A%20%5C%22Buy%20milk%5C%22)%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn**Note%3A%20When%20you%20require%20'capybara%2Frspec'%20proxy%20methods%20are%20installed%20to%20work%20around%20name%20collisions%20between%20Capybara%3A%3ADSL%20methods%5Cn%20%20%60all%60%2F%60within%60%20and%20the%20identically%20named%20built-in%20RSpec%20matchers.%20If%20you%20opt%20not%20to%20require%20'capybara%2Frspec'%20you%20can%20install%20the%20proxy%20methods%20by%20requiring%20'capybara%2Frspec%2Fmatcher_proxies'%20after%20requiring%20RSpec%20and%20'capybara%2Fdsl'**%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-testunit%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Test%3A%3AUnit%5Cn%5Cn*%20If%20you%20are%20using%20%60Test%3A%3AUnit%60%2C%20define%20a%20base%20class%20for%20your%20Capybara%20tests%5Cn%20%20like%20so%3A%5Cn%5Cn%20%20%20%20%60%60%60ruby%5Cn%20%20%20%20require%20'capybara%2Fdsl'%5Cn%5Cn%20%20%20%20class%20CapybaraTestCase%20%3C%20Test%3A%3AUnit%3A%3ATestCase%5Cn%20%20%20%20%20%20include%20Capybara%3A%3ADSL%5Cn%5Cn%20%20%20%20%20%20def%20teardown%5Cn%20%20%20%20%20%20%20%20Capybara.reset_sessions!%5Cn%20%20%20%20%20%20%20%20Capybara.use_default_driver%5Cn%20%20%20%20%20%20end%5Cn%20%20%20%20end%5Cn%20%20%20%20%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-minitest%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Minitest%5Cn%5Cn*%20If%20you%20are%20using%20Rails%20system%20tests%20please%20see%20their%20documentation%20for%20information%20on%20selecting%20the%20driver%20you%20wish%20to%20use.%5Cn%5Cn*%20If%20you%20are%20using%20Rails%2C%20but%20not%20using%20Rails%20system%20tests%2C%20add%20the%20following%20code%20in%20your%20%60test_helper.rb%60%5Cn%20%20%20%20file%20to%20make%20Capybara%20available%20in%20all%20test%20cases%20deriving%20from%5Cn%20%20%20%20%60ActionDispatch%3A%3AIntegrationTest%60%3A%5Cn%5Cn%20%20%20%20%60%60%60ruby%5Cn%20%20%20%20require%20'capybara%2Frails'%5Cn%20%20%20%20require%20'capybara%2Fminitest'%5Cn%5Cn%20%20%20%20class%20ActionDispatch%3A%3AIntegrationTest%5Cn%20%20%20%20%20%20%23%20Make%20the%20Capybara%20DSL%20available%20in%20all%20integration%20tests%5Cn%20%20%20%20%20%20include%20Capybara%3A%3ADSL%5Cn%20%20%20%20%20%20%23%20Make%20%60assert_*%60%20methods%20behave%20like%20Minitest%20assertions%5Cn%20%20%20%20%20%20include%20Capybara%3A%3AMinitest%3A%3AAssertions%5Cn%5Cn%20%20%20%20%20%20%23%20Reset%20sessions%20and%20driver%20between%20tests%5Cn%20%20%20%20%20%20teardown%20do%5Cn%20%20%20%20%20%20%20%20Capybara.reset_sessions!%5Cn%20%20%20%20%20%20%20%20Capybara.use_default_driver%5Cn%20%20%20%20%20%20end%5Cn%20%20%20%20end%5Cn%20%20%20%20%60%60%60%5Cn%5Cn*%20If%20you%20are%20not%20using%20Rails%2C%20define%20a%20base%20class%20for%20your%20Capybara%20tests%20like%5Cn%20%20so%3A%5Cn%5Cn%20%20%20%20%60%60%60ruby%5Cn%20%20%20%20require%20'capybara%2Fminitest'%5Cn%5Cn%20%20%20%20class%20CapybaraTestCase%20%3C%20Minitest%3A%3ATest%5Cn%20%20%20%20%20%20include%20Capybara%3A%3ADSL%5Cn%20%20%20%20%20%20include%20Capybara%3A%3AMinitest%3A%3AAssertions%5Cn%5Cn%20%20%20%20%20%20def%20teardown%5Cn%20%20%20%20%20%20%20%20Capybara.reset_sessions!%5Cn%20%20%20%20%20%20%20%20Capybara.use_default_driver%5Cn%20%20%20%20%20%20end%5Cn%20%20%20%20end%5Cn%20%20%20%20%60%60%60%5Cn%5Cn%20%20%20%20Remember%20to%20call%20%60super%60%20in%20any%20subclasses%20that%20override%5Cn%20%20%20%20%60teardown%60.%5Cn%5CnTo%20switch%20the%20driver%2C%20set%20%60Capybara.current_driver%60.%20For%20instance%2C%5Cn%5Cn%60%60%60ruby%5Cnclass%20BlogTest%20%3C%20ActionDispatch%3A%3AIntegrationTest%5Cn%20%20setup%20do%5Cn%20%20%20%20Capybara.current_driver%20%3D%20Capybara.javascript_driver%20%23%20%3Aselenium%20by%20default%5Cn%20%20end%5Cn%5Cn%20%20test%20'shows%20blog%20posts'%20do%5Cn%20%20%20%20%23%20...%20this%20test%20is%20run%20with%20Selenium%20...%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-capybara-with-minitestspec%5C%22%3E%3C%2Fa%3EUsing%20Capybara%20with%20Minitest%3A%3ASpec%5Cn%5CnFollow%20the%20above%20instructions%20for%20Minitest%20and%20additionally%20require%20capybara%2Fminitest%2Fspec%5Cn%5Cn%60%60%60ruby%5Cnpage.must_have_content('Important!')%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22drivers%5C%22%3E%3C%2Fa%3EDrivers%5Cn%5CnCapybara%20uses%20the%20same%20DSL%20to%20drive%20a%20variety%20of%20browser%20and%20headless%20drivers.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22selecting-the-driver%5C%22%3E%3C%2Fa%3ESelecting%20the%20Driver%5Cn%5CnBy%20default%2C%20Capybara%20uses%20the%20%60%3Arack_test%60%20driver%2C%20which%20is%20fast%20but%20limited%3A%20it%5Cndoes%20not%20support%20JavaScript%2C%20nor%20is%20it%20able%20to%20access%20HTTP%20resources%20outside%20of%5Cnyour%20Rack%20application%2C%20such%20as%20remote%20APIs%20and%20OAuth%20services.%20To%20get%20around%5Cnthese%20limitations%2C%20you%20can%20set%20up%20a%20different%20default%20driver%20for%20your%20features.%5CnFor%20example%2C%20if%20you'd%20prefer%20to%20run%20everything%20in%20Selenium%2C%20you%20could%20do%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.default_driver%20%3D%20%3Aselenium%20%23%20%3Aselenium_chrome%20and%20%3Aselenium_chrome_headless%20are%20also%20registered%5Cn%60%60%60%5Cn%5CnHowever%2C%20if%20you%20are%20using%20RSpec%20or%20Cucumber%20(and%20your%20app%20runs%20correctly%20without%20JS)%2C%5Cnyou%20may%20instead%20want%20to%20consider%20leaving%20the%20faster%20%60%3Arack_test%60%20as%20the%20__default_driver__%2C%20and%5Cnmarking%20only%20those%20tests%20that%20require%20a%20JavaScript-capable%20driver%20using%20%60js%3A%20true%60%20or%5Cn%60%40javascript%60%2C%20respectively.%20%20By%20default%2C%20JavaScript%20tests%20are%20run%20using%20the%5Cn%60%3Aselenium%60%20driver.%20You%20can%20change%20this%20by%20setting%5Cn%60Capybara.javascript_driver%60.%5Cn%5CnYou%20can%20also%20change%20the%20driver%20temporarily%20(typically%20in%20the%20Before%2Fsetup%20and%5CnAfter%2Fteardown%20blocks)%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.current_driver%20%3D%20%3Aselenium%20%23%20temporarily%20select%20different%20driver%5Cn%23%20tests%20here%5CnCapybara.use_default_driver%20%20%20%20%20%20%20%23%20switch%20back%20to%20default%20driver%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20switching%20the%20driver%20creates%20a%20new%20session%2C%20so%20you%20may%20not%20be%20able%20to%5Cnswitch%20in%20the%20middle%20of%20a%20test.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22racktest%5C%22%3E%3C%2Fa%3ERackTest%5Cn%5CnRackTest%20is%20Capybara's%20default%20driver.%20It%20is%20written%20in%20pure%20Ruby%20and%20does%20not%5Cnhave%20any%20support%20for%20executing%20JavaScript.%20Since%20the%20RackTest%20driver%20interacts%5Cndirectly%20with%20Rack%20interfaces%2C%20it%20does%20not%20require%20a%20server%20to%20be%20started.%5CnHowever%2C%20this%20means%20that%20if%20your%20application%20is%20not%20a%20Rack%20application%20(Rails%2C%5CnSinatra%20and%20most%20other%20Ruby%20frameworks%20are%20Rack%20applications)%20then%20you%20cannot%5Cnuse%20this%20driver.%20Furthermore%2C%20you%20cannot%20use%20the%20RackTest%20driver%20to%20test%20a%5Cnremote%20application%2C%20or%20to%20access%20remote%20URLs%20(e.g.%2C%20redirects%20to%20external%5Cnsites%2C%20external%20APIs%2C%20or%20OAuth%20services)%20that%20your%20application%20might%20interact%5Cnwith.%5Cn%5Cn%5Bcapybara-mechanize%5D(https%3A%2F%2Fgithub.com%2Fjeroenvandijk%2Fcapybara-mechanize)%5Cnprovides%20a%20similar%20driver%20that%20can%20access%20remote%20servers.%5Cn%5CnRackTest%20can%20be%20configured%20with%20a%20set%20of%20headers%20like%20this%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.register_driver%20%3Arack_test%20do%20%7Capp%7C%5Cn%20%20Capybara%3A%3ARackTest%3A%3ADriver.new(app%2C%20headers%3A%20%7B%20'HTTP_USER_AGENT'%20%3D%3E%20'Capybara'%20%7D)%5Cnend%5Cn%60%60%60%5Cn%5CnSee%20the%20section%20on%20adding%20and%20configuring%20drivers.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22selenium%5C%22%3E%3C%2Fa%3ESelenium%5Cn%5CnCapybara%20supports%20%5BSelenium%203.5%2B%5Cn(Webdriver)%5D(https%3A%2F%2Fwww.seleniumhq.org%2Fprojects%2Fwebdriver%2F).%5CnIn%20order%20to%20use%20Selenium%2C%20you'll%20need%20to%20install%20the%20%60selenium-webdriver%60%20gem%2C%5Cnand%20add%20it%20to%20your%20Gemfile%20if%20you're%20using%20bundler.%5Cn%5CnCapybara%20pre-registers%20a%20number%20of%20named%20drivers%20that%20use%20Selenium%20-%20they%20are%3A%5Cn%5Cn%20%20*%20%3Aselenium%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%3E%20Selenium%20driving%20Firefox%5Cn%20%20*%20%3Aselenium_headless%20%20%20%20%20%20%20%20%3D%3E%20Selenium%20driving%20Firefox%20in%20a%20headless%20configuration%5Cn%20%20*%20%3Aselenium_chrome%20%20%20%20%20%20%20%20%20%20%3D%3E%20Selenium%20driving%20Chrome%5Cn%20%20*%20%3Aselenium_chrome_headless%20%3D%3E%20Selenium%20driving%20Chrome%20in%20a%20headless%20configuration%5Cn%5CnThese%20should%20work%20(with%20relevant%20software%20installation)%20in%20a%20local%20desktop%20configuration%20but%20you%20may%5Cnneed%20to%20customize%20them%20if%20using%20in%20a%20CI%20environment%20where%20additional%20options%20may%20need%20to%20be%20passed%5Cnto%20the%20browsers.%20%20See%20the%20section%20on%20adding%20and%20configuring%20drivers.%5Cn%5Cn%5Cn**Note**%3A%20drivers%20which%20run%20the%20server%20in%20a%20different%20thread%20may%20not%20share%20the%5Cnsame%20transaction%20as%20your%20tests%2C%20causing%20data%20not%20to%20be%20shared%20between%20your%20test%5Cnand%20test%20server%2C%20see%20%5BTransactions%20and%20database%20setup%5D(%23transactions-and-database-setup)%20below.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22the-dsl%5C%22%3E%3C%2Fa%3EThe%20DSL%5Cn%5Cn*A%20complete%20reference%20is%20available%20at%5Cn%5Brubydoc.info%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster)*.%5Cn%5Cn**Note%3A%20By%20default%20Capybara%20will%20only%20locate%20visible%20elements.%20This%20is%20because%5Cn%20a%20real%20user%20would%20not%20be%20able%20to%20interact%20with%20non-visible%20elements.**%5Cn%5Cn**Note**%3A%20All%20searches%20in%20Capybara%20are%20*case%20sensitive*.%20This%20is%20because%5CnCapybara%20heavily%20uses%20XPath%2C%20which%20doesn't%20support%20case%20insensitivity.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22navigating%5C%22%3E%3C%2Fa%3ENavigating%5Cn%5CnYou%20can%20use%20the%5Cn%3Ctt%3E%5Bvisit%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23visit-instance_method)%3C%2Ftt%3E%5Cnmethod%20to%20navigate%20to%20other%20pages%3A%5Cn%5Cn%60%60%60ruby%5Cnvisit('%2Fprojects')%5Cnvisit(post_comments_path(post))%5Cn%60%60%60%5Cn%5CnThe%20visit%20method%20only%20takes%20a%20single%20parameter%2C%20the%20request%20method%20is%20**always**%5CnGET.%5Cn%5CnYou%20can%20get%20the%20%5Bcurrent%20path%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23current_path-instance_method)%5Cnof%20the%20browsing%20session%2C%20and%20test%20it%20using%20the%20%5B%60have_current_path%60%5D(http%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FRSpecMatchers%23have_current_path-instance_method)%20matcher%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(page).to%20have_current_path(post_comments_path(post))%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20You%20can%20also%20assert%20the%20current%20path%20by%20testing%20the%20value%20of%5Cn%60current_path%60%20directly.%20However%2C%20using%20the%20%60have_current_path%60%20matcher%20is%5Cnsafer%20since%20it%20uses%20Capybara's%20%5Bwaiting%20behaviour%5D(%23asynchronous-javascript-ajax-and-friends)%5Cnto%20ensure%20that%20preceding%20actions%20(such%20as%20a%20%60click_link%60)%20have%20completed.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22clicking-links-and-buttons%5C%22%3E%3C%2Fa%3EClicking%20links%20and%20buttons%5Cn%5Cn*Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AActions%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FActions)*%5Cn%5CnYou%20can%20interact%20with%20the%20webapp%20by%20following%20links%20and%20buttons.%20Capybara%5Cnautomatically%20follows%20any%20redirects%2C%20and%20submits%20forms%20associated%20with%20buttons.%5Cn%5Cn%60%60%60ruby%5Cnclick_link('id-of-link')%5Cnclick_link('Link%20Text')%5Cnclick_button('Save')%5Cnclick_on('Link%20Text')%20%23%20clicks%20on%20either%20links%20or%20buttons%5Cnclick_on('Button%20Value')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22interacting-with-forms%5C%22%3E%3C%2Fa%3EInteracting%20with%20forms%5Cn%5Cn*Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AActions%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FActions)*%5Cn%5CnThere%20are%20a%20number%20of%20tools%20for%20interacting%20with%20form%20elements%3A%5Cn%5Cn%60%60%60ruby%5Cnfill_in('First%20Name'%2C%20with%3A%20'John')%5Cnfill_in('Password'%2C%20with%3A%20'Seekrit')%5Cnfill_in('Description'%2C%20with%3A%20'Really%20Long%20Text...')%5Cnchoose('A%20Radio%20Button')%5Cncheck('A%20Checkbox')%5Cnuncheck('A%20Checkbox')%5Cnattach_file('Image'%2C%20'%2Fpath%2Fto%2Fimage.jpg')%5Cnselect('Option'%2C%20from%3A%20'Select%20Box')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22querying%5C%22%3E%3C%2Fa%3EQuerying%5Cn%5Cn*Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AMatchers%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FMatchers)*%5Cn%5CnCapybara%20has%20a%20rich%20set%20of%20options%20for%20querying%20the%20page%20for%20the%20existence%20of%5Cncertain%20elements%2C%20and%20working%20with%20and%20manipulating%20those%20elements.%5Cn%5Cn%60%60%60ruby%5Cnpage.has_selector%3F('table%20tr')%5Cnpage.has_selector%3F(%3Axpath%2C%20'.%2F%2Ftable%2Ftr')%5Cn%5Cnpage.has_xpath%3F('.%2F%2Ftable%2Ftr')%5Cnpage.has_css%3F('table%20tr.foo')%5Cnpage.has_content%3F('foo')%5Cn%60%60%60%5Cn%5Cn**Note%3A**%20The%20negative%20forms%20like%20%60has_no_selector%3F%60%20are%20different%20from%20%60not%5Cnhas_selector%3F%60.%20Read%20the%20section%20on%20asynchronous%20JavaScript%20for%20an%20explanation.%5Cn%5CnYou%20can%20use%20these%20with%20RSpec's%20magic%20matchers%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(page).to%20have_selector('table%20tr')%5Cnexpect(page).to%20have_selector(%3Axpath%2C%20'.%2F%2Ftable%2Ftr')%5Cn%5Cnexpect(page).to%20have_xpath('.%2F%2Ftable%2Ftr')%5Cnexpect(page).to%20have_css('table%20tr.foo')%5Cnexpect(page).to%20have_content('foo')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22finding%5C%22%3E%3C%2Fa%3EFinding%5Cn%5Cn_Full%20reference%3A%20%5BCapybara%3A%3ANode%3A%3AFinders%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FNode%2FFinders)_%5Cn%5CnYou%20can%20also%20find%20specific%20elements%2C%20in%20order%20to%20manipulate%20them%3A%5Cn%5Cn%60%60%60ruby%5Cnfind_field('First%20Name').value%5Cnfind_field(id%3A%20'my_field').value%5Cnfind_link('Hello'%2C%20%3Avisible%20%3D%3E%20%3Aall).visible%3F%5Cnfind_link(class%3A%20%5B'some_class'%2C%20'some_other_class'%5D%2C%20%3Avisible%20%3D%3E%20%3Aall).visible%3F%5Cn%5Cnfind_button('Send').click%5Cnfind_button(value%3A%20'1234').click%5Cn%5Cnfind(%3Axpath%2C%20%5C%22.%2F%2Ftable%2Ftr%5C%22).click%5Cnfind(%5C%22%23overlay%5C%22).find(%5C%22h1%5C%22).click%5Cnall('a').each%20%7B%20%7Ca%7C%20a%5B%3Ahref%5D%20%7D%5Cn%60%60%60%5Cn%5CnIf%20you%20need%20to%20find%20elements%20by%20additional%20attributes%2Fproperties%20you%20can%20also%20pass%20a%20filter%20block%2C%20which%20will%20be%20checked%20inside%20the%20normal%20waiting%20behavior.%5CnIf%20you%20find%20yourself%20needing%20to%20use%20this%20a%20lot%20you%20may%20be%20better%20off%20adding%20a%20%5Bcustom%20selector%5D(http%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2FCapybara%23add_selector-class_method)%20or%20%5Badding%20a%20filter%20to%20an%20existing%20selector%5D(http%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2FCapybara%23modify_selector-class_method).%5Cn%5Cn%60%60%60ruby%5Cnfind_field('First%20Name')%7B%20%7Cel%7C%20el%5B'data-xyz'%5D%20%3D%3D%20'123'%20%7D%5Cnfind(%5C%22%23img_loading%5C%22)%7B%20%7Cimg%7C%20img%5B'complete'%5D%20%3D%3D%20true%20%7D%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20%60find%60%20will%20wait%20for%20an%20element%20to%20appear%20on%20the%20page%2C%20as%20explained%20in%20the%5CnAjax%20section.%20If%20the%20element%20does%20not%20appear%20it%20will%20raise%20an%20error.%5Cn%5CnThese%20elements%20all%20have%20all%20the%20Capybara%20DSL%20methods%20available%2C%20so%20you%20can%20restrict%20them%5Cnto%20specific%20parts%20of%20the%20page%3A%5Cn%5Cn%60%60%60ruby%5Cnfind('%23navigation').click_link('Home')%5Cnexpect(find('%23navigation')).to%20have_button('Sign%20out')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22scoping%5C%22%3E%3C%2Fa%3EScoping%5Cn%5CnCapybara%20makes%20it%20possible%20to%20restrict%20certain%20actions%2C%20such%20as%20interacting%20with%5Cnforms%20or%20clicking%20links%20and%20buttons%2C%20to%20within%20a%20specific%20area%20of%20the%20page.%20For%5Cnthis%20purpose%20you%20can%20use%20the%20generic%5Cn%3Ctt%3E%5Bwithin%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23within-instance_method)%3C%2Ftt%3E%5Cnmethod.%20Optionally%20you%20can%20specify%20which%20kind%20of%20selector%20to%20use.%5Cn%5Cn%60%60%60ruby%5Cnwithin(%5C%22li%23employee%5C%22)%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%5Cnwithin(%3Axpath%2C%20%5C%22.%2F%2Fli%5B%40id%3D'employee'%5D%5C%22)%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%60%60%60%5Cn%5CnThere%20are%20special%20methods%20for%20restricting%20the%20scope%20to%20a%20specific%20fieldset%2C%5Cnidentified%20by%20either%20an%20id%20or%20the%20text%20of%20the%20fieldset's%20legend%20tag%2C%20and%20to%20a%5Cnspecific%20table%2C%20identified%20by%20either%20id%20or%20text%20of%20the%20table's%20caption%20tag.%5Cn%5Cn%60%60%60ruby%5Cnwithin_fieldset('Employee')%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%5Cnwithin_table('Employee')%20do%5Cn%20%20fill_in%20'Name'%2C%20with%3A%20'Jimmy'%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22working-with-windows%5C%22%3E%3C%2Fa%3EWorking%20with%20windows%5Cn%5CnCapybara%20provides%20some%20methods%20to%20ease%20finding%20and%20switching%20windows%3A%5Cn%5Cn%60%60%60ruby%5Cnfacebook_window%20%3D%20window_opened_by%20do%5Cn%20%20click_button%20'Like'%5Cnend%5Cnwithin_window%20facebook_window%20do%5Cn%20%20find('%23login_email').set('a%40example.com')%5Cn%20%20find('%23login_password').set('qwerty')%5Cn%20%20click_button%20'Submit'%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22scripting%5C%22%3E%3C%2Fa%3EScripting%5Cn%5CnIn%20drivers%20which%20support%20it%2C%20you%20can%20easily%20execute%20JavaScript%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.execute_script(%5C%22%24('body').empty()%5C%22)%5Cn%60%60%60%5Cn%5CnFor%20simple%20expressions%2C%20you%20can%20return%20the%20result%20of%20the%20script.%5Cn%5Cn%60%60%60ruby%5Cnresult%20%3D%20page.evaluate_script('4%20%2B%204')%3B%5Cn%60%60%60%5Cn%5CnFor%20more%20complicated%20scripts%20you'll%20need%20to%20write%20them%20as%20one%20expression.%5Cn%5Cn%60%60%60ruby%5Cnresult%20%3D%20page.evaluate_script(%3C%3C~JS%2C%203%2C%20element)%5Cn%20%20(function(n%2C%20el)%7B%5Cn%20%20%20%20var%20val%20%3D%20parseInt(el.value%2C%2010)%3B%5Cn%20%20%20%20return%20n%2Bval%3B%5Cn%20%20%7D)(arguments%5B0%5D%2C%20arguments%5B1%5D)%5CnJS%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22modals%5C%22%3E%3C%2Fa%3EModals%5Cn%5CnIn%20drivers%20which%20support%20it%2C%20you%20can%20accept%2C%20dismiss%20and%20respond%20to%20alerts%2C%20confirms%2C%20and%20prompts.%5Cn%5CnYou%20can%20accept%20or%20dismiss%20alert%20messages%20by%20wrapping%20the%20code%20that%20produces%20an%20alert%20in%20a%20block%3A%5Cn%5Cn%60%60%60ruby%5Cnaccept_alert%20do%5Cn%20%20click_link('Show%20Alert')%5Cnend%5Cn%60%60%60%5Cn%5CnYou%20can%20accept%20or%20dismiss%20a%20confirmation%20by%20wrapping%20it%20in%20a%20block%2C%20as%20well%3A%5Cn%5Cn%60%60%60ruby%5Cndismiss_confirm%20do%5Cn%20%20click_link('Show%20Confirm')%5Cnend%5Cn%60%60%60%5Cn%5CnYou%20can%20accept%20or%20dismiss%20prompts%20as%20well%2C%20and%20also%20provide%20text%20to%20fill%20in%20for%20the%20response%3A%5Cn%5Cn%60%60%60ruby%5Cnaccept_prompt(with%3A%20'Linus%20Torvalds')%20do%5Cn%20%20click_link('Show%20Prompt%20About%20Linux')%5Cnend%5Cn%60%60%60%5Cn%5CnAll%20modal%20methods%20return%20the%20message%20that%20was%20presented.%20So%2C%20you%20can%20access%20the%20prompt%20message%5Cnby%20assigning%20the%20return%20to%20a%20variable%3A%5Cn%5Cn%60%60%60ruby%5Cnmessage%20%3D%20accept_prompt(with%3A%20'Linus%20Torvalds')%20do%5Cn%20%20click_link('Show%20Prompt%20About%20Linux')%5Cnend%5Cnexpect(message).to%20eq('Who%20is%20the%20chief%20architect%20of%20Linux%3F')%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22debugging%5C%22%3E%3C%2Fa%3EDebugging%5Cn%5CnIt%20can%20be%20useful%20to%20take%20a%20snapshot%20of%20the%20page%20as%20it%20currently%20is%20and%20take%20a%5Cnlook%20at%20it%3A%5Cn%5Cn%60%60%60ruby%5Cnsave_and_open_page%5Cn%60%60%60%5Cn%5CnYou%20can%20also%20retrieve%20the%20current%20state%20of%20the%20DOM%20as%20a%20string%20using%5Cn%3Ctt%3E%5Bpage.html%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession%23html-instance_method)%3C%2Ftt%3E.%5Cn%5Cn%60%60%60ruby%5Cnprint%20page.html%5Cn%60%60%60%5Cn%5CnThis%20is%20mostly%20useful%20for%20debugging.%20You%20should%20avoid%20testing%20against%20the%5Cncontents%20of%20%60page.html%60%20and%20use%20the%20more%20expressive%20finder%20methods%20instead.%5Cn%5CnFinally%2C%20in%20drivers%20that%20support%20it%2C%20you%20can%20save%20a%20screenshot%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.save_screenshot('screenshot.png')%5Cn%60%60%60%5Cn%5CnOr%20have%20it%20save%20and%20automatically%20open%3A%5Cn%5Cn%60%60%60ruby%5Cnsave_and_open_screenshot%5Cn%60%60%60%5Cn%5CnScreenshots%20are%20saved%20to%20%60Capybara.save_path%60%2C%20relative%20to%20the%20app%20directory.%5CnIf%20you%20have%20required%20%60capybara%2Frails%60%2C%20%60Capybara.save_path%60%20will%20default%20to%5Cn%60tmp%2Fcapybara%60.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22matching%5C%22%3E%3C%2Fa%3EMatching%5Cn%5CnIt%20is%20possible%20to%20customize%20how%20Capybara%20finds%20elements.%20At%20your%20disposal%5Cnare%20two%20options%2C%20%60Capybara.exact%60%20and%20%60Capybara.match%60.%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22exactness%5C%22%3E%3C%2Fa%3EExactness%5Cn%5Cn%60Capybara.exact%60%20and%20the%20%60exact%60%20option%20work%20together%20with%20the%20%60is%60%20expression%5Cninside%20the%20XPath%20gem.%20When%20%60exact%60%20is%20true%2C%20all%20%60is%60%20expressions%20match%20exactly%2C%5Cnwhen%20it%20is%20false%2C%20they%20allow%20substring%20matches.%20Many%20of%20the%20selectors%20built%20into%5CnCapybara%20use%20the%20%60is%60%20expression.%20This%20way%20you%20can%20specify%20whether%20you%20want%20to%5Cnallow%20substring%20matches%20or%20not.%20%60Capybara.exact%60%20is%20false%20by%20default.%5Cn%5CnFor%20example%3A%5Cn%5Cn%60%60%60ruby%5Cnclick_link(%5C%22Password%5C%22)%20%23%20also%20matches%20%5C%22Password%20confirmation%5C%22%5CnCapybara.exact%20%3D%20true%5Cnclick_link(%5C%22Password%5C%22)%20%23%20does%20not%20match%20%5C%22Password%20confirmation%5C%22%5Cnclick_link(%5C%22Password%5C%22%2C%20exact%3A%20false)%20%23%20can%20be%20overridden%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22strategy%5C%22%3E%3C%2Fa%3EStrategy%5Cn%5CnUsing%20%60Capybara.match%60%20and%20the%20equivalent%20%60match%60%20option%2C%20you%20can%20control%20how%5CnCapybara%20behaves%20when%20multiple%20elements%20all%20match%20a%20query.%20There%20are%20currently%5Cnfour%20different%20strategies%20built%20into%20Capybara%3A%5Cn%5Cn1.%20**first%3A**%20Just%20picks%20the%20first%20element%20that%20matches.%5Cn2.%20**one%3A**%20Raises%20an%20error%20if%20more%20than%20one%20element%20matches.%5Cn3.%20**smart%3A**%20If%20%60exact%60%20is%20%60true%60%2C%20raises%20an%20error%20if%20more%20than%20one%20element%5Cn%20%20%20matches%2C%20just%20like%20%60one%60.%20If%20%60exact%60%20is%20%60false%60%2C%20it%20will%20first%20try%20to%20find%5Cn%20%20%20an%20exact%20match.%20An%20error%20is%20raised%20if%20more%20than%20one%20element%20is%20found.%20If%20no%5Cn%20%20%20element%20is%20found%2C%20a%20new%20search%20is%20performed%20which%20allows%20partial%20matches.%20If%5Cn%20%20%20that%20search%20returns%20multiple%20matches%2C%20an%20error%20is%20raised.%5Cn4.%20**prefer_exact%3A**%20If%20multiple%20matches%20are%20found%2C%20some%20of%20which%20are%20exact%2C%5Cn%20%20%20and%20some%20of%20which%20are%20not%2C%20then%20the%20first%20exactly%20matching%20element%20is%5Cn%20%20%20returned.%5Cn%5CnThe%20default%20for%20%60Capybara.match%60%20is%20%60%3Asmart%60.%20To%20emulate%20the%20behaviour%20in%5CnCapybara%202.0.x%2C%20set%20%60Capybara.match%60%20to%20%60%3Aone%60.%20To%20emulate%20the%20behaviour%20in%5CnCapybara%201.x%2C%20set%20%60Capybara.match%60%20to%20%60%3Aprefer_exact%60.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22transactions-and-database-setup%5C%22%3E%3C%2Fa%3ETransactions%20and%20database%20setup%5Cn%5Cn**Note%3A**%20%20Rails%205.1%2B%20%5C%22safely%5C%22%20shares%20the%20database%20connection%20between%20the%20app%20and%20test%20threads.%20%20Therefore%2C%5Cnif%20using%20Rails%205.1%2B%20you%20SHOULD%20be%20able%20to%20ignore%20this%20section.%5Cn%5CnSome%20Capybara%20drivers%20need%20to%20run%20against%20an%20actual%20HTTP%20server.%20Capybara%20takes%5Cncare%20of%20this%20and%20starts%20one%20for%20you%20in%20the%20same%20process%20as%20your%20test%2C%20but%20on%5Cnanother%20thread.%20Selenium%20is%20one%20of%20those%20drivers%2C%20whereas%20RackTest%20is%20not.%5Cn%5CnIf%20you%20are%20using%20a%20SQL%20database%2C%20it%20is%20common%20to%20run%20every%20test%20in%20a%5Cntransaction%2C%20which%20is%20rolled%20back%20at%20the%20end%20of%20the%20test%2C%20rspec-rails%20does%20this%5Cnby%20default%20out%20of%20the%20box%20for%20example.%20Since%20transactions%20are%20usually%20not%5Cnshared%20across%20threads%2C%20this%20will%20cause%20data%20you%20have%20put%20into%20the%20database%20in%5Cnyour%20test%20code%20to%20be%20invisible%20to%20Capybara.%5Cn%5CnCucumber%20handles%20this%20by%20using%20truncation%20instead%20of%20transactions%2C%20i.e.%20they%5Cnempty%20out%20the%20entire%20database%20after%20each%20test.%20You%20can%20get%20the%20same%20behaviour%5Cnby%20using%20a%20gem%20such%20as%20%5Bdatabase_cleaner%5D(https%3A%2F%2Fgithub.com%2FDatabaseCleaner%2Fdatabase_cleaner).%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22asynchronous-javascript-ajax-and-friends%5C%22%3E%3C%2Fa%3EAsynchronous%20JavaScript%20(Ajax%20and%20friends)%5Cn%5CnWhen%20working%20with%20asynchronous%20JavaScript%2C%20you%20might%20come%20across%20situations%5Cnwhere%20you%20are%20attempting%20to%20interact%20with%20an%20element%20which%20is%20not%20yet%20present%5Cnon%20the%20page.%20Capybara%20automatically%20deals%20with%20this%20by%20waiting%20for%20elements%5Cnto%20appear%20on%20the%20page.%5Cn%5CnWhen%20issuing%20instructions%20to%20the%20DSL%20such%20as%3A%5Cn%5Cn%60%60%60ruby%5Cnclick_link('foo')%5Cnclick_link('bar')%5Cnexpect(page).to%20have_content('baz')%5Cn%60%60%60%5Cn%5CnIf%20clicking%20on%20the%20*foo*%20link%20triggers%20an%20asynchronous%20process%2C%20such%20as%5Cnan%20Ajax%20request%2C%20which%2C%20when%20complete%20will%20add%20the%20*bar*%20link%20to%20the%20page%2C%5Cnclicking%20on%20the%20*bar*%20link%20would%20be%20expected%20to%20fail%2C%20since%20that%20link%20doesn't%5Cnexist%20yet.%20However%2C%20Capybara%20is%20smart%20enough%20to%20retry%20finding%20the%20link%20for%20a%5Cnbrief%20period%20of%20time%20before%20giving%20up%20and%20throwing%20an%20error.%20The%20same%20is%20true%20of%5Cnthe%20next%20line%2C%20which%20looks%20for%20the%20content%20*baz*%20on%20the%20page%3B%20it%20will%20retry%5Cnlooking%20for%20that%20content%20for%20a%20brief%20time.%20You%20can%20adjust%20how%20long%20this%20period%5Cnis%20(the%20default%20is%202%20seconds)%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.default_max_wait_time%20%3D%205%5Cn%60%60%60%5Cn%5CnBe%20aware%20that%20because%20of%20this%20behaviour%2C%20the%20following%20two%20statements%20are%20**not**%5Cnequivalent%2C%20and%20you%20should%20**always**%20use%20the%20latter!%5Cn%5Cn%60%60%60ruby%5Cn%23%20Given%20use%20of%20a%20driver%20where%20the%20page%20is%20loaded%20when%20visit%20returns%5Cn%23%20and%20that%20Capybara.predicates_wait%20is%20%60true%60%5Cn%23%20consider%20a%20page%20where%20the%20%60a%60%20tag%20is%20removed%20through%20AJAX%20after%201s%5Cnvisit(some_path)%5Cn!page.has_xpath%3F('a')%20%20%23%20is%20false%5Cnpage.has_no_xpath%3F('a')%20%20%23%20is%20true%5Cn%60%60%60%5Cn%5CnFirst%20expression%3A%5Cn-%20%60has_xpath%3F('a')%60%20is%20called%20right%20after%20%60visit%60%20returns.%20It%20is%20%60true%60%20because%20the%20link%20has%20not%20yet%20been%20removed%5Cn-%20Capybara%20does%20not%20wait%20upon%20successful%20predicates%2Fassertions%2C%20therefore%20**has_xpath%3F%20returns%20%60true%60%20immediately**%5Cn-%20The%20expression%20returns%20%60false%60%20(because%20it%20is%20negated%20with%20the%20leading%20%60!%60)%5Cn%5CnSecond%20expression%3A%5Cn-%20%60has_no_xpath%3F('a')%60%20is%20called%20right%20after%20%60visit%60%20returns.%20It%20is%20%60false%60%20because%20the%20link%20has%20not%20yet%20been%20removed.%5Cn-%20Capybara%20waits%20upon%20failed%20predicates%2Fassertions%2C%20therefore%20**has_no_xpath%3F%20does%20not%20return%20%60false%60%20immediately**%5Cn-%20Capybara%20will%20periodically%20re-check%20the%20predicate%2Fassertion%20up%20to%20the%20%60default_max_wait_time%60%20defined%5Cn-%20after%201s%2C%20the%20predicate%20becomes%20%60true%60%20(because%20the%20link%20has%20been%20removed)%5Cn-%20The%20expression%20returns%20%60true%60%5Cn%5CnCapybara's%20RSpec%20matchers%2C%20however%2C%20are%20smart%20enough%20to%20handle%20either%20form.%5CnThe%20two%20following%20statements%20are%20functionally%20equivalent%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(page).not_to%20have_xpath('a')%5Cnexpect(page).to%20have_no_xpath('a')%5Cn%60%60%60%5Cn%5CnCapybara's%20waiting%20behaviour%20is%20quite%20advanced%2C%20and%20can%20deal%20with%20situations%5Cnsuch%20as%20the%20following%20line%20of%20code%3A%5Cn%5Cn%60%60%60ruby%5Cnexpect(find('%23sidebar').find('h1')).to%20have_content('Something')%5Cn%60%60%60%5Cn%5CnEven%20if%20JavaScript%20causes%20%60%23sidebar%60%20to%20disappear%20off%20the%20page%2C%20Capybara%5Cnwill%20automatically%20reload%20it%20and%20any%20elements%20it%20contains.%20So%20if%20an%20AJAX%5Cnrequest%20causes%20the%20contents%20of%20%60%23sidebar%60%20to%20change%2C%20which%20would%20update%5Cnthe%20text%20of%20the%20%60h1%60%20to%20%5C%22Something%5C%22%2C%20and%20this%20happened%2C%20this%20test%20would%5Cnpass.%20If%20you%20do%20not%20want%20this%20behaviour%2C%20you%20can%20set%5Cn%60Capybara.automatic_reload%60%20to%20%60false%60.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-the-dsl-elsewhere%5C%22%3E%3C%2Fa%3EUsing%20the%20DSL%20elsewhere%5Cn%5CnYou%20can%20mix%20the%20DSL%20into%20any%20context%20by%20including%20%3Ctt%3ECapybara%3A%3ADSL%3C%2Ftt%3E%3A%5Cn%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara%2Fdsl'%5Cn%5CnCapybara.default_driver%20%3D%20%3Awebkit%5Cn%5Cnmodule%20MyModule%5Cn%20%20include%20Capybara%3A%3ADSL%5Cn%5Cn%20%20def%20login!%5Cn%20%20%20%20within(%3Axpath%2C%20%5C%22.%2F%2Fform%5B%40id%3D'session'%5D%5C%22)%20do%5Cn%20%20%20%20%20%20fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20%20%20%20%20fill_in%20'Password'%2C%20with%3A%20'password'%5Cn%20%20%20%20end%5Cn%20%20%20%20click_button%20'Sign%20in'%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5CnThis%20enables%20its%20use%20in%20unsupported%20testing%20frameworks%2C%20and%20for%20general-purpose%20scripting.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22calling-remote-servers%5C%22%3E%3C%2Fa%3ECalling%20remote%20servers%5Cn%5CnNormally%20Capybara%20expects%20to%20be%20testing%20an%20in-process%20Rack%20application%2C%20but%20you%5Cncan%20also%20use%20it%20to%20talk%20to%20a%20web%20server%20running%20anywhere%20on%20the%20internet%2C%20by%5Cnsetting%20app_host%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.current_driver%20%3D%20%3Aselenium%5CnCapybara.app_host%20%3D%20'http%3A%2F%2Fwww.google.com'%5Cn...%5Cnvisit('%2F')%5Cn%60%60%60%5Cn%5Cn**Note**%3A%20the%20default%20driver%20(%60%3Arack_test%60)%20does%20not%20support%20running%5Cnagainst%20a%20remote%20server.%20With%20drivers%20that%20support%20it%2C%20you%20can%20also%20visit%20any%5CnURL%20directly%3A%5Cn%5Cn%60%60%60ruby%5Cnvisit('http%3A%2F%2Fwww.google.com')%5Cn%60%60%60%5Cn%5CnBy%20default%20Capybara%20will%20try%20to%20boot%20a%20rack%20application%20automatically.%20You%5Cnmight%20want%20to%20switch%20off%20Capybara's%20rack%20server%20if%20you%20are%20running%20against%20a%5Cnremote%20application%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.run_server%20%3D%20false%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22using-sessions%5C%22%3E%3C%2Fa%3EUsing%20sessions%5Cn%5CnCapybara%20manages%20named%20sessions%20(%3Adefault%20if%20not%20specified)%20allowing%20multiple%20sessions%20using%20the%20same%20driver%20and%20test%20app%20instance%20to%20be%20interacted%20with.%5CnA%20new%20session%20will%20be%20created%20using%20the%20current%20driver%20if%20a%20session%20with%20the%20given%20name%20using%20the%20current%20driver%20and%20test%20app%20instance%20is%20not%20found.%5Cn%5Cn%23%23%23%20Named%20sessions%5CnTo%20perform%20operations%20in%20a%20different%20session%20and%20then%20revert%20to%20the%20previous%20session%5Cn%5Cn%60%60%60ruby%5CnCapybara.using_session(%5C%22Bob's%20session%5C%22)%20do%5Cn%20%20%20%23do%20something%20in%20Bob's%20browser%20session%5Cnend%5Cn%20%23reverts%20to%20previous%20session%5Cn%60%60%60%5Cn%5CnTo%20permanently%20switch%20the%20current%20session%20to%20a%20different%20session%5Cn%5Cn%60%60%60ruby%5CnCapybara.session_name%20%3D%20%5C%22some%20other%20session%5C%22%5Cn%60%60%60%5Cn%5Cn%23%23%23%20%3Ca%20name%3D%5C%22using-sessions-manually%5C%22%3E%3C%2Fa%3EUsing%20sessions%20manually%5Cn%5CnFor%20ultimate%20control%2C%20you%20can%20instantiate%20and%20use%20a%5Cn%5BSession%5D(http%3A%2F%2Frubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2Fmaster%2FCapybara%2FSession)%5Cnmanually.%5Cn%5Cn%60%60%60ruby%5Cnrequire%20'capybara'%5Cn%5Cnsession%20%3D%20Capybara%3A%3ASession.new(%3Awebkit%2C%20my_rack_app)%5Cnsession.within(%5C%22form%23session%5C%22)%20do%5Cn%20%20session.fill_in%20'Email'%2C%20with%3A%20'user%40example.com'%5Cn%20%20session.fill_in%20'Password'%2C%20with%3A%20'password'%5Cnend%5Cnsession.click_button%20'Sign%20in'%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22xpath-css-and-selectors%5C%22%3E%3C%2Fa%3EXPath%2C%20CSS%20and%20selectors%5Cn%5CnCapybara%20does%20not%20try%20to%20guess%20what%20kind%20of%20selector%20you%20are%20going%20to%20give%20it%2C%5Cnand%20will%20always%20use%20CSS%20by%20default.%20%20If%20you%20want%20to%20use%20XPath%2C%20you'll%20need%20to%5Cndo%3A%5Cn%5Cn%60%60%60ruby%5Cnwithin(%3Axpath%2C%20'.%2F%2Ful%2Fli')%20%7B%20...%20%7D%5Cnfind(%3Axpath%2C%20'.%2F%2Ful%2Fli').text%5Cnfind(%3Axpath%2C%20'.%2F%2Fli%5Bcontains(.%2F%2Fa%5B%40href%20%3D%20%5C%22%23%5C%22%5D%2Ftext()%2C%20%5C%22foo%5C%22)%5D').value%5Cn%60%60%60%5Cn%5CnAlternatively%20you%20can%20set%20the%20default%20selector%20to%20XPath%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.default_selector%20%3D%20%3Axpath%5Cnfind('.%2F%2Ful%2Fli').text%5Cn%60%60%60%5Cn%5CnCapybara%20provides%20a%20number%20of%20other%20built-in%20selector%20types.%20The%20full%20list%2C%20along%5Cnwith%20applicable%20filters%2C%20can%20be%20seen%20at%20%5Bbuilt-in%20selectors%5D(https%3A%2F%2Fwww.rubydoc.info%2Fgithub%2Fteamcapybara%2Fcapybara%2FCapybara%2FSelector)%5Cn%5CnCapybara%20also%20allows%20you%20to%20add%20custom%20selectors%2C%20which%20can%20be%20very%20useful%20if%20you%5Cnfind%20yourself%20using%20the%20same%20kinds%20of%20selectors%20very%20often.%20The%20examples%20below%20are%20very%5Cnsimple%2C%20and%20there%20are%20many%20available%20features%20not%20demonstrated.%20For%20more%20in-depth%20examples%5Cnplease%20see%20Capybaras%20built-in%20selector%20definitions.%5Cn%5Cn%60%60%60ruby%5CnCapybara.add_selector(%3Amy_attribute)%20do%5Cn%20%20xpath%20%7B%20%7Cid%7C%20XPath.descendant%5BXPath.attr(%3Amy_attribute)%20%3D%3D%20id.to_s%5D%20%7D%5Cnend%5Cn%5CnCapybara.add_selector(%3Arow)%20do%5Cn%20%20xpath%20%7B%20%7Cnum%7C%20%5C%22.%2F%2Ftbody%2Ftr%5B%23%7Bnum%7D%5D%5C%22%20%7D%5Cnend%5Cn%5CnCapybara.add_selector(%3Aflash_type)%20do%5Cn%20%20css%20%7B%20%7Ctype%7C%20%5C%22%23flash.%23%7Btype%7D%5C%22%20%7D%5Cnend%5Cn%60%60%60%5Cn%5CnThe%20block%20given%20to%20xpath%20must%20always%20return%20an%20XPath%20expression%20as%20a%20String%2C%20or%5Cnan%20XPath%20expression%20generated%20through%20the%20XPath%20gem.%20You%20can%20now%20use%20these%5Cnselectors%20like%20this%3A%5Cn%5Cn%60%60%60ruby%5Cnfind(%3Amy_attribute%2C%20'post_123')%20%23%20find%20element%20with%20matching%20attribute%5Cnfind(%3Arow%2C%203)%20%23%20find%203rd%20row%20in%20table%20body%5Cnfind(%3Aflash_type%2C%20%3Anotice)%20%23%20find%20element%20with%20id%20of%20'flash'%20and%20class%20of%20'notice'%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22beware-the-xpath--trap%5C%22%3E%3C%2Fa%3EBeware%20the%20XPath%20%2F%2F%20trap%5Cn%5CnIn%20XPath%20the%20expression%20%2F%2F%20means%20something%20very%20specific%2C%20and%20it%20might%20not%20be%20what%5Cnyou%20think.%20Contrary%20to%20common%20belief%2C%20%2F%2F%20means%20%5C%22anywhere%20in%20the%20document%5C%22%20not%20%5C%22anywhere%5Cnin%20the%20current%20context%5C%22.%20As%20an%20example%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.find(%3Axpath%2C%20'%2F%2Fbody').all(%3Axpath%2C%20'%2F%2Fscript')%5Cn%60%60%60%5Cn%5CnYou%20might%20expect%20this%20to%20find%20all%20script%20tags%20in%20the%20body%2C%20but%20actually%2C%20it%20finds%20all%5Cnscript%20tags%20in%20the%20entire%20document%2C%20not%20only%20those%20in%20the%20body!%20What%20you're%20looking%5Cnfor%20is%20the%20.%2F%2F%20expression%20which%20means%20%5C%22any%20descendant%20of%20the%20current%20node%5C%22%3A%5Cn%5Cn%60%60%60ruby%5Cnpage.find(%3Axpath%2C%20'%2F%2Fbody').all(%3Axpath%2C%20'.%2F%2Fscript')%5Cn%60%60%60%5CnThe%20same%20thing%20goes%20for%20within%3A%5Cn%5Cn%60%60%60ruby%5Cnwithin(%3Axpath%2C%20'%2F%2Fbody')%20do%5Cn%20%20page.find(%3Axpath%2C%20'.%2F%2Fscript')%5Cn%20%20within(%3Axpath%2C%20'.%2F%2Ftable%2Ftbody')%20do%5Cn%20%20...%5Cn%20%20end%5Cnend%5Cn%60%60%60%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22configuring-and-adding-drivers%5C%22%3E%3C%2Fa%3EConfiguring%20and%20adding%20drivers%5Cn%5CnCapybara%20makes%20it%20convenient%20to%20switch%20between%20different%20drivers.%20It%20also%20exposes%5Cnan%20API%20to%20tweak%20those%20drivers%20with%20whatever%20settings%20you%20want%2C%20or%20to%20add%20your%20own%5Cndrivers.%20This%20is%20how%20to%20override%20the%20selenium%20driver%20configuration%20to%20use%20chrome%3A%5Cn%5Cn%60%60%60ruby%5CnCapybara.register_driver%20%3Aselenium%20do%20%7Capp%7C%5Cn%20%20Capybara%3A%3ASelenium%3A%3ADriver.new(app%2C%20%3Abrowser%20%3D%3E%20%3Achrome)%5Cnend%5Cn%60%60%60%5Cn%5CnHowever%2C%20it's%20also%20possible%20to%20give%20this%20configuration%20a%20different%20name.%5Cn%5Cn%60%60%60ruby%5Cn%23%20Note%3A%20Capybara%20registers%20this%20by%20default%5CnCapybara.register_driver%20%3Aselenium_chrome%20do%20%7Capp%7C%5Cn%20%20Capybara%3A%3ASelenium%3A%3ADriver.new(app%2C%20%3Abrowser%20%3D%3E%20%3Achrome)%5Cnend%5Cn%60%60%60%5Cn%5CnThen%20tests%20can%20switch%20between%20using%20different%20browsers%20effortlessly%3A%5Cn%60%60%60ruby%5CnCapybara.current_driver%20%3D%20%3Aselenium_chrome%5Cn%60%60%60%5Cn%5CnWhatever%20is%20returned%20from%20the%20block%20should%20conform%20to%20the%20API%20described%20by%5CnCapybara%3A%3ADriver%3A%3ABase%2C%20it%20does%20not%20however%20have%20to%20inherit%20from%20this%20class.%5CnGems%20can%20use%20this%20API%20to%20add%20their%20own%20drivers%20to%20Capybara.%5Cn%5CnThe%20%5BSelenium%20wiki%5D(https%3A%2F%2Fgithub.com%2FSeleniumHQ%2Fselenium%2Fwiki%2FRuby-Bindings)%20has%5Cnadditional%20info%20about%20how%20the%20underlying%20driver%20can%20be%20configured.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22gotchas%5C%22%3E%3C%2Fa%3EGotchas%3A%5Cn%5Cn*%20Access%20to%20session%20and%20request%20is%20not%20possible%20from%20the%20test%2C%20Access%20to%5Cn%20%20response%20is%20limited.%20Some%20drivers%20allow%20access%20to%20response%20headers%20and%20HTTP%5Cn%20%20status%20code%2C%20but%20this%20kind%20of%20functionality%20is%20not%20provided%20by%20some%20drivers%2C%5Cn%20%20such%20as%20Selenium.%5Cn%5Cn*%20Access%20to%20Rails%20specific%20stuff%20(such%20as%20%60controller%60)%20is%20unavailable%2C%5Cn%20%20since%20we're%20not%20using%20Rails'%20integration%20testing.%5Cn%5Cn*%20Freezing%20time%3A%20It's%20common%20practice%20to%20mock%20out%20the%20Time%20so%20that%20features%5Cn%20%20that%20depend%20on%20the%20current%20Date%20work%20as%20expected.%20This%20can%20be%20problematic%20on%5Cn%20%20ruby%2Fplatform%20combinations%20that%20don't%20support%20access%20to%20a%20monotonic%20process%20clock%2C%5Cn%20%20since%20Capybara's%20Ajax%20timing%20uses%20the%20system%20time%2C%20resulting%20in%20Capybara%5Cn%20%20never%20timing%20out%20and%20just%20hanging%20when%20a%20failure%20occurs.%20It's%20still%20possible%20to%5Cn%20%20use%20gems%20which%20allow%20you%20to%20travel%20in%20time%2C%20rather%20than%20freeze%20time.%5Cn%20%20One%20such%20gem%20is%20%5BTimecop%5D(https%3A%2F%2Fgithub.com%2Ftravisjeffery%2Ftimecop).%5Cn%5Cn*%20When%20using%20Rack%3A%3ATest%2C%20beware%20if%20attempting%20to%20visit%20absolute%20URLs.%20For%5Cn%20%20example%2C%20a%20session%20might%20not%20be%20shared%20between%20visits%20to%20%60posts_path%60%5Cn%20%20and%20%60posts_url%60.%20If%20testing%20an%20absolute%20URL%20in%20an%20Action%20Mailer%20email%2C%5Cn%20%20set%20%60default_url_options%60%20to%20match%20the%20Rails%20default%20of%5Cn%20%20%60www.example.com%60.%5Cn%5Cn*%20Server%20errors%20will%20only%20be%20raised%20in%20the%20session%20that%20initiates%20the%20server%20thread.%20If%20you%5Cn%20%20are%20testing%20for%20specific%20server%20errors%20and%20using%20multiple%20sessions%20make%20sure%20to%20test%20for%20the%5Cn%20%20errors%20using%20the%20initial%20session%20(usually%20%3Adefault)%5Cn%5Cn*%20If%20WebMock%20is%20enabled%2C%20you%20may%20encounter%20a%20%5C%22Too%20many%20open%20files%5C%22%5Cn%20%20error.%20A%20simple%20%60page.find%60%20call%20may%20cause%20thousands%20of%20HTTP%20requests%5Cn%20%20until%20the%20timeout%20occurs.%20By%20default%2C%20WebMock%20will%20cause%20each%20of%20these%5Cn%20%20requests%20to%20spawn%20a%20new%20connection.%20To%20work%20around%20this%20problem%2C%20you%5Cn%20%20may%20need%20to%20%5Benable%20WebMock's%20%60net_http_connect_on_start%3A%20true%60%5Cn%20%20parameter%5D(https%3A%2F%2Fgithub.com%2Fbblimke%2Fwebmock%2Fblob%2Fmaster%2FREADME.md%23connecting-on-nethttpstart).%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22threadsafe%5C%22%3E%3C%2Fa%3E%5C%22Threadsafe%5C%22%20mode%5Cn%5CnIn%20normal%20mode%20most%20of%20Capybara's%20configuration%20options%20are%20global%20settings%20which%20can%20cause%20issues%5Cnif%20using%20multiple%20sessions%20and%20wanting%20to%20change%20a%20setting%20for%20only%20one%20of%20the%20sessions.%20%20To%20provide%5Cnsupport%20for%20this%20type%20of%20usage%20Capybara%20now%20provides%20a%20%5C%22threadsafe%5C%22%20mode%20which%20can%20be%20enabled%20by%20setting%5Cn%5Cn%60%60%60ruby%5CnCapybara.threadsafe%20%3D%20true%5Cn%60%60%60%5Cn%5CnThis%20setting%20can%20only%20be%20changed%20before%20any%20sessions%20have%20been%20created.%20%20In%20%5C%22threadsafe%5C%22%20mode%20the%20following%5Cnbehaviors%20of%20Capybara%20change%5Cn%5Cn*%20Most%20options%20can%20now%20be%20set%20on%20a%20session.%20%20These%20can%20either%20be%20set%20at%20session%20creation%20time%20or%20after%2C%20and%5Cn%20%20default%20to%20the%20global%20options%20at%20the%20time%20of%20session%20creation.%20%20Options%20which%20are%20NOT%20session%20specific%20are%5Cn%20%20%60app%60%2C%20%60reuse_server%60%2C%20%60default_driver%60%2C%20%60javascript_driver%60%2C%20and%20(obviously)%20%60threadsafe%60.%20%20Any%20drivers%20and%20servers%5Cn%20%20registered%20through%20%60register_driver%60%20and%20%60register_server%60%20are%20also%20global.%5Cn%5Cn%20%20%60%60%60ruby%5Cn%20%20my_session%20%3D%20Capybara%3A%3ASession.new(%3Adriver%2C%20some_app)%20do%20%7Cconfig%7C%5Cn%20%20%20%20config.automatic_label_click%20%3D%20true%20%23%20only%20set%20for%20my_session%5Cn%20%20end%5Cn%20%20my_session.config.default_max_wait_time%20%3D%2010%20%23%20only%20set%20for%20my_session%5Cn%20%20Capybara.default_max_wait_time%20%3D%202%20%23%20will%20not%20change%20the%20default_max_wait%20in%20my_session%5Cn%20%20%60%60%60%5Cn%5Cn*%20%60current_driver%60%20and%20%60session_name%60%20are%20thread%20specific.%20%20This%20means%20that%20%60using_session%60%20and%5Cn%20%20%60using_driver%60%20also%20only%20affect%20the%20current%20thread.%5Cn%5Cn%23%23%20%3Ca%20name%3D%5C%22development%5C%22%3E%3C%2Fa%3EDevelopment%5Cn%5CnTo%20set%20up%20a%20development%20environment%2C%20simply%20do%3A%5Cn%5Cn%60%60%60bash%5Cnbundle%20install%5Cnbundle%20exec%20rake%20%20%23%20run%20the%20test%20suite%20with%20Firefox%20-%20requires%20%60geckodriver%60%20to%20be%20installed%5Cnbundle%20exec%20rake%20spec_chrome%20%23%20run%20the%20test%20suite%20with%20Chrome%20-%20require%20%60chromedriver%60%20to%20be%20installed%5Cn%60%60%60%5Cn%5CnSee%5Cn%5BCONTRIBUTING.md%5D(https%3A%2F%2Fgithub.com%2Fteamcapybara%2Fcapybara%2Fblob%2Fmaster%2FCONTRIBUTING.md)%5Cnfor%20how%20to%20send%20issues%20and%20pull%20requests.%5Cn%22%7D"},"zoneReducer":{"zoneDetail":"","newsDetail":""}}
Capybara
Capybara helps you test web applications by simulating how a real user would interact with your app. It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in. WebKit is supported through an external gem.
Support Capybara
If you and/or your company find value in Capybara and would like to contribute financially to its ongoing maintenance and development, please visit Patreon
Need help? Ask on the discussions (please do not open an issue): https://github.com/orgs/teamcapybara/discussions/categories/q-a
Table of contents
Key benefits
Setup
Capybara requires Ruby 3.0.0 or later. To install, add this line to your
Gemfile
and runbundle install
:If the application that you are testing is a Rails app, add this line to your test helper file:
If the application that you are testing is a Rack app, but not Rails, set Capybara.app to your Rack app:
If you need to test JavaScript, or if your app interacts with (or is located at) a remote URL, you’ll need to use a different driver. If using Rails 5.0+, but not using the Rails system tests from 5.1, you’ll probably also want to swap the “server” used to launch your app to Puma in order to match Rails defaults.
Using Capybara with Cucumber
The
cucumber-rails
gem comes with Capybara support built-in. If you are not using Rails, manually load thecapybara/cucumber
module:You can use the Capybara DSL in your steps, like so:
You can switch to the
Capybara.javascript_driver
(:selenium
by default) by tagging scenarios (or features) with@javascript
:There are also explicit tags for each registered driver set up for you (
@selenium
,@rack_test
, etc).Using Capybara with RSpec
Load RSpec 3.5+ support by adding the following line (typically to your
spec_helper.rb
file):If you are using Rails, put your Capybara specs in
spec/features
orspec/system
(only works if you have it configured in RSpec) and if you have your Capybara specs in a different directory, then tag the example groups withtype: :feature
ortype: :system
depending on which type of test you’re writing.If you are using Rails system specs please see their documentation for selecting the driver you wish to use.
If you are not using Rails, tag all the example groups in which you want to use Capybara with
type: :feature
.You can now write your specs like so:
Use
js: true
to switch to theCapybara.javascript_driver
(:selenium
by default), or provide a:driver
option to switch to one specific driver. For example:Capybara also comes with a built in DSL for creating descriptive acceptance tests:
feature
is in fact just an alias fordescribe ..., type: :feature
,background
is an alias forbefore
,scenario
forit
, andgiven
/given!
aliases forlet
/let!
, respectively.Finally, Capybara matchers are also supported in view specs:
Note: When you require ‘capybara/rspec’ proxy methods are installed to work around name collisions between Capybara::DSL methods
all
/within
and the identically named built-in RSpec matchers. If you opt not to require ‘capybara/rspec’ you can install the proxy methods by requiring ‘capybara/rspec/matcher_proxies’ after requiring RSpec and ‘capybara/dsl’Using Capybara with Test::Unit
If you are using
Test::Unit
, define a base class for your Capybara tests like so:Using Capybara with Minitest
If you are using Rails system tests please see their documentation for information on selecting the driver you wish to use.
If you are using Rails, but not using Rails system tests, add the following code in your
test_helper.rb
file to make Capybara available in all test cases deriving fromActionDispatch::IntegrationTest
:If you are not using Rails, define a base class for your Capybara tests like so:
Remember to call
super
in any subclasses that overrideteardown
.To switch the driver, set
Capybara.current_driver
. For instance,Using Capybara with Minitest::Spec
Follow the above instructions for Minitest and additionally require capybara/minitest/spec
Drivers
Capybara uses the same DSL to drive a variety of browser and headless drivers.
Selecting the Driver
By default, Capybara uses the
:rack_test
driver, which is fast but limited: it does not support JavaScript, nor is it able to access HTTP resources outside of your Rack application, such as remote APIs and OAuth services. To get around these limitations, you can set up a different default driver for your features. For example, if you’d prefer to run everything in Selenium, you could do:However, if you are using RSpec or Cucumber (and your app runs correctly without JS), you may instead want to consider leaving the faster
:rack_test
as the default_driver, and marking only those tests that require a JavaScript-capable driver usingjs: true
or@javascript
, respectively. By default, JavaScript tests are run using the:selenium
driver. You can change this by settingCapybara.javascript_driver
.You can also change the driver temporarily (typically in the Before/setup and After/teardown blocks):
Note: switching the driver creates a new session, so you may not be able to switch in the middle of a test.
RackTest
RackTest is Capybara’s default driver. It is written in pure Ruby and does not have any support for executing JavaScript. Since the RackTest driver interacts directly with Rack interfaces, it does not require a server to be started. However, this means that if your application is not a Rack application (Rails, Sinatra and most other Ruby frameworks are Rack applications) then you cannot use this driver. Furthermore, you cannot use the RackTest driver to test a remote application, or to access remote URLs (e.g., redirects to external sites, external APIs, or OAuth services) that your application might interact with.
capybara-mechanize provides a similar driver that can access remote servers.
RackTest can be configured with a set of headers like this:
See the section on adding and configuring drivers.
Selenium
Capybara supports Selenium 3.5+ (Webdriver). In order to use Selenium, you’ll need to install the
selenium-webdriver
gem, and add it to your Gemfile if you’re using bundler.Capybara pre-registers a number of named drivers that use Selenium - they are:
These should work (with relevant software installation) in a local desktop configuration but you may need to customize them if using in a CI environment where additional options may need to be passed to the browsers. See the section on adding and configuring drivers.
Note: drivers which run the server in a different thread may not share the same transaction as your tests, causing data not to be shared between your test and test server, see Transactions and database setup below.
The DSL
A complete reference is available at rubydoc.info.
Note: By default Capybara will only locate visible elements. This is because a real user would not be able to interact with non-visible elements.
Note: All searches in Capybara are case sensitive. This is because Capybara heavily uses XPath, which doesn’t support case insensitivity.
Navigating
You can use the visit method to navigate to other pages:
The visit method only takes a single parameter, the request method is always GET.
You can get the current path of the browsing session, and test it using the
have_current_path
matcher:Note: You can also assert the current path by testing the value of
current_path
directly. However, using thehave_current_path
matcher is safer since it uses Capybara’s waiting behaviour to ensure that preceding actions (such as aclick_link
) have completed.Clicking links and buttons
Full reference: Capybara::Node::Actions
You can interact with the webapp by following links and buttons. Capybara automatically follows any redirects, and submits forms associated with buttons.
Interacting with forms
Full reference: Capybara::Node::Actions
There are a number of tools for interacting with form elements:
Querying
Full reference: Capybara::Node::Matchers
Capybara has a rich set of options for querying the page for the existence of certain elements, and working with and manipulating those elements.
Note: The negative forms like
has_no_selector?
are different fromnot has_selector?
. Read the section on asynchronous JavaScript for an explanation.You can use these with RSpec’s magic matchers:
Finding
Full reference: Capybara::Node::Finders
You can also find specific elements, in order to manipulate them:
If you need to find elements by additional attributes/properties you can also pass a filter block, which will be checked inside the normal waiting behavior. If you find yourself needing to use this a lot you may be better off adding a custom selector or adding a filter to an existing selector.
Note:
find
will wait for an element to appear on the page, as explained in the Ajax section. If the element does not appear it will raise an error.These elements all have all the Capybara DSL methods available, so you can restrict them to specific parts of the page:
Scoping
Capybara makes it possible to restrict certain actions, such as interacting with forms or clicking links and buttons, to within a specific area of the page. For this purpose you can use the generic within method. Optionally you can specify which kind of selector to use.
There are special methods for restricting the scope to a specific fieldset, identified by either an id or the text of the fieldset’s legend tag, and to a specific table, identified by either id or text of the table’s caption tag.
Working with windows
Capybara provides some methods to ease finding and switching windows:
Scripting
In drivers which support it, you can easily execute JavaScript:
For simple expressions, you can return the result of the script.
For more complicated scripts you’ll need to write them as one expression.
Modals
In drivers which support it, you can accept, dismiss and respond to alerts, confirms, and prompts.
You can accept or dismiss alert messages by wrapping the code that produces an alert in a block:
You can accept or dismiss a confirmation by wrapping it in a block, as well:
You can accept or dismiss prompts as well, and also provide text to fill in for the response:
All modal methods return the message that was presented. So, you can access the prompt message by assigning the return to a variable:
Debugging
It can be useful to take a snapshot of the page as it currently is and take a look at it:
You can also retrieve the current state of the DOM as a string using page.html.
This is mostly useful for debugging. You should avoid testing against the contents of
page.html
and use the more expressive finder methods instead.Finally, in drivers that support it, you can save a screenshot:
Or have it save and automatically open:
Screenshots are saved to
Capybara.save_path
, relative to the app directory. If you have requiredcapybara/rails
,Capybara.save_path
will default totmp/capybara
.Matching
It is possible to customize how Capybara finds elements. At your disposal are two options,
Capybara.exact
andCapybara.match
.Exactness
Capybara.exact
and theexact
option work together with theis
expression inside the XPath gem. Whenexact
is true, allis
expressions match exactly, when it is false, they allow substring matches. Many of the selectors built into Capybara use theis
expression. This way you can specify whether you want to allow substring matches or not.Capybara.exact
is false by default.For example:
Strategy
Using
Capybara.match
and the equivalentmatch
option, you can control how Capybara behaves when multiple elements all match a query. There are currently four different strategies built into Capybara:exact
istrue
, raises an error if more than one element matches, just likeone
. Ifexact
isfalse
, it will first try to find an exact match. An error is raised if more than one element is found. If no element is found, a new search is performed which allows partial matches. If that search returns multiple matches, an error is raised.The default for
Capybara.match
is:smart
. To emulate the behaviour in Capybara 2.0.x, setCapybara.match
to:one
. To emulate the behaviour in Capybara 1.x, setCapybara.match
to:prefer_exact
.Transactions and database setup
Note: Rails 5.1+ “safely” shares the database connection between the app and test threads. Therefore, if using Rails 5.1+ you SHOULD be able to ignore this section.
Some Capybara drivers need to run against an actual HTTP server. Capybara takes care of this and starts one for you in the same process as your test, but on another thread. Selenium is one of those drivers, whereas RackTest is not.
If you are using a SQL database, it is common to run every test in a transaction, which is rolled back at the end of the test, rspec-rails does this by default out of the box for example. Since transactions are usually not shared across threads, this will cause data you have put into the database in your test code to be invisible to Capybara.
Cucumber handles this by using truncation instead of transactions, i.e. they empty out the entire database after each test. You can get the same behaviour by using a gem such as database_cleaner.
Asynchronous JavaScript (Ajax and friends)
When working with asynchronous JavaScript, you might come across situations where you are attempting to interact with an element which is not yet present on the page. Capybara automatically deals with this by waiting for elements to appear on the page.
When issuing instructions to the DSL such as:
If clicking on the foo link triggers an asynchronous process, such as an Ajax request, which, when complete will add the bar link to the page, clicking on the bar link would be expected to fail, since that link doesn’t exist yet. However, Capybara is smart enough to retry finding the link for a brief period of time before giving up and throwing an error. The same is true of the next line, which looks for the content baz on the page; it will retry looking for that content for a brief time. You can adjust how long this period is (the default is 2 seconds):
Be aware that because of this behaviour, the following two statements are not equivalent, and you should always use the latter!
First expression:
has_xpath?('a')
is called right aftervisit
returns. It istrue
because the link has not yet been removedtrue
immediatelyfalse
(because it is negated with the leading!
)Second expression:
has_no_xpath?('a')
is called right aftervisit
returns. It isfalse
because the link has not yet been removed.false
immediatelydefault_max_wait_time
definedtrue
(because the link has been removed)true
Capybara’s RSpec matchers, however, are smart enough to handle either form. The two following statements are functionally equivalent:
Capybara’s waiting behaviour is quite advanced, and can deal with situations such as the following line of code:
Even if JavaScript causes
#sidebar
to disappear off the page, Capybara will automatically reload it and any elements it contains. So if an AJAX request causes the contents of#sidebar
to change, which would update the text of theh1
to “Something”, and this happened, this test would pass. If you do not want this behaviour, you can setCapybara.automatic_reload
tofalse
.Using the DSL elsewhere
You can mix the DSL into any context by including Capybara::DSL:
This enables its use in unsupported testing frameworks, and for general-purpose scripting.
Calling remote servers
Normally Capybara expects to be testing an in-process Rack application, but you can also use it to talk to a web server running anywhere on the internet, by setting app_host:
Note: the default driver (
:rack_test
) does not support running against a remote server. With drivers that support it, you can also visit any URL directly:By default Capybara will try to boot a rack application automatically. You might want to switch off Capybara’s rack server if you are running against a remote application:
Using sessions
Capybara manages named sessions (:default if not specified) allowing multiple sessions using the same driver and test app instance to be interacted with. A new session will be created using the current driver if a session with the given name using the current driver and test app instance is not found.
Named sessions
To perform operations in a different session and then revert to the previous session
To permanently switch the current session to a different session
Using sessions manually
For ultimate control, you can instantiate and use a Session manually.
XPath, CSS and selectors
Capybara does not try to guess what kind of selector you are going to give it, and will always use CSS by default. If you want to use XPath, you’ll need to do:
Alternatively you can set the default selector to XPath:
Capybara provides a number of other built-in selector types. The full list, along with applicable filters, can be seen at built-in selectors
Capybara also allows you to add custom selectors, which can be very useful if you find yourself using the same kinds of selectors very often. The examples below are very simple, and there are many available features not demonstrated. For more in-depth examples please see Capybaras built-in selector definitions.
The block given to xpath must always return an XPath expression as a String, or an XPath expression generated through the XPath gem. You can now use these selectors like this:
Beware the XPath // trap
In XPath the expression // means something very specific, and it might not be what you think. Contrary to common belief, // means “anywhere in the document” not “anywhere in the current context”. As an example:
You might expect this to find all script tags in the body, but actually, it finds all script tags in the entire document, not only those in the body! What you’re looking for is the .// expression which means “any descendant of the current node”:
The same thing goes for within:
Configuring and adding drivers
Capybara makes it convenient to switch between different drivers. It also exposes an API to tweak those drivers with whatever settings you want, or to add your own drivers. This is how to override the selenium driver configuration to use chrome:
However, it’s also possible to give this configuration a different name.
Then tests can switch between using different browsers effortlessly:
Whatever is returned from the block should conform to the API described by Capybara::Driver::Base, it does not however have to inherit from this class. Gems can use this API to add their own drivers to Capybara.
The Selenium wiki has additional info about how the underlying driver can be configured.
Gotchas:
Access to session and request is not possible from the test, Access to response is limited. Some drivers allow access to response headers and HTTP status code, but this kind of functionality is not provided by some drivers, such as Selenium.
Access to Rails specific stuff (such as
controller
) is unavailable, since we’re not using Rails’ integration testing.Freezing time: It’s common practice to mock out the Time so that features that depend on the current Date work as expected. This can be problematic on ruby/platform combinations that don’t support access to a monotonic process clock, since Capybara’s Ajax timing uses the system time, resulting in Capybara never timing out and just hanging when a failure occurs. It’s still possible to use gems which allow you to travel in time, rather than freeze time. One such gem is Timecop.
When using Rack::Test, beware if attempting to visit absolute URLs. For example, a session might not be shared between visits to
posts_path
andposts_url
. If testing an absolute URL in an Action Mailer email, setdefault_url_options
to match the Rails default ofwww.example.com
.Server errors will only be raised in the session that initiates the server thread. If you are testing for specific server errors and using multiple sessions make sure to test for the errors using the initial session (usually :default)
If WebMock is enabled, you may encounter a “Too many open files” error. A simple
page.find
call may cause thousands of HTTP requests until the timeout occurs. By default, WebMock will cause each of these requests to spawn a new connection. To work around this problem, you may need to enable WebMock’snet_http_connect_on_start: true
parameter.“Threadsafe” mode
In normal mode most of Capybara’s configuration options are global settings which can cause issues if using multiple sessions and wanting to change a setting for only one of the sessions. To provide support for this type of usage Capybara now provides a “threadsafe” mode which can be enabled by setting
This setting can only be changed before any sessions have been created. In “threadsafe” mode the following behaviors of Capybara change
Most options can now be set on a session. These can either be set at session creation time or after, and default to the global options at the time of session creation. Options which are NOT session specific are
app
,reuse_server
,default_driver
,javascript_driver
, and (obviously)threadsafe
. Any drivers and servers registered throughregister_driver
andregister_server
are also global.current_driver
andsession_name
are thread specific. This means thatusing_session
andusing_driver
also only affect the current thread.Development
To set up a development environment, simply do:
See CONTRIBUTING.md for how to send issues and pull requests.