Incrementing test project with Capybara. Although Capybara is not required to automate ui tests, it has a great DSL that might boost our experience scripting automate tests.
- Same basic steps from the
ruby-rspec-selenium
Project until theWriting first test script
Step - Add
gem 'capybara', '~> 3.29'
to the Gemfile - Run
bundle install
command to install all your gems - Add
require 'capybara/rspec'
andconfig.include Capybara::DSL
to thespec_helper.rb
file - Add basic Browser configurations through
Capybara.configure do |config|
Capybara.configure do |config|
config.default_driver = :selenium #Firefox default driver, it's also possible to use :selenium_chrome and :selenium_chrome_headless
config.default_max_wait_time = 5 #implicit wait
config.app_host = "http://the-internet.herokuapp.com"
end
- Navigation is done using
visit "<URL>"
- Actions:
fill_in [locator], with: "value"
: locator can be the name, id, test_id attribute, placeholder, or label textclick_on [locator]
orclick_button [locator]
choose [locator]
check [locator]
select "Option", from: [locator]
- Finders:
find
find_link
find_button
- Querying:
page.has_selector?('table tr')
page.has_selector?(:xpath, './/table/tr')
page.has_xpath?('.//table/tr')
page.has_css?('table tr.foo')
page.has_content?('foo')