Capybara is a powerful Ruby library for automating control of browsers.
Capybara has a robust internal wait system that can be used to efficiently wait for certain page elements to appear before continuing. You should never need to write a flaky
sleep call with Capybara.
expect(page).to have_css('#new-project') expect(page).to have_content('New Project')
This will efficiently wait for the
#new-project element to exist.
You can use Capybara's generic
has_xpath? methods to make sure that the page state is correct before continuing on. You probably will want to raise an exception to stop execution if the query for the element returns false.
raise 'element missing!' unless page.has_css?('#new-project') raise 'element missing!' unless page.has_content?('New Project')
Updated about 3 years ago