watigiri 0.2.2 → 0.3.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: b54f1a44d2ce370b82465ea35623426beb9cc700
4
- data.tar.gz: 16c9d06260d4a01271bc7f789a816e9d20cbdee3
3
+ metadata.gz: 54015d016184d1f885580b11fefc238c8b033adc
4
+ data.tar.gz: e8a3da5a13389f1a12d75767619d14a155661bc2
5
5
  SHA512:
6
- metadata.gz: 68cad5b608ac6b3eebc53f1c36b62371c968db2af9035cfa352a5f96c915a5ca0cb9eb3651f275d3b634fabf44f68fd360905298d7db485a0ce9d9c75ff3a10c
7
- data.tar.gz: be6cb2c9ff17d61c292c4b26a86ed4ddc9da9eabc95a8ec777cafa0cecaad50ad8f9bae0143b7b6513a6fcf553f95d0e5c5b06e18124c78151c738d8cbb0032b
6
+ metadata.gz: 4507c403832e15ef7c955262f199a5a7a28e95fc8f75d4c3273f9a55edba3fbde703a20a41f27e857bf092805b98be894a6a796a813e134b1ccb5d571519e30d
7
+ data.tar.gz: 8443226c18ace25acb37722d32230945bf2db2c4a77553b5cafb7a0cfd03d872d1853da86899da0d4bafb17067edd91dffd98eecad0f619e1c35267b467b2067
@@ -19,6 +19,7 @@ module Watir
19
19
  @doc = nil
20
20
  after_hooks.delete(@reset_doc_hook)
21
21
  end
22
+
22
23
  #
23
24
  # Uses Nokogiri to return the text of page body.
24
25
  #
@@ -2,8 +2,27 @@ module Watir
2
2
 
3
3
  class Element
4
4
 
5
- # TODO - reimplement with Watir Executor when available
5
+ attr_reader :doc
6
6
 
7
+ #
8
+ # Store instance of Nokogiri
9
+ #
10
+
11
+ def doc=(html)
12
+ @doc = html
13
+ return if html.nil?
14
+
15
+ @reset_doc_hook = ->(element) { element.reset_doc }
16
+ browser.after_hooks.add(@reset_doc_hook)
17
+ end
18
+
19
+ def reset_doc
20
+ @doc = nil
21
+ browser.after_hooks.delete(@reset_doc_hook)
22
+ end
23
+
24
+ #
25
+ # TODO - reimplement with Watir Executor when available
7
26
  #
8
27
  # Uses Nokogiri to return the text of the element.
9
28
  #
@@ -15,5 +34,10 @@ module Watir
15
34
  text
16
35
  end
17
36
 
37
+ alias_method :el_stale?, :stale?
38
+ def stale?
39
+ @doc.nil? && el_stale?
40
+ end
41
+
18
42
  end # Element
19
43
  end # Watir
@@ -15,7 +15,8 @@ module Watigiri
15
15
  @regex = regex?
16
16
 
17
17
  return super unless @nokogiri || @regex
18
- @query_scope.browser.doc ||= Nokogiri::HTML(@query_scope.html).tap { |d| d.css('script').remove }
18
+ command = @query_scope.is_a?(Watir::Browser) ? :html : :inner_html
19
+ @query_scope.doc ||= Nokogiri::HTML(@query_scope.send(command)).tap { |d| d.css('script').remove }
19
20
 
20
21
  element = using_watir(:first)
21
22
  return if element.nil?
@@ -27,7 +28,7 @@ module Watigiri
27
28
  @regex = regex?
28
29
 
29
30
  return super unless @nokogiri || @regex
30
- @query_scope.browser.doc ||= Nokogiri::HTML(@query_scope.html).tap { |d| d.css('script').remove }
31
+ @query_scope.doc ||= Nokogiri::HTML(@query_scope.html).tap { |d| d.css('script').remove }
31
32
 
32
33
  elements = using_watir(:all)
33
34
  @nokogiri ? elements : elements.map { |element| nokogiri_to_watir element }
@@ -37,15 +38,15 @@ module Watigiri
37
38
  def locate_element(how, what)
38
39
  return super unless @nokogiri
39
40
 
40
- el = @query_scope.browser.doc.send("at_#{how}", what)
41
+ el = @query_scope.doc.send("at_#{how}", what)
41
42
  Watigiri::Element.new element: el, selector: {how => what}
42
43
  end
43
44
 
44
45
  # "how" can only be :css or :xpath
45
46
  def locate_elements(how, what, _scope = @query_scope.wd)
46
- return super unless (@nokogiri || @regex) && @query_scope.is_a?(Watir::Browser)
47
+ return super unless @nokogiri || @regex
47
48
 
48
- @query_scope.browser.doc.send(how, what).map do |el|
49
+ @query_scope.doc.send(how, what).map do |el|
49
50
  Watigiri::Element.new element: el, selector: {how => what}
50
51
  end
51
52
  end
@@ -106,7 +107,7 @@ module Watigiri
106
107
  def nokogiri_to_selenium(element)
107
108
  return element if element.is_a?(Selenium::WebDriver::Element)
108
109
  tag = element.name
109
- index = @query_scope.browser.doc.xpath("//#{tag}").find_index { |el| el == element }
110
+ index = @query_scope.doc.xpath("//#{tag}").find_index { |el| el == element }
110
111
  Watir::Element.new(@query_scope, index: index, tag_name: tag).wd
111
112
  end
112
113
 
data/watigiri.gemspec CHANGED
@@ -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.2.2"
7
+ spec.version = "0.3.0"
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.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2018-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler