capybara-select-2 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitlab-ci.yml +19 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -18
- data/README.md +9 -0
- data/capybara_select2.gemspec +4 -4
- data/ci/install-chrome +11 -0
- data/ci/install-chromedriver +23 -0
- data/lib/capybara_select2.rb +1 -0
- data/lib/capybara_select2/helpers.rb +10 -38
- data/lib/capybara_select2/rspec/matchers.rb +20 -0
- data/lib/capybara_select2/selectors.rb +38 -0
- data/lib/capybara_select2/utils.rb +18 -0
- data/lib/capybara_select2/version.rb +1 -1
- metadata +22 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 01f1574cc4400755884d066349b52d23174b5b61634c9baff7e5332e83687654
|
4
|
+
data.tar.gz: 5614b845dc929345d9463b7e9de2fdebe483071b5423ff5b0a376add3ac08e5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ebe35a60da59411376f3e473d479fde65b05bd1186caef104b8745564fc5afbe21815bd1f0504a83cb1ba3bd15ae4ead119d4182af5978be9341f5b1591cc61
|
7
|
+
data.tar.gz: 0cd9d2747b433bbdefd1ad926dbddb35f0790ae10a48206666dc43441a3ab3fd3d7afb03ca2816062972c1c3a6e37dcf1a4ed6858dab95ddefa56f045153f235
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
image: ruby:2.4.3
|
2
|
+
|
3
|
+
variables:
|
4
|
+
MIN_CHROMEDRIVER_VER: '2.44'
|
5
|
+
MIN_CHROME_VER: '70'
|
6
|
+
TMPDIR: '/tmp'
|
7
|
+
|
8
|
+
before_script:
|
9
|
+
- echo $HOME
|
10
|
+
- chmod +x ./ci/install-chromedriver && ./ci/install-chromedriver
|
11
|
+
- chmod +x ./ci/install-chrome && ./ci/install-chrome
|
12
|
+
- echo $PATH
|
13
|
+
- echo `which chromedriver`
|
14
|
+
- gem install bundler --no-ri --no-rdoc
|
15
|
+
- bundle install
|
16
|
+
|
17
|
+
test:
|
18
|
+
script:
|
19
|
+
- rspec spec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/.travis.yml
CHANGED
@@ -2,30 +2,19 @@ sudo: required
|
|
2
2
|
dist: trusty
|
3
3
|
language: ruby
|
4
4
|
rvm:
|
5
|
-
- 2.4.
|
6
|
-
before_install: gem install bundler -v
|
5
|
+
- 2.4.1
|
6
|
+
before_install: gem install bundler -v 2.0.1
|
7
7
|
env:
|
8
8
|
global:
|
9
|
-
- MOZ_HEADLESS=1
|
10
9
|
- CC_TEST_REPORTER_ID=e82aca58fe4e7eae020799b830f8df7dd35ec67f7476078d4fe97ae884be8f84
|
11
|
-
- GECKODRIVER_VERSION=0.21.0
|
12
10
|
addons:
|
13
|
-
|
14
|
-
apt:
|
15
|
-
sources:
|
16
|
-
- ubuntu-sdk-team
|
17
|
-
packages:
|
18
|
-
- libqt5webkit5-dev
|
19
|
-
- qtdeclarative5-dev
|
20
|
-
before_install:
|
21
|
-
- wget https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER_VERSION/geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz
|
22
|
-
- mkdir geckodriver
|
23
|
-
- tar -xzf geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz -C geckodriver
|
24
|
-
- export PATH=$PATH:$PWD/geckodriver
|
11
|
+
chrome: stable
|
25
12
|
before_script:
|
26
13
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
27
|
-
- chmod +x ./cc-test-reporter
|
28
|
-
-
|
14
|
+
- chmod +x ./cc-test-reporter && ./cc-test-reporter before-build
|
15
|
+
- # start your web application and listen on `localhost`
|
16
|
+
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
|
17
|
+
|
29
18
|
script: COVERAGE=1 xvfb-run bundle exec rspec
|
30
19
|
after_script:
|
31
20
|
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/README.md
CHANGED
@@ -77,6 +77,15 @@ select2 'Millennials', from: 'Generations', tag: true
|
|
77
77
|
select2 'Buy Milk', 'Go to gym', css: '#todo'
|
78
78
|
```
|
79
79
|
|
80
|
+
### Add match strategy in case of ambiguous results
|
81
|
+
```ruby
|
82
|
+
select2 'Buy Milk', from: 'Things to do', search: true, match: :first
|
83
|
+
```
|
84
|
+
|
85
|
+
### Check for select2 option on the page
|
86
|
+
```ruby
|
87
|
+
expect(page).to have_select2_option('Buy Milk')
|
88
|
+
```
|
80
89
|
## Contributing
|
81
90
|
|
82
91
|
1. Add a test case which covers the bug
|
data/capybara_select2.gemspec
CHANGED
@@ -26,13 +26,13 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler", "~>
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
-
spec.add_development_dependency "capybara", "~> 3.
|
33
|
-
spec.add_development_dependency "
|
32
|
+
spec.add_development_dependency "capybara", "~> 3.12"
|
33
|
+
spec.add_development_dependency "chromedriver-helper", "~> 2.1"
|
34
|
+
spec.add_development_dependency "selenium-webdriver", "~> 3.141.0"
|
34
35
|
spec.add_development_dependency "capybara-screenshot" , "~> 1.0"
|
35
|
-
spec.add_development_dependency "capybara-webkit", "~> 1.15"
|
36
36
|
spec.add_development_dependency "puma", "~> 3.12"
|
37
37
|
spec.add_development_dependency "pry", "~> 0.11.0"
|
38
38
|
spec.add_development_dependency "simplecov", "~> 0.16"
|
data/ci/install-chrome
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -xe
|
4
|
+
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
|
5
|
+
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
|
6
|
+
|
7
|
+
# Update packages
|
8
|
+
apt-get update -yqqq
|
9
|
+
|
10
|
+
# Install Chrome browser
|
11
|
+
apt-get install -y google-chrome-stable
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -xe
|
4
|
+
|
5
|
+
# Update packages
|
6
|
+
apt-get update -yqqq
|
7
|
+
|
8
|
+
# Install Chrome browser
|
9
|
+
apt-get install -y unzip
|
10
|
+
|
11
|
+
# Install/use specific version of chrome if an installed version is lower
|
12
|
+
install_chromedriver() {
|
13
|
+
wget -O $TMPDIR/chromedriver.zip https://chromedriver.storage.googleapis.com/${MIN_CHROMEDRIVER_VER}/chromedriver_linux64.zip
|
14
|
+
mkdir -p $HOME/.chromedriver
|
15
|
+
(cd $HOME/.chromedriver && unzip $TMPDIR/chromedriver.zip && chmod +x chromedriver)
|
16
|
+
rm -f $TMPDIR/chromedriver.zip
|
17
|
+
ln -s $HOME/.chromedriver/chromedriver /usr/local/bin/chromedriver
|
18
|
+
}
|
19
|
+
if ! which chromedriver; then
|
20
|
+
install_chromedriver
|
21
|
+
elif dpkg --compare-versions `chromedriver --version | cut -d " " -f2` lt $MIN_CHROMEDRIVER_VER; then
|
22
|
+
install_chromedriver
|
23
|
+
fi
|
data/lib/capybara_select2.rb
CHANGED
@@ -9,51 +9,23 @@ module CapybaraSelect2
|
|
9
9
|
|
10
10
|
Utils.validate_options!(options)
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
elsif options[:css]
|
15
|
-
find(:css, options[:css])
|
16
|
-
else
|
17
|
-
find("label:not(.select2-offscreen)", text: options[:from])
|
18
|
-
.find(:xpath, '..')
|
19
|
-
.find('.select2-container')
|
20
|
-
end
|
21
|
-
|
22
|
-
container = if container['class'] =~ /select2-container/
|
23
|
-
container
|
24
|
-
else
|
25
|
-
container.find('.select2-container')
|
26
|
-
end
|
27
|
-
|
28
|
-
select2_version = Utils.detect_select2_version(container)
|
29
|
-
|
30
|
-
open_select = {
|
31
|
-
'2' => ".select2-choice, .select2-search-field",
|
32
|
-
'3' => ".select2-choice, .select2-search-field",
|
33
|
-
'4' => ".select2-selection"
|
34
|
-
}.fetch(select2_version)
|
35
|
-
|
36
|
-
search_input = {
|
37
|
-
'2' => ".select2-dropdown-open input.select2-focused",
|
38
|
-
'3' => ".select2-drop-active input.select2-input," + # single
|
39
|
-
".select2-dropdown-open input.select2-input", # multi
|
40
|
-
'4' => ".select2-container--open input.select2-search__field"
|
41
|
-
}.fetch(select2_version)
|
12
|
+
select2_container = Utils.find_select2_container(options, page)
|
13
|
+
select2_version = Utils.detect_select2_version(select2_container)
|
42
14
|
|
43
|
-
|
44
|
-
|
45
|
-
'3' => ".select2-drop-active .select2-result",
|
46
|
-
'4' => ".select2-results .select2-results__option[role='treeitem']"
|
47
|
-
}.fetch(select2_version)
|
15
|
+
opener_selector = Selectors.opener_selector(select2_version)
|
16
|
+
option_selector = Selectors.option_selector(select2_version)
|
48
17
|
|
49
18
|
values.each do |value|
|
50
|
-
|
19
|
+
select2_container.find(:css, opener_selector).click
|
51
20
|
|
52
21
|
if options[:search] || options[:tag]
|
53
|
-
|
22
|
+
search_input_selector = Selectors.search_input_selector(select2_version)
|
23
|
+
find(:xpath, '//body').find(:css, search_input_selector).set value
|
54
24
|
end
|
55
25
|
|
56
|
-
|
26
|
+
find_options = { text: value }
|
27
|
+
find_options[:match] = options[:match] if options[:match]
|
28
|
+
find(:xpath, '//body').find(:css, option_selector, find_options).click
|
57
29
|
end
|
58
30
|
end
|
59
31
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
require 'capybara_select2/selectors'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :have_select2_option do |expected|
|
5
|
+
def option_matcher(element)
|
6
|
+
select2_container = element.find('.select2-container', match: :first)
|
7
|
+
|
8
|
+
select2_version = CapybaraSelect2::Utils.detect_select2_version(select2_container)
|
9
|
+
|
10
|
+
CapybaraSelect2::Selectors.option_selector(select2_version)
|
11
|
+
end
|
12
|
+
|
13
|
+
match do |element|
|
14
|
+
expect(element).to have_css option_matcher(element), text: expected
|
15
|
+
end
|
16
|
+
|
17
|
+
match_when_negated do |element|
|
18
|
+
expect(element).not_to have_css option_matcher(element), text: expected
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CapybaraSelect2
|
2
|
+
module Selectors
|
3
|
+
|
4
|
+
module_function
|
5
|
+
|
6
|
+
OpenerSelectors = {
|
7
|
+
'2' => ".select2-choice, .select2-search-field",
|
8
|
+
'3' => ".select2-choice, .select2-search-field",
|
9
|
+
'4' => ".select2-selection"
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
def opener_selector(select2_version)
|
13
|
+
OpenerSelectors.fetch(select2_version)
|
14
|
+
end
|
15
|
+
|
16
|
+
SearchInputSelectors = {
|
17
|
+
'2' => ".select2-dropdown-open input.select2-focused",
|
18
|
+
'3' => ".select2-drop-active input.select2-input," + # single
|
19
|
+
".select2-dropdown-open input.select2-input", # multi
|
20
|
+
'4' => ".select2-container--open input.select2-search__field"
|
21
|
+
}.freeze
|
22
|
+
|
23
|
+
def search_input_selector(select2_version)
|
24
|
+
SearchInputSelectors.fetch(select2_version)
|
25
|
+
end
|
26
|
+
|
27
|
+
OptionSelectors = {
|
28
|
+
'2' => ".select2-container-active .select2-result",
|
29
|
+
'3' => ".select2-drop-active .select2-result",
|
30
|
+
'4' => ".select2-results .select2-results__option[role='treeitem']"
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
def option_selector(select2_version)
|
34
|
+
OptionSelectors.fetch(select2_version)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -17,5 +17,23 @@ module CapybaraSelect2
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.find_select2_container(options, page)
|
21
|
+
container = if options[:xpath]
|
22
|
+
page.find(:xpath, options[:xpath])
|
23
|
+
elsif options[:css]
|
24
|
+
page.find(:css, options[:css])
|
25
|
+
else
|
26
|
+
page.find(:css, "label:not(.select2-offscreen)", text: options[:from])
|
27
|
+
.find(:xpath, '..')
|
28
|
+
.find(:css, '.select2-container')
|
29
|
+
end
|
30
|
+
|
31
|
+
if container['class'] =~ /select2-container/
|
32
|
+
container
|
33
|
+
else
|
34
|
+
container.find(:css, '.select2-container')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
20
38
|
end
|
21
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-select-2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Kavalionak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,56 +58,56 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.12'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.12'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: chromedriver-helper
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '2.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '2.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: selenium-webdriver
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.141.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.141.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: capybara-
|
98
|
+
name: capybara-screenshot
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1.
|
103
|
+
version: '1.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '1.
|
110
|
+
version: '1.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: puma
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,7 +158,9 @@ extensions: []
|
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
160
|
- ".gitignore"
|
161
|
+
- ".gitlab-ci.yml"
|
161
162
|
- ".rspec"
|
163
|
+
- ".ruby-version"
|
162
164
|
- ".travis.yml"
|
163
165
|
- Gemfile
|
164
166
|
- LICENSE
|
@@ -168,9 +170,13 @@ files:
|
|
168
170
|
- bin/console
|
169
171
|
- bin/setup
|
170
172
|
- capybara_select2.gemspec
|
173
|
+
- ci/install-chrome
|
174
|
+
- ci/install-chromedriver
|
171
175
|
- lib/capybara-select-2.rb
|
172
176
|
- lib/capybara_select2.rb
|
173
177
|
- lib/capybara_select2/helpers.rb
|
178
|
+
- lib/capybara_select2/rspec/matchers.rb
|
179
|
+
- lib/capybara_select2/selectors.rb
|
174
180
|
- lib/capybara_select2/utils.rb
|
175
181
|
- lib/capybara_select2/version.rb
|
176
182
|
homepage: https://github.com/Hirurg103/capybara_select2
|
@@ -193,8 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
199
|
- !ruby/object:Gem::Version
|
194
200
|
version: '0'
|
195
201
|
requirements: []
|
196
|
-
|
197
|
-
rubygems_version: 2.6.14
|
202
|
+
rubygems_version: 3.0.2
|
198
203
|
signing_key:
|
199
204
|
specification_version: 4
|
200
205
|
summary: Capybara helpers for https://select2.org select box (supports Select2 versions
|