pickles 0.1.12 → 0.2.0

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: 67d811b15d2ba4b98a659537383cc987a9427d5e
4
- data.tar.gz: be4c82f13dbfa6efa300ab8e844ddf0bd5e5f296
3
+ metadata.gz: 6b246c85cb90145f058da79dac65a4826dce3c1f
4
+ data.tar.gz: ec1754a3f0fc0bb06c87624d76152a19afb4a5a7
5
5
  SHA512:
6
- metadata.gz: 23913ff9c5bf8e8e82965e70f29c88d8b26fa36ac0c5db70f4d210e0194152a4e3cc93fbf47ec4ea66385869bb363fb7e88d4e37e0358be53ea25388d67ac1a2
7
- data.tar.gz: 9c033d6bc6bd0de0df2e4f9aa44f6d7824554d3f0900aaac033dbcea74b7a7a680d2e2a47d0f106934e7eb5be64496b598e9a09b185d631f8a66d7165bacb8da
6
+ metadata.gz: 16ac3a5fb9385eb4278d1ca43ed330072e10438bde2779b23f43532e75dd77831802a9ff044f276c1f9241ef30611fb9128a7c33ee04fe5043c3d24fabe01d86
7
+ data.tar.gz: b6f4f774eadf120d651b9047d193b215734023f2aa29837884d5daddfac46797c6a27354980e34513cc0621c82eeb50681d8bf7e6a99d06161994f84af874014
@@ -22,7 +22,7 @@ class Pickles::Config
22
22
  @css_node_map = {}
23
23
  @log_xhr_response = false
24
24
  @xpath_node_map = {}
25
- @fill_tag_steps_map = { 'select' => FillIN::Select }
25
+ @fill_tag_steps_map = { 'select' => FillIN::Select, 'jselect' => FillIN::JsSelect }
26
26
  @check_tag_steps_map = { 'text' => CheckIn::Text }
27
27
  end
28
28
 
@@ -4,6 +4,7 @@ module FillIN
4
4
 
5
5
  autoload :Factory, _dir + 'factory'
6
6
  autoload :Input, _dir + 'input'
7
+ autoload :JsSelect, _dir + 'js_select'
7
8
  autoload :Select, _dir + 'select'
8
9
  autoload :ComplexInput, _dir + 'complex_input'
9
10
 
@@ -64,6 +64,31 @@ module NodeFinders
64
64
  end
65
65
  end
66
66
 
67
+ #
68
+ # try to guess which of the above 2 methods should be used
69
+ #
70
+ def guess_node(within_string, within: nil)
71
+ is_find_node_case = within_string[0] == "\"" && within_string[-1] == "\""
72
+
73
+ match = Helpers::Regex::WITHIN.match(within_string)
74
+ is_detect_node_case = !match.nil?
75
+
76
+ if is_detect_node_case
77
+ captures = match.captures
78
+ el_alias = captures[0]
79
+ locator = captures[1]
80
+
81
+ detect_node(el_alias, locator, within: within)
82
+ elsif is_find_node_case
83
+ within_string[0] = ''
84
+ within_string[-1] = ''
85
+
86
+ find_node(within_string, within: within)
87
+ else
88
+ fail "Incorrect within def"
89
+ end
90
+ end
91
+
67
92
  #
68
93
  # Similar to find_node, but looking for fillable fields for this cases:
69
94
  # 1. label or span(as label) with input hint for input || textarea || @contenteditable
@@ -1,6 +1,6 @@
1
1
  # :nodoc:
2
2
  module Helpers::Regex
3
3
 
4
- WITHIN = /\A\s*(.*)?\s*(?:["|'](.*?)["|'])?\s*\Z/
4
+ WITHIN = /^\s*(.*?)?\s*(?:["|'](.*?)["|'])?\s*$/
5
5
 
6
6
  end
@@ -5,16 +5,18 @@
5
5
  # | .note | Nice guy |
6
6
  #
7
7
 
8
- Then(/^I can(not)? see:$/) do |is_not, table|
8
+ Then(/^I can(not)? see:( within (?:.*))?$/) do |is_not, within_block, table|
9
+ within_block ||= page
10
+
9
11
  if is_not
10
12
  check = -> within, content {
11
- within = within.strip.present? ? find_node(within) : page
13
+ within = within.strip.present? ? Pickles.guess_node(within, within: within_block) : within_block
12
14
 
13
15
  expect(within).not_to have_content(content)
14
16
  }
15
17
  else
16
18
  check = -> within, content {
17
- within = within.strip.present? ? find_node(within) : page
19
+ within = within.strip.present? ? Pickles.guess_node(within, within: within_block) : within_block
18
20
 
19
21
  expect(within).to have_content(content)
20
22
  }
@@ -61,7 +61,11 @@ When /^(?:|I )(fill|select)(?: "([^"]*)")?(?: with "([^"]*)")?( within (?:.*))?$
61
61
  Waiter.wait_for_ajax
62
62
 
63
63
  if type == 'select' && value.present?
64
- FillIN::Select.new(labels, value, within).call
64
+ begin
65
+ FillIN::Select.new(labels, value, within).call
66
+ rescue Capybara::ElementNotFound
67
+ FillIN::JsSelect.new(labels, value, within).call
68
+ end
65
69
  else
66
70
  labels.split(/\s*\|\s*/).each do |label|
67
71
  FillIN::Factory.new(label, value, within: within).call.call
@@ -0,0 +1,32 @@
1
+ class FillIN::JsSelect
2
+
3
+ def initialize(label, value, within)
4
+ @label = label
5
+ @value = value
6
+ @within = within || Capybara.current_session
7
+ end
8
+
9
+ def call
10
+ input = FillIN::Input.new(@label, @value, @within).call
11
+
12
+ locator, index = Locator::Index.execute(@value)
13
+ locator, xpath = Locator::Equal.execute(locator)
14
+
15
+ index ||= 1
16
+
17
+ Waiter.wait do
18
+ input.find(:xpath, "./ancestor::*[#{xpath}][#{index}]/#{xpath}").click
19
+ end
20
+
21
+ Pickles.blur(input)
22
+
23
+ Waiter.wait_for_ajax
24
+
25
+ input
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :label, :value
31
+
32
+ end
@@ -1,3 +1,7 @@
1
+ # When /^select "(.*)" from "(.*)"$/ do |value, label|
2
+ # select value, from: label
3
+ # end
4
+
1
5
  class FillIN::Select
2
6
 
3
7
  def initialize(label, value, within)
@@ -7,20 +11,12 @@ class FillIN::Select
7
11
  end
8
12
 
9
13
  def call
10
- input = FillIN::Input.new(@label, @value, @within).call
11
-
12
- text, selector = NodeTextLookup.lookup_values(value)
13
- item_xpath = selector.(text)
14
-
15
- Waiter.wait do
16
- input.find(:xpath, "./ancestor::*[#{item_xpath}][1]/#{item_xpath}").click
17
- end
18
-
19
- Pickles.blur(input)
14
+ locator, wait = Locator::Wait.execute(@label)
20
15
 
21
- Waiter.wait_for_ajax
16
+ options = { from: locator }
17
+ options[:wait] = wait if wait
22
18
 
23
- input
19
+ @within.select @value, options
24
20
  end
25
21
 
26
22
  private
@@ -1,3 +1,9 @@
1
1
  When 'I go back' do
2
2
  page.evaluate_script('history.back()')
3
3
  end
4
+
5
+ And(/^visit "(.*)"$/) do |url|
6
+ visit url
7
+
8
+ Waiter.wait_for_ajax
9
+ end
@@ -1,9 +1,6 @@
1
- within_reg = /\A\s*(.*)?\s*(?:["|'](.*?)["|'])?\s*\Z/
2
-
3
1
  transformation = -> (within_info) do
4
2
  splitted = within_info.split('within').reject(&:blank?)
5
3
 
6
-
7
4
  splitted.reverse_each.inject(page) do |within, info|
8
5
  captures = Helpers::Regex::WITHIN.match(info).captures
9
6
  el_alias = captures[0]
@@ -1,3 +1,3 @@
1
1
  module Pickles
2
- VERSION = "0.1.12"
2
+ VERSION = "0.2.0"
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.12
4
+ version: 0.2.0
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-05 00:00:00.000000000 Z
11
+ date: 2017-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -114,6 +114,7 @@ files:
114
114
  - lib/cucumber/pickles/steps/fill_in/complex_input.rb
115
115
  - lib/cucumber/pickles/steps/fill_in/factory.rb
116
116
  - lib/cucumber/pickles/steps/fill_in/input.rb
117
+ - lib/cucumber/pickles/steps/fill_in/js_select.rb
117
118
  - lib/cucumber/pickles/steps/fill_in/select.rb
118
119
  - lib/cucumber/pickles/steps/redirect.rb
119
120
  - lib/cucumber/pickles/transform.rb