Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/doamaral/ruby-rspec-selenium-capybara

Trying out basic setup and features for UI testing using Capybara
https://github.com/doamaral/ruby-rspec-selenium-capybara

capybara rspec ruby selenium

Last synced: 19 days ago
JSON representation

Trying out basic setup and features for UI testing using Capybara

Awesome Lists containing this project

README

        

# 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](https://github.com/doamaral/ruby-rspec-selenium) 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|`

```ruby
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](https://www.rubydoc.info/github/jnicklas/capybara/Capybara.configure)

## Using Capybara's DSL

[capybara cheat sheet](https://gist.github.com/zhengjia/428105)

- Navigation is done using `visit ""`
- [Actions](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/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](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders):
- `find`
- `find_link`
- `find_button`
- [Querying](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Matchers):
- `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')`