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 +4 -4
- data/lib/extensions/watir/browser.rb +1 -0
- data/lib/extensions/watir/element.rb +25 -1
- data/lib/watigiri/locators/element/locator.rb +7 -6
- data/watigiri.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54015d016184d1f885580b11fefc238c8b033adc
|
4
|
+
data.tar.gz: e8a3da5a13389f1a12d75767619d14a155661bc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4507c403832e15ef7c955262f199a5a7a28e95fc8f75d4c3273f9a55edba3fbde703a20a41f27e857bf092805b98be894a6a796a813e134b1ccb5d571519e30d
|
7
|
+
data.tar.gz: 8443226c18ace25acb37722d32230945bf2db2c4a77553b5cafb7a0cfd03d872d1853da86899da0d4bafb17067edd91dffd98eecad0f619e1c35267b467b2067
|
@@ -2,8 +2,27 @@ module Watir
|
|
2
2
|
|
3
3
|
class Element
|
4
4
|
|
5
|
-
|
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
|
-
|
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.
|
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.
|
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
|
47
|
+
return super unless @nokogiri || @regex
|
47
48
|
|
48
|
-
@query_scope.
|
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.
|
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
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.
|
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:
|
11
|
+
date: 2018-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|