doamaral / ruby-rspec-selenium-capybara

Trying out basic setup and features for UI testing using Capybara

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ruby-rspec-selenium-capybara

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.

Initial project structure

  • Same basic steps from the ruby-rspec-selenium Project until the Writing 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' and config.include Capybara::DSL to the spec_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

Obs: More possible configs

Using Capybara's DSL

capybara cheat sheet

  • Navigation is done using visit "<URL>"
  • Actions:
    • fill_in [locator], with: "value": locator can be the name, id, test_id attribute, placeholder, or label text
    • click_on [locator] or click_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')

About

Trying out basic setup and features for UI testing using Capybara


Languages

Language:Ruby 100.0%