pickles 0.1.10 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60e12a093f0976dc32ffba53f9e8ada6cd0e686a
4
- data.tar.gz: d514867ab85fdb7376daa8b5aafd85f3a9da142a
3
+ metadata.gz: 67d811b15d2ba4b98a659537383cc987a9427d5e
4
+ data.tar.gz: be4c82f13dbfa6efa300ab8e844ddf0bd5e5f296
5
5
  SHA512:
6
- metadata.gz: adaa725437c33b2845d905afa75ac54ac70b137f8f606c5af351f14d7ccb5ba9e31bf4b6d1a009a9c08fb50c84e21130c798abadb57b25638b1f40f3239d0626
7
- data.tar.gz: f59cc23cf4a1790634fae5da2a0d6af13988bd1f1c8f9a8a000fdd894f08e3bc3a16942d9b37b88f95ae3a66b4b3862c8ef3b20187888a4a46244c2d07c61117
6
+ metadata.gz: 23913ff9c5bf8e8e82965e70f29c88d8b26fa36ac0c5db70f4d210e0194152a4e3cc93fbf47ec4ea66385869bb363fb7e88d4e37e0358be53ea25388d67ac1a2
7
+ data.tar.gz: 9c033d6bc6bd0de0df2e4f9aa44f6d7824554d3f0900aaac033dbcea74b7a7a680d2e2a47d0f106934e7eb5be64496b598e9a09b185d631f8a66d7165bacb8da
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ README.md~
data/README.md CHANGED
@@ -1,4 +1,38 @@
1
1
  # Pickles
2
+ <details>
3
+ <summary> Available steps summary </summary>
4
+
5
+ ```rb
6
+ When I click "My button"
7
+ When I click "=Mo"
8
+ When I click ">Mo"
9
+ When I navigate:
10
+ | click | My button |
11
+ | hover | My span |
12
+
13
+ When I fill in the following:
14
+ | User data | Sex (select) | Male |
15
+ | | Avatar | avatar.png |
16
+
17
+ When I attach the file "test.png" to "Avatar" within "User data"
18
+ When I fill "Name" with "Peter" within "User data"
19
+ When I fill "Avatar" with "test.png" within "User data"
20
+
21
+ Then fields are filled with:
22
+ | Account Number | 5002 |
23
+ | Expiry date | 2009-11-01 |
24
+
25
+ Then I can see:
26
+ | form | Sarah |
27
+ | menu_item "profile change" | admin |
28
+
29
+ Then I can see video "cool_stuff"
30
+ Then I cannot see image "test.png"
31
+ Then focus is on "Sample"
32
+ Then focus is on form_field "Fill user data"
33
+ ```
34
+
35
+ </details>
2
36
 
3
37
  This gem contains some helpers to simplify testing with capybara along with afew predefined cucumber steps.
4
38
 
@@ -300,6 +334,47 @@ Mostly usefull if you're building a SPA app or just have tons of javascript and
300
334
  + Check fields filled by `I fill in the folllwing`
301
335
  + Supports exact same table syntax and optional column
302
336
 
337
+ `Then I can(not)? see:`
338
+ ##### Examples:
339
+ ```rb
340
+ Then I can see:
341
+ | form | Sarah |
342
+ | menu_item "profile change" | admin |
343
+ ```
344
+ ##### Description:
345
+ + First column is optional for identifying within blocks
346
+
347
+ `Then I can(not)? see video (".*?")( within (?:.*))?`
348
+
349
+ ##### Examples:
350
+ ```rb
351
+ Then I can see video "cool_stuff"
352
+ ```
353
+
354
+ ##### Description:
355
+ + value is src link to the video ( i.e. youtube link )
356
+
357
+ `Then I can(not)? see image (".*?")( within (?:.*))?`
358
+
359
+ ##### Examples:
360
+ ```rb
361
+ Then I cannot see image "test.png"
362
+ ```
363
+
364
+ ##### Description:
365
+ + value is image_url ( i.e. assets/images/first.png )
366
+
367
+ `Then focus is on (.*) ?"(.*?)"`
368
+
369
+ ##### Examples:
370
+ ```rb
371
+ Then focus is on "Sample"
372
+ Then focus is on form_field "Fill user data"
373
+ ```
374
+
375
+ ##### Description:
376
+ + first matching group is optional and used from node maps ( see #detect_node )
377
+
303
378
  ## Contributing
304
379
 
305
380
  Bug reports and pull requests are welcome on GitHub at https://github.com/vshaveyko/pickles.
@@ -41,13 +41,13 @@ class Pickles::Config
41
41
  def fill_tag_steps_map=(map)
42
42
  raise(ArgumentError, "Node map must be a hash") unless map.is_a?(Hash)
43
43
 
44
- @fill_tag_steps_map.merge!(map)
44
+ @fill_tag_steps_map.merge!(map.stringify_keys)
45
45
  end
46
46
 
47
47
  def check_tag_steps_map=(map)
48
48
  raise(ArgumentError, "Node map must be a hash") unless map.is_a?(Hash)
49
49
 
50
- @check_tag_steps_map.merge!(map)
50
+ @check_tag_steps_map.merge!(map.stringify_keys)
51
51
  end
52
52
 
53
53
  def step_by_tag(tag)
@@ -20,6 +20,7 @@ module Locator
20
20
 
21
21
  autoload :Index, _dir + 'index'
22
22
  autoload :Equal, _dir + 'equal'
23
+ autoload :Wait, _dir + 'wait'
23
24
 
24
25
  end
25
26
 
@@ -76,11 +76,14 @@ module NodeFinders
76
76
  #
77
77
  def find_input(input_locator, within: nil, options: {})
78
78
  within ||= Capybara.current_session
79
- options[:visible] = false
80
79
 
81
80
  locator, index = Locator::Index.execute(input_locator)
81
+ locator, wait = Locator::Wait.execute(locator)
82
82
  locator, label_xpath = Locator::Equal.execute(locator)
83
83
 
84
+ options[:visible] = false
85
+ options[:wait] = wait if wait
86
+
84
87
  if index
85
88
  index_xpath = "[#{index}]"
86
89
  end
@@ -0,0 +1,21 @@
1
+ module Locator::Wait
2
+
3
+ WAIT_REGEX = /\A([^\p{L}]*)(>)(.*)\Z/
4
+
5
+ module_function
6
+
7
+ def execute(locator)
8
+ matches = WAIT_REGEX.match(locator)
9
+
10
+ if matches
11
+ captures = matches.captures
12
+ locator = "#{captures[0]}#{captures[2]}"
13
+
14
+ [locator, nil]
15
+ else
16
+
17
+ [locator, 0]
18
+ end
19
+ end
20
+
21
+ end
@@ -51,20 +51,20 @@ And(/^I can(not)? see image (".*?")( within (?:.*))?$/) do |is_not, image_src, w
51
51
  end
52
52
  end
53
53
 
54
- # Then /^focus is on "(.*?)"$/ do |locator|
55
- # node = find_node(locator, within: page)
56
- #
57
- # begin
58
- # block_scroll = page.evaluate_script("arguments[0].offsetTop", node)
59
- # rescue
60
- # raise ArgumentError, "Element #{locator} does not exist on page"
61
- # end
62
- #
63
- # window_height = page.evaluate_script('window.innerHeight') / 2
64
- #
65
- # synchronize do
66
- # scrolled = page.evaluate_script('document.body.scrollTop')
67
- #
68
- # (scrolled <= block_scroll && block_scroll <= scrolled + window_height) || raise(Capybara::ElementNotFound)
69
- # end
70
- # end
54
+ Then /^focus is on (.*) ?"(.*?)"$/ do |identifier, locator|
55
+ node = if identifier
56
+ Pickles.detect_node(identifier, locator)
57
+ else
58
+ Pickles.find_node(locator, within: page)
59
+ end
60
+
61
+ block_scroll = page.evaluate_script("arguments[0].offsetTop", node)
62
+
63
+ window_height = page.evaluate_script('window.innerHeight') / 2
64
+
65
+ Waiter.wait do
66
+ scrolled = page.evaluate_script('document.body.scrollTop')
67
+
68
+ (scrolled <= block_scroll && block_scroll <= scrolled + window_height) || raise(Capybara::ElementNotFound)
69
+ end
70
+ end
@@ -9,13 +9,17 @@ class CheckIn::Factory
9
9
  end
10
10
 
11
11
  def call
12
- if !@value.nil? && @value[':']
12
+ if in_quotes?
13
+ remove_quotes!
14
+ end
15
+
16
+ if !@value.nil? && @value[':'] && !in_quotes?
13
17
  step = CheckIn::ComplexInput
14
18
  # return if text_complex_input(label, value, within)
15
19
  elsif @label =~ TAG
16
20
  @label = $1
17
- tag = $2
18
- step = Pickles.config.check_step_by_tag(tag) || CheckIn::Input
21
+ tag = $2
22
+ step = Pickles.config.check_step_by_tag(tag) || CheckIn::Input
19
23
  else
20
24
  step = CheckIn::Input
21
25
  end
@@ -23,4 +27,15 @@ class CheckIn::Factory
23
27
  step.new(@label, @value, @within)
24
28
  end
25
29
 
30
+ private
31
+
32
+ def in_quotes?
33
+ @in_quotes ||= @value && @value[0] == "\"" && @value[-1] == "\""
34
+ end
35
+
36
+ def remove_quotes!
37
+ @value[0] = ''
38
+ @value[-1] = ''
39
+ end
40
+
26
41
  end
@@ -58,6 +58,8 @@ end)
58
58
  # end
59
59
 
60
60
  When /^(?:|I )(fill|select)(?: "([^"]*)")?(?: with "([^"]*)")?( within (?:.*))?$/ do |type, labels, value, within|
61
+ Waiter.wait_for_ajax
62
+
61
63
  if type == 'select' && value.present?
62
64
  FillIN::Select.new(labels, value, within).call
63
65
  else
@@ -17,8 +17,8 @@ class FillIN::Factory
17
17
  step = FillIN::ComplexInput
18
18
  elsif @label =~ TAG
19
19
  @label = $1
20
- tag = $2
21
- step = Pickles.config.step_by_tag(tag) || FillIN::Input
20
+ tag = $2
21
+ step = Pickles.config.step_by_tag(tag) || FillIN::Input
22
22
  else
23
23
  step = FillIN::Input
24
24
  end
@@ -1,6 +1,6 @@
1
1
  within_reg = /\A\s*(.*)?\s*(?:["|'](.*?)["|'])?\s*\Z/
2
2
 
3
- Transform(/(within .*)$/) do |within_info|
3
+ transformation = -> (within_info) do
4
4
  splitted = within_info.split('within').reject(&:blank?)
5
5
 
6
6
 
@@ -16,3 +16,15 @@ Transform(/(within .*)$/) do |within_info|
16
16
  within
17
17
  end
18
18
  end
19
+
20
+ transform_regex = /(within .*)$/
21
+
22
+ begin
23
+ Transform(transform_regex, &transformation)
24
+ rescue NoMethodError => err
25
+ ParameterType(
26
+ name: 'within',
27
+ regexp: transform_regex,
28
+ transformer: transformation
29
+ )
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Pickles
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pickles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - vs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -100,6 +100,7 @@ files:
100
100
  - lib/cucumber/pickles/helpers/waiter.rb
101
101
  - lib/cucumber/pickles/locator/equal.rb
102
102
  - lib/cucumber/pickles/locator/index.rb
103
+ - lib/cucumber/pickles/locator/wait.rb
103
104
  - lib/cucumber/pickles/refinements.rb
104
105
  - lib/cucumber/pickles/steps.rb
105
106
  - lib/cucumber/pickles/steps/can_see.rb