pickles 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +196 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/cucumber/pickles.rb +6 -0
- data/lib/cucumber/pickles/check_in.rb +10 -0
- data/lib/cucumber/pickles/config.rb +61 -0
- data/lib/cucumber/pickles/errors/ambigious.rb +27 -0
- data/lib/cucumber/pickles/errors/node_find_error.rb +37 -0
- data/lib/cucumber/pickles/fill_in.rb +10 -0
- data/lib/cucumber/pickles/helpers.rb +40 -0
- data/lib/cucumber/pickles/helpers/extensions/chrome/.DS_Store +0 -0
- data/lib/cucumber/pickles/helpers/extensions/chrome/compiled.crx.base64 +1 -0
- data/lib/cucumber/pickles/helpers/extensions/chrome/manifest.json +15 -0
- data/lib/cucumber/pickles/helpers/extensions/chrome/src/.DS_Store +0 -0
- data/lib/cucumber/pickles/helpers/extensions/chrome/src/inject/inject.js +35 -0
- data/lib/cucumber/pickles/helpers/main.rb +88 -0
- data/lib/cucumber/pickles/helpers/node_finders.rb +125 -0
- data/lib/cucumber/pickles/helpers/regex.rb +6 -0
- data/lib/cucumber/pickles/helpers/waiter.rb +152 -0
- data/lib/cucumber/pickles/locator/equal.rb +26 -0
- data/lib/cucumber/pickles/locator/index.rb +20 -0
- data/lib/cucumber/pickles/refinements.rb +49 -0
- data/lib/cucumber/pickles/steps.rb +73 -0
- data/lib/cucumber/pickles/steps/can_see.rb +70 -0
- data/lib/cucumber/pickles/steps/check.rb +55 -0
- data/lib/cucumber/pickles/steps/check_in/complex_input.rb +17 -0
- data/lib/cucumber/pickles/steps/check_in/factory.rb +26 -0
- data/lib/cucumber/pickles/steps/check_in/input.rb +36 -0
- data/lib/cucumber/pickles/steps/check_in/text.rb +17 -0
- data/lib/cucumber/pickles/steps/click.rb +91 -0
- data/lib/cucumber/pickles/steps/fill.rb +72 -0
- data/lib/cucumber/pickles/steps/fill_in/complex_input.rb +19 -0
- data/lib/cucumber/pickles/steps/fill_in/factory.rb +25 -0
- data/lib/cucumber/pickles/steps/fill_in/input.rb +29 -0
- data/lib/cucumber/pickles/steps/fill_in/select.rb +30 -0
- data/lib/cucumber/pickles/steps/redirect.rb +3 -0
- data/lib/cucumber/pickles/transform.rb +13 -0
- data/lib/cucumber/pickles/version.rb +3 -0
- data/lib/pickles.rb +3 -0
- data/pickles.gemspec +36 -0
- data/spec/helpers/node_finders_spec.rb +155 -0
- data/spec/helpers/waiter_spec.rb +41 -0
- data/spec/locator_spec.rb +31 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/step_def_spec.rb +0 -0
- data/spec/steps/check_in/factory_spec.rb +52 -0
- data/spec/steps/fill_in/factory_spec.rb +51 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f33295e4575421e5d5fd0d643395d666e31acf4
|
4
|
+
data.tar.gz: a19ac5ac4bd3c1525ec5132521a58c920baf53aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f32f96c2a0f9acf15d2c7d7ca2423394eb15ce9340e937820bcf0be9a1f0b519344d6807799add03aa2bd787eb70023ab83a7d77cbce6e934ba396cdd0d0f85e
|
7
|
+
data.tar.gz: 6f63f831c3dfc9209bf2b2c39b6eaee030f0dc23efd0b33cbdfef2317dd89e37989cd6d6f16b52bb4f8f69685b32fd816ee5e2e78bfb9f01e2e85f85ecb8a2a0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 vs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
# Pickles
|
2
|
+
|
3
|
+
This gem contains some helpers to simplify testing with capybara along with afew predefined cucumber steps.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pickles'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pickles
|
20
|
+
|
21
|
+
# Usage
|
22
|
+
|
23
|
+
## Supported cucumber steps:
|
24
|
+
|
25
|
+
+ Navigation
|
26
|
+
|
27
|
+
1. ```rb
|
28
|
+
When I (?:click|navigate) "([^"]*)"( within (?:.*))?
|
29
|
+
```
|
30
|
+
|
31
|
+
##### Examples:
|
32
|
+
```rb
|
33
|
+
When I click "My button" # standard click by text
|
34
|
+
|
35
|
+
When I click "=Mo" # click node that has exact this text. i.e. ignore: Monday, Moth
|
36
|
+
|
37
|
+
When I click ">Mo" # ajax wait requests done before clicking
|
38
|
+
When I click "Mo>" # ajax wait requests done after clicking
|
39
|
+
|
40
|
+
When I click ">Mo>" # both of the above
|
41
|
+
|
42
|
+
When I click "My button,=Mo" # chain clicks ( click My button then click exact Mo )
|
43
|
+
|
44
|
+
When I click "My button->=Mo" # same as above (-> is for chaining sequential clicks)
|
45
|
+
|
46
|
+
When I click "My button>->=Mo>" # click My button, ajax wait then click Mo
|
47
|
+
|
48
|
+
When I navigate ... # alias
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
##### Description:
|
53
|
+
+ for within checkout docs
|
54
|
+
|
55
|
+
2. ```rb
|
56
|
+
I (?:click|navigate):( within (?:.*))?
|
57
|
+
```
|
58
|
+
|
59
|
+
##### Examples:
|
60
|
+
```rb
|
61
|
+
I navigate:
|
62
|
+
| click | My button |
|
63
|
+
| hover | My span |
|
64
|
+
| hover | Your span |
|
65
|
+
| click | Your button |
|
66
|
+
```
|
67
|
+
|
68
|
+
##### Description:
|
69
|
+
+ alias for previous, but accepts table as argument to allow multiple arguments.
|
70
|
+
+ note ':' in definition
|
71
|
+
+ for within checkout docs
|
72
|
+
|
73
|
+
|
74
|
+
+ Forms:
|
75
|
+
+ Fill:
|
76
|
+
1. ```rb
|
77
|
+
When (?:|I )fill in the following:( within (?:.*))?
|
78
|
+
```
|
79
|
+
|
80
|
+
##### Examples:
|
81
|
+
```rb
|
82
|
+
When I fill in the following:
|
83
|
+
| | Account Number | 5002 |
|
84
|
+
| | Expiry date | 2009-11-01 |
|
85
|
+
| | Note | Nice guy |
|
86
|
+
| | Wants Email? | |
|
87
|
+
| User data | Sex (select) | Male |
|
88
|
+
| | Avatar | avatar.png |
|
89
|
+
| | Due date | 12:35 |
|
90
|
+
| Additional data | Accept user agrement | true |
|
91
|
+
| | Send me letters | false |
|
92
|
+
| | radio 1 | true |
|
93
|
+
```
|
94
|
+
|
95
|
+
##### Description:
|
96
|
+
+ Fills form fields identified by second column.
|
97
|
+
+ First column is optional and defines 'within block' - see docs for within
|
98
|
+
+ Add custom (...) block for second column to define your own form fill steps
|
99
|
+
supported by default:
|
100
|
+
(select) - uses 'I select ".." from ".."' under the hood. Check it out
|
101
|
+
|
102
|
+
2. ```rb
|
103
|
+
When (?:|I ) select "([^"]*)" from "([^"]*)"( within (?:.*))?
|
104
|
+
```
|
105
|
+
|
106
|
+
##### Examples:
|
107
|
+
```rb
|
108
|
+
When I select "Male" from "sex" within "User data"
|
109
|
+
```
|
110
|
+
|
111
|
+
##### Description:
|
112
|
+
+ Fills javascript-like custom selectors(inputs with blocks)
|
113
|
+
+ Params:
|
114
|
+
1. value to select identifier for block with select result( see [find_node](#find_nodelocator-within-nil) )
|
115
|
+
2. field identifier ( used by [find_node](#find_nodelocator-within-nil) )
|
116
|
+
3. within block identifier
|
117
|
+
3. ```rb
|
118
|
+
When (?:|I )(?:select|unselect) "([^"]*)"( within (?:.*))?
|
119
|
+
```
|
120
|
+
|
121
|
+
##### Examples:
|
122
|
+
```rb
|
123
|
+
When I select "Male" within "User data"
|
124
|
+
```
|
125
|
+
|
126
|
+
##### Description:
|
127
|
+
+ Fills checkboxes/radio buttons
|
128
|
+
+ Params:
|
129
|
+
1. identifier for block with selected select ( see [find_node](#find_nodelocator-within-nil) )
|
130
|
+
4. ```rb
|
131
|
+
When (?:|I )attach the file "([^"]*)" to "([^"]*)"( within (?:.*))?
|
132
|
+
```
|
133
|
+
|
134
|
+
##### Examples:
|
135
|
+
```rb
|
136
|
+
When I attach the file "test.png" to "Avatar" within "User data"
|
137
|
+
```
|
138
|
+
|
139
|
+
##### Description:
|
140
|
+
+ Attaches given file to identified fields
|
141
|
+
+ Params:
|
142
|
+
1. relative file name. see attach_file
|
143
|
+
2. file input identifier. see [find_node](#find_nodelocator-within-nil)
|
144
|
+
3. within block identifier. see [find_node](#find_nodelocator-within-nil)
|
145
|
+
|
146
|
+
5. ```rb
|
147
|
+
When (?:|I )(?:fill|select|unselect)(select)?(?: "([^"]*)")?(?: with "([^"]*)")?( within (?:.*))?
|
148
|
+
```
|
149
|
+
|
150
|
+
##### Examples:
|
151
|
+
```rb
|
152
|
+
When I fill "Name" with "Peter" within "User data"
|
153
|
+
When I fill "Avatar" with "test.png" within "User data"
|
154
|
+
When I fill "Male" within "User data"
|
155
|
+
When I fill "sex" with "Male" within "User data"
|
156
|
+
```
|
157
|
+
|
158
|
+
##### Description:
|
159
|
+
+ Tries to fill data by guessing field type from found input type(text|checkbox|radio|etc)
|
160
|
+
+ There MUST always be an input identified by identifier
|
161
|
+
|
162
|
+
+ Check
|
163
|
+
1. ```rb
|
164
|
+
Then fields are filled with:( within (?:.*))?
|
165
|
+
```
|
166
|
+
|
167
|
+
##### Examples:
|
168
|
+
```rb
|
169
|
+
Then fields are filled with:
|
170
|
+
| Account Number | 5002 |
|
171
|
+
| Expiry date | 2009-11-01 |
|
172
|
+
| Note | Nice guy |
|
173
|
+
| Wants Email? | true |
|
174
|
+
| Sex | Male |
|
175
|
+
| Accept user agrement | true |
|
176
|
+
| Send me letters | false |
|
177
|
+
| radio 1 | true |
|
178
|
+
| Avatar | avatar.png |
|
179
|
+
| Due date | 12:35 |
|
180
|
+
```
|
181
|
+
|
182
|
+
##### Description:
|
183
|
+
+ Check fields filled by 'I fill in the folllwing'
|
184
|
+
+ Supports exact same table syntax and optional column
|
185
|
+
|
186
|
+
## Development
|
187
|
+
|
188
|
+
|
189
|
+
## Contributing
|
190
|
+
|
191
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vshaveyko/pickles.
|
192
|
+
|
193
|
+
|
194
|
+
## License
|
195
|
+
|
196
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pickles"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Pickles
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def configure
|
5
|
+
yield config
|
6
|
+
end
|
7
|
+
|
8
|
+
def config
|
9
|
+
@_configuration ||= Pickles::Config.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class Pickles::Config
|
16
|
+
|
17
|
+
using HashSymbolizeKeys
|
18
|
+
|
19
|
+
attr_accessor :css_node_map, :xpath_node_map, :log_xhr_response
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@css_node_map = {}
|
23
|
+
@log_xhr_response = false
|
24
|
+
@xpath_node_map = {}
|
25
|
+
@fill_tag_steps_map = { 'select' => FillIN::Select }
|
26
|
+
@check_tag_steps_map = { 'text' => CheckIn::Text }
|
27
|
+
end
|
28
|
+
|
29
|
+
def css_node_map=(map)
|
30
|
+
raise(ArgumentError, "Node map must be a hash") unless map.is_a?(Hash)
|
31
|
+
|
32
|
+
@css_node_map = map.symbolize_keys
|
33
|
+
end
|
34
|
+
|
35
|
+
def xpath_node_map=(map)
|
36
|
+
raise(ArgumentError, "Node map must be a hash") unless map.is_a?(Hash)
|
37
|
+
|
38
|
+
@xpath_node_map = map.symbolize_keys
|
39
|
+
end
|
40
|
+
|
41
|
+
def fill_tag_steps_map=(map)
|
42
|
+
raise(ArgumentError, "Node map must be a hash") unless map.is_a?(Hash)
|
43
|
+
|
44
|
+
@fill_tag_steps_map.merge!(map)
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_tag_steps_map=(map)
|
48
|
+
raise(ArgumentError, "Node map must be a hash") unless map.is_a?(Hash)
|
49
|
+
|
50
|
+
@check_tag_steps_map.merge!(map)
|
51
|
+
end
|
52
|
+
|
53
|
+
def step_by_tag(tag)
|
54
|
+
@fill_tag_steps_map[tag]
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_step_by_tag(tag)
|
58
|
+
@check_tag_steps_map[tag]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Pickles::Ambiguous < StandardError
|
2
|
+
|
3
|
+
def initialize(locator, within, search_params, message)
|
4
|
+
@search_params= search_params
|
5
|
+
@within = within
|
6
|
+
@locator = locator
|
7
|
+
@message = message.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"Ambiguous(locator: #{@locator}, count: #{_nodes.count}" \
|
12
|
+
+ (@message != "" ? ", message: #@message" : "") \
|
13
|
+
+ (@within.respond_to?(:path) ? "\n within: #{@within.path}" : "") \
|
14
|
+
+ "): \n#{_inspect_nodes}"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def _inspect_nodes
|
20
|
+
_nodes.map(&:inspect).join("\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
def _nodes
|
24
|
+
@nodes ||= @within.all(*@search_params)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class NodeFindError < Capybara::ElementNotFound
|
2
|
+
|
3
|
+
def initialize(text, index, nodes)
|
4
|
+
@text = text
|
5
|
+
@index = index
|
6
|
+
@nodes = nodes
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
if @nodes.empty?
|
11
|
+
_not_found_at_all_message
|
12
|
+
else
|
13
|
+
if @index.present?
|
14
|
+
_not_found_by_index_message
|
15
|
+
else
|
16
|
+
if @nodes.length > 1
|
17
|
+
_need_index_message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def _not_found_by_index_message
|
24
|
+
"Element with text #{@text}[#{@index}] was not found on the page, " \
|
25
|
+
"but #{@text}[0] found; Maybe used incorrect index?"
|
26
|
+
end
|
27
|
+
|
28
|
+
def _not_found_at_all_message
|
29
|
+
"Element with text #{@text}[#{@index}] was not found on the page; " \
|
30
|
+
"Maybe used incorrect text?"
|
31
|
+
end
|
32
|
+
|
33
|
+
def _need_index_message
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|