capybara-select-2 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +57 -21
- data/lib/capybara_select2.rb +5 -4
- data/lib/capybara_select2/helpers.rb +11 -22
- data/lib/capybara_select2/utils.rb +12 -0
- data/lib/capybara_select2/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a699d3e0d5eec84d768a123c94ba5480793e43
|
4
|
+
data.tar.gz: da4ddebbf20ea31461c6fb5be32b3ef3d7a3e6b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc85290a29be0951fa40e6a763ce2f526c59cb6d4c7e438f1e82c7a1a1ed25826464d783774b9b8142f108d8615b6f56e7ca5c5584f42ba594bc9d6683c80040
|
7
|
+
data.tar.gz: 7c8324a51abda2745c5d1ce3f9ba0c88407801805f959b6890b41898fe8fa0eedd941ec44ce1685ccc08c971c3042ca156e67d8dcb512224c015181649ff6c20
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -59,14 +59,47 @@ World CapybaraSelect2::Helpers # if need specific helpers
|
|
59
59
|
### Examples
|
60
60
|
|
61
61
|
```ruby
|
62
|
+
select2 'Buy Milk', from: 'Todo'
|
62
63
|
select2 'Buy Milk', css: '#todo'
|
63
64
|
select2 'Buy Milk', xpath: '//div[@id="todo"]'
|
64
|
-
|
65
|
-
|
65
|
+
```
|
66
|
+
|
67
|
+
#### Selecting two or more options
|
66
68
|
|
67
|
-
|
68
|
-
select2 'Buy Milk',
|
69
|
-
|
69
|
+
```ruby
|
70
|
+
select2 'Buy Milk', 'Go to gym', from: 'Todo'
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Searching
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
select2 'Buy Milk', from: 'Todo', search: true
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Searching by text different than an option text
|
80
|
+
|
81
|
+
```
|
82
|
+
select2 'Buy Milk', from: 'Todo', search: 'Buy'
|
83
|
+
```
|
84
|
+
|
85
|
+
#### Tagging
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
select2 'Go to gym', from: 'Todo', tag: true
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Resolving ambiguous match
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
# Select the first matching option if there are two or more options with text 'Buy'
|
95
|
+
select2 'Buy', from: 'Todo', match: :first
|
96
|
+
```
|
97
|
+
|
98
|
+
#### Selecting an option by exact text
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# Select 'Eat' if there are two or more options with text 'Eat' ('Eat', 'Eat salad')
|
102
|
+
select2 'Eat', from: 'Todo', exact_text: true
|
70
103
|
```
|
71
104
|
|
72
105
|
[Note] CSS and XPath selectors must identify an HTML node that wraps select2 element or a select2 element itself (an HTML element with the `.select2-container` class)
|
@@ -75,17 +108,18 @@ select2 'Millennials', from: 'Generation', tag: true
|
|
75
108
|
|
76
109
|
Option | Purpose
|
77
110
|
:------|:-------
|
78
|
-
css | Identify select2 element by a CSS selector
|
79
|
-
xpath | Identify select2 element by an XPath selector
|
80
|
-
from | Identify select2 element by a label
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
111
|
+
`css` | Identify select2 element by a CSS selector
|
112
|
+
`xpath` | Identify select2 element by an XPath selector
|
113
|
+
`from` | Identify select2 element by a label
|
114
|
+
`label` | Identify select2 element by a label
|
115
|
+
`search` | Search for an option by the passed string. Search by an option text if `true` is passed
|
116
|
+
`tag` | Create an option
|
117
|
+
`match` | Specifies Capybara's [matching strategy](https://github.com/teamcapybara/capybara#strategy) when selecting an option
|
118
|
+
`exact_text` | Whether an option text must match exactly
|
85
119
|
|
86
120
|
### Helpers
|
87
121
|
|
88
|
-
Specific select2 helpers that allow more refined access to select2 control
|
122
|
+
Specific select2 helpers that allow more refined access to a select2 control
|
89
123
|
|
90
124
|
```ruby
|
91
125
|
select2_open label: 'Todo'
|
@@ -95,15 +129,17 @@ select2_select 'Buy Milk', from: 'Todo'
|
|
95
129
|
select2_clear xpath: "//div[@id='todo']"
|
96
130
|
```
|
97
131
|
|
98
|
-
Helper | Purpose
|
99
|
-
|
100
|
-
select2_open | Open select2 control
|
101
|
-
select2_close | Close select2 control
|
102
|
-
select2_search | Type into a select2 search field
|
103
|
-
select2_select | Select an option from an opened select2 control
|
104
|
-
select2_clear | Remove selected options (for multi select only)
|
132
|
+
Helper | Purpose | Options
|
133
|
+
:------|:--------|:-------
|
134
|
+
`select2_open(options)` | Open select2 control | `label`, `css`, `xpath`
|
135
|
+
`select2_close` | Close select2 control | -
|
136
|
+
`select2_search(term, options)` | Type into a select2 search field | `label`, `from`, `css`, `xpath`
|
137
|
+
`select2_select(value, options)` | Select an option from an opened select2 control | `label`, `from`, `css`, `xpath`, `match`, `exact_text`
|
138
|
+
`select2_clear(options)` | Remove selected options (for multi select only) | `label`, `from`, `css`, `xpath`
|
139
|
+
|
140
|
+
See description for each option in the [Options](https://github.com/Hirurg103/capybara_select2#options) section
|
105
141
|
|
106
|
-
[
|
142
|
+
[Note] Helpers above are not available in tests by default. To use them include `CapybaraSelect2::Helpers` in your test invironment (see [Configuration section](https://github.com/Hirurg103/capybara_select2#configuration))
|
107
143
|
|
108
144
|
### RSpec matchers
|
109
145
|
|
data/lib/capybara_select2.rb
CHANGED
@@ -12,17 +12,18 @@ module CapybaraSelect2
|
|
12
12
|
|
13
13
|
container = Utils.find_select2_container(options, page)
|
14
14
|
version = Utils.detect_select2_version(container)
|
15
|
-
|
15
|
+
options_with_select2_details =
|
16
|
+
options.merge({ container: container, version: version, page: page })
|
16
17
|
|
17
18
|
values.each do |value|
|
18
|
-
Helpers.select2_open(
|
19
|
+
Helpers.select2_open(options_with_select2_details)
|
19
20
|
|
20
21
|
if options[:search] || options[:tag]
|
21
22
|
term = options[:search].is_a?(String) ? options[:search] : value
|
22
|
-
Helpers.select2_search(term,
|
23
|
+
Helpers.select2_search(term, options_with_select2_details)
|
23
24
|
end
|
24
25
|
|
25
|
-
Helpers.select2_select(value,
|
26
|
+
Helpers.select2_select(value, options_with_select2_details)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -6,13 +6,10 @@ module CapybaraSelect2
|
|
6
6
|
module_function
|
7
7
|
|
8
8
|
def select2_open(options)
|
9
|
-
options = options
|
10
|
-
options[:from] ||= options[:label]
|
9
|
+
options = Utils.set_option_aliases(options)
|
11
10
|
Utils.validate_options!(options)
|
12
11
|
|
13
|
-
|
14
|
-
container = options[:container] || Utils.find_select2_container(options, _page)
|
15
|
-
version = options[:version] || Utils.detect_select2_version(container)
|
12
|
+
_, container, version = Utils.get_page_container_and_version(options, self)
|
16
13
|
opener_selector = Selectors.opener_selector(version)
|
17
14
|
|
18
15
|
container.find(:css, opener_selector).click
|
@@ -23,40 +20,32 @@ module CapybaraSelect2
|
|
23
20
|
end
|
24
21
|
|
25
22
|
def select2_search(text, options)
|
26
|
-
options = options
|
27
|
-
options[:from] ||= options[:label]
|
23
|
+
options = Utils.set_option_aliases(options)
|
28
24
|
Utils.validate_options!(options)
|
29
25
|
|
30
|
-
|
31
|
-
container = options[:container] || Utils.find_select2_container(options, _page)
|
32
|
-
version = options[:version] || Utils.detect_select2_version(container)
|
26
|
+
page, _, version = Utils.get_page_container_and_version(options, self)
|
33
27
|
search_input_selector = Selectors.search_input_selector(version)
|
34
28
|
|
35
|
-
|
29
|
+
page.find(:xpath, '//body').find(:css, search_input_selector).set text
|
36
30
|
end
|
37
31
|
|
38
32
|
def select2_select(value, options)
|
39
33
|
Utils.validate_options!(options)
|
40
34
|
|
41
|
-
|
42
|
-
container = options[:container] || Utils.find_select2_container(options, _page)
|
43
|
-
version = options[:version] || Utils.detect_select2_version(container)
|
35
|
+
page, _, version = Utils.get_page_container_and_version(options, self)
|
44
36
|
option_selector = Selectors.option_selector(version)
|
45
37
|
|
46
|
-
find_options = {
|
47
|
-
find_options
|
48
|
-
find_options[:exact_text] = options[:exact_text] if options[:exact_text]
|
38
|
+
find_options = options.select { |k, _| [:match, :exact_text].include?(k) }
|
39
|
+
find_options = find_options.merge(text: value)
|
49
40
|
|
50
|
-
|
41
|
+
page.find(:xpath, '//body').find(:css, option_selector, **find_options).click
|
51
42
|
end
|
52
43
|
|
53
44
|
def select2_clear(options)
|
54
|
-
options = options
|
55
|
-
options[:from] ||= options[:label]
|
45
|
+
options = Utils.set_option_aliases(options)
|
56
46
|
Utils.validate_options!(options)
|
57
47
|
|
58
|
-
container = Utils.
|
59
|
-
version = Utils.detect_select2_version(container)
|
48
|
+
_, container, version = Utils.get_page_container_and_version(options, self)
|
60
49
|
remove_option_selector = Selectors.remove_option_selector(version)
|
61
50
|
|
62
51
|
container.all(remove_option_selector).map(&:click)
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module CapybaraSelect2
|
2
2
|
module Utils
|
3
3
|
|
4
|
+
def self.set_option_aliases(options)
|
5
|
+
options.dup.tap { |o| o[:from] ||= o[:label] }
|
6
|
+
end
|
7
|
+
|
4
8
|
def self.detect_select2_version(container)
|
5
9
|
if container['class'] =~ /^select2\s/
|
6
10
|
'4'
|
@@ -35,5 +39,13 @@ module CapybaraSelect2
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
42
|
+
def self.get_page_container_and_version(options, context)
|
43
|
+
page = options[:page] || context.page
|
44
|
+
container = options[:container] || find_select2_container(options, page)
|
45
|
+
version = options[:version] || detect_select2_version(container)
|
46
|
+
|
47
|
+
[page, container, version]
|
48
|
+
end
|
49
|
+
|
38
50
|
end
|
39
51
|
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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Kavalionak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|