Skip to content

Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt
Notifications You must be signed in to change notification settings

r4do/capybara_select2

 
 

Repository files navigation

CapybaraSelect2 for select2 version 2/3/4

!!! CapybaraSelect2 detects select2 version automatically

Build Status Maintainability Test Coverage

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'capybara-select-2'
end

And then execute:

$ bundle

Or install it yourself as:

$ gem install capybara-select-2

[Note] In the projects which use RSpec or Cucumber select2 helper is available out of the box

Manual installation with Rspec

In your spec_helper.rb

RSpec.configure do |config|
  config.include CapybaraSelect2
end

Manual installation with Cucumber

In your env.rb

World CapybaraSelect2

Usage

Select from a node containing select2 control

  • Identified by CSS selector
select2 'Buy Milk', css: '#todo'
  • Identified by XPath selector
select2 'Buy Milk', xpath: '//div[@id="todo"]'

Select from select2 control identified by label

select2 'Buy Milk', from: 'Things to do'

If you want to search for an option (via Ajax for example)

select2 'Buy Milk', from: 'Things to do', search: true

Dynamically create an option from search input

select2 'Millennials', from: 'Generations', tag: true

Select several options at once

select2 'Buy Milk', 'Go to gym', css: '#todo'

Add match strategy in case of ambiguous results

select2 'Buy Milk', from: 'Things to do', search: true, match: :first

Contributing

  1. Add a test case which covers the bug
  2. Add code which makes the test green
  3. Open pull request

License

The gem is available as open source under the terms of the MIT License.

About

Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.3%
  • Shell 0.7%