watigiri 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1467249eba7486417d9378223903444241c26d04
4
- data.tar.gz: d28c6579fc4fd346b952a5283042d57fe6a0d1c2
3
+ metadata.gz: acd708121fc8cb20c263c683acf3b021c396fc16
4
+ data.tar.gz: ed2524285816a2add8b394598141115556ed7dc8
5
5
  SHA512:
6
- metadata.gz: b3f2adcbaf7d8206c12af6608fbbf0192729c5427cc26ce896e3466cb5c939c5be5760eab3a92b24c2bdace7b651577a53f73542ed0a763259751fd165c739f3
7
- data.tar.gz: d7e2ba7e4c3207359c6f15dd58ad96cdb16d9c000d6ac00e038fd13d8011c39ae56004640d0b1db88caed41ec4c9e8b56c8ddbe606aa22e18147ba6107891056
6
+ metadata.gz: 42ca74e87402d2a77a9777795814f0e95cb731f8ee1bbad710b8d35703e590d9f2dee3b1e9c04b1ad06234821a0882cc96c699dde6587cb3bc383093e4847419
7
+ data.tar.gz: 5a01f63348806558b179d4f2285ba2eddc3ed9298f3063d1b8790c9156bda4f9d5a427038488bbb1d2635a236f6da89492ca367aafaf2302c494462cbe111616
@@ -6,6 +6,10 @@ module Watigiri
6
6
  @element = element
7
7
  @selector = selector
8
8
  end
9
+
10
+ def tag_name
11
+ element.name
12
+ end
9
13
  end
10
14
 
11
15
  module Locators
@@ -23,19 +27,8 @@ module Watigiri
23
27
  @nokogiri ? element.element : nokogiri_to_selenium(element)
24
28
  end
25
29
 
26
- def locate_all
27
- @nokogiri = @selector.delete(:nokogiri)
28
- @regex = regex?
29
-
30
- return super unless @nokogiri || @regex
31
- @query_scope.doc ||= Nokogiri::HTML(@query_scope.html).tap { |d| d.css('script').remove }
32
-
33
- elements = using_watir(:all)
34
- @nokogiri ? elements : elements.map { |element| nokogiri_to_watir element }
35
- end
36
-
37
30
  # Is only used when there is no regex, index or visibility locators
38
- def locate_element(how, what)
31
+ def locate_element(how, what, _driver_scope = @query_scope.wd)
39
32
  return super unless @nokogiri
40
33
 
41
34
  el = @query_scope.doc.send("at_#{how}", what)
@@ -51,40 +44,10 @@ module Watigiri
51
44
  end
52
45
  end
53
46
 
54
- def filter_elements_by_locator noko_elements, visible = nil, visible_text = nil, idx = nil, tag_name: nil, filter: :first
55
- return super unless @nokogiri || @regex
56
- return super if noko_elements.first.is_a?(Selenium::WebDriver::Element)
57
-
58
- unless visible.nil?
59
- noko_elements.select! { |el| visible == nokogiri_to_watir(el.element).visible? }
60
- end
61
- filter == :first ? noko_elements[idx || 0] : noko_elements
62
- end
63
-
64
- def filter_elements_by_regex(noko_elements, rx_selector, filter)
65
- return if noko_elements.empty?
66
- return super if noko_elements.first.is_a?(Selenium::WebDriver::Element)
67
- method = filter == :first ? :find : :select
68
-
69
- if @nokogiri || !@regex
70
- return noko_elements.__send__(method) { |el| matches_selector?(el.element, rx_selector) }
71
- end
72
-
73
- selenium_elements = ensure_scope_context.find_elements(noko_elements.first.selector)
74
-
75
- if method == :select
76
- selenium_elements.zip(noko_elements).each_with_object([]) do |els, array|
77
- array << els.first if matches_selector?(els.last.element, rx_selector)
78
- end
79
- else
80
- index = noko_elements.find_index { |el| matches_selector?(el.element, rx_selector) }
81
- index.nil? ? nil : selenium_elements[index]
82
- end
83
- end
84
-
85
47
  def fetch_value(element, how)
86
48
  return super unless @nokogiri || @regex
87
49
  return super if element.is_a?(Selenium::WebDriver::Element)
50
+ element = element.element if element.is_a?(Watigiri::Element)
88
51
  case how
89
52
  when :text
90
53
  element.inner_text
@@ -97,30 +60,13 @@ module Watigiri
97
60
  end
98
61
  end
99
62
 
100
- def nokogiri_to_watir(element)
101
- return element if element.is_a?(Selenium::WebDriver::Element)
102
- se_element = nokogiri_to_selenium(element)
103
- tag = element.name
104
- Watir.element_class_for(tag).new(@query_scope, element: se_element)
105
- end
106
-
107
63
  def nokogiri_to_selenium(element)
108
64
  return element if element.is_a?(Selenium::WebDriver::Element)
109
- tag = element.name
110
- index = @query_scope.doc.xpath("//#{tag}").find_index { |el| el == element }
65
+ tag = element.tag_name
66
+ index = @query_scope.doc.xpath("//#{tag}").find_index { |el| el == element.element }
111
67
  Watir::Element.new(@query_scope, index: index, tag_name: tag).wd
112
68
  end
113
69
 
114
- def label_from_text(label_exp)
115
- # TODO: this won't work correctly if @wd is a sub-element
116
- elements = locate_elements(:xpath, '//label')
117
- return super if elements.any? { |el| el.is_a? Selenium::WebDriver::Element }
118
- element = elements.find do |el|
119
- matches_selector?(el.element, text: label_exp)
120
- end
121
- element.nil? ? nil : element.element
122
- end
123
-
124
70
  def regex?
125
71
  @selector.values.any? { |v| v.is_a?(Regexp) }
126
72
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "watigiri"
7
- spec.version = "0.3.1"
7
+ spec.version = "0.3.2"
8
8
  spec.authors = ["Titus Fortner"]
9
9
  spec.email = ["titusfortner@gmail.com"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watigiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-20 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler