jarib-celerity 0.0.6.7 → 0.0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +4 -0
- data/lib/celerity/browser.rb +36 -21
- data/lib/celerity/clickable_element.rb +16 -1
- data/lib/celerity/collections.rb +2 -2
- data/lib/celerity/default_viewer.rb +1 -1
- data/lib/celerity/disabled_element.rb +5 -5
- data/lib/celerity/element.rb +25 -21
- data/lib/celerity/element_collection.rb +14 -14
- data/lib/celerity/element_locator.rb +9 -9
- data/lib/celerity/elements/button.rb +9 -9
- data/lib/celerity/elements/file_field.rb +3 -3
- data/lib/celerity/elements/form.rb +5 -5
- data/lib/celerity/elements/frame.rb +2 -2
- data/lib/celerity/elements/image.rb +2 -2
- data/lib/celerity/elements/label.rb +1 -1
- data/lib/celerity/elements/link.rb +4 -4
- data/lib/celerity/elements/non_control_elements.rb +3 -3
- data/lib/celerity/elements/option.rb +5 -5
- data/lib/celerity/elements/radio_check.rb +16 -16
- data/lib/celerity/elements/select_list.rb +16 -16
- data/lib/celerity/elements/table.rb +15 -12
- data/lib/celerity/elements/table_row.rb +3 -3
- data/lib/celerity/elements/text_field.rb +22 -25
- data/lib/celerity/exception.rb +5 -5
- data/lib/celerity/htmlunit.rb +8 -2
- data/lib/celerity/htmlunit/htmlunit-2.6-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/{nekohtml-1.9.12.jar → nekohtml-1.9.13-20090507.082850-2.jar} +0 -0
- data/lib/celerity/listener.rb +17 -17
- data/lib/celerity/util.rb +1 -1
- data/lib/celerity/version.rb +2 -2
- data/lib/celerity/watir_compatibility.rb +2 -2
- metadata +7 -9
- data/lib/celerity/extra/method_generator.rb +0 -170
- data/lib/celerity/htmlunit/htmlunit-2.5.jar +0 -0
data/README.txt
CHANGED
@@ -50,6 +50,10 @@ The source code is available at http://github.com/jarib/celerity/tree/master
|
|
50
50
|
|
51
51
|
* http://github.com/jarib/celerity/wikis
|
52
52
|
|
53
|
+
== BUG TRACKER:
|
54
|
+
|
55
|
+
* http://github.com/jarib/celerity/issues
|
56
|
+
|
53
57
|
== LICENSE:
|
54
58
|
|
55
59
|
Celerity - JRuby wrapper for HtmlUnit
|
data/lib/celerity/browser.rb
CHANGED
@@ -3,7 +3,7 @@ module Celerity
|
|
3
3
|
include Container
|
4
4
|
|
5
5
|
attr_accessor :page, :object, :charset
|
6
|
-
attr_reader :webclient, :viewer
|
6
|
+
attr_reader :webclient, :viewer, :options
|
7
7
|
|
8
8
|
#
|
9
9
|
# Initialize a browser and go to the given URL
|
@@ -27,7 +27,7 @@ module Celerity
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def inspect
|
30
|
-
short_inspect :exclude => %w[@webclient @browser @object]
|
30
|
+
short_inspect :exclude => %w[@webclient @browser @object @options]
|
31
31
|
end
|
32
32
|
|
33
33
|
#
|
@@ -43,7 +43,7 @@ module Celerity
|
|
43
43
|
# @option opts :javascript_exceptions [Boolean] (false) Raise exceptions on script errors. Disabled by default.
|
44
44
|
# @option opts :status_code_exceptions [Boolean] (false) Raise exceptions on failing status codes (404 etc.). Disabled by default.
|
45
45
|
# @option opts :render [:html, :xml] (:html) What DOM representation to send to connected viewers.
|
46
|
-
# @option opts :charset [String] ("UTF-8") Specify the charset that webclient will use
|
46
|
+
# @option opts :charset [String] ("UTF-8") Specify the charset that webclient will use for requests, and those where texts are getting gibberished, like Browser#html.
|
47
47
|
# @option opts :proxy [String] (nil) Proxy server to use, in address:port format.
|
48
48
|
# @option opts :user_agent [String] Override the User-Agent set by the :browser option
|
49
49
|
#
|
@@ -61,6 +61,8 @@ module Celerity
|
|
61
61
|
raise ArgumentError, "expected one of #{render_types.inspect} for key :render"
|
62
62
|
end
|
63
63
|
|
64
|
+
@options = opts.dup # for ClickableElement#click_and_attach
|
65
|
+
|
64
66
|
@render_type = opts.delete(:render) || :html
|
65
67
|
@charset = opts.delete(:charset) || "UTF-8"
|
66
68
|
self.log_level = opts.delete(:log_level) || :warning
|
@@ -142,7 +144,7 @@ module Celerity
|
|
142
144
|
#
|
143
145
|
|
144
146
|
def html
|
145
|
-
@page ? @page.getWebResponse.getContentAsString : ''
|
147
|
+
@page ? @page.getWebResponse.getContentAsString(@charset) : ''
|
146
148
|
end
|
147
149
|
|
148
150
|
#
|
@@ -164,8 +166,10 @@ module Celerity
|
|
164
166
|
|
165
167
|
if @page.respond_to?("getContent")
|
166
168
|
string = @page.getContent.strip
|
167
|
-
|
169
|
+
elsif @page.documentElement
|
168
170
|
string = @page.documentElement.asText.strip
|
171
|
+
else
|
172
|
+
string = ''
|
169
173
|
end
|
170
174
|
|
171
175
|
# Celerity::Util.normalize_text(string)
|
@@ -421,7 +425,8 @@ module Celerity
|
|
421
425
|
end
|
422
426
|
|
423
427
|
#
|
424
|
-
# Allows you to temporarily switch to HtmlUnit's NicelyResynchronizingAjaxController
|
428
|
+
# Allows you to temporarily switch to HtmlUnit's NicelyResynchronizingAjaxController
|
429
|
+
# to resynchronize ajax calls.
|
425
430
|
#
|
426
431
|
# @browser.resynchronized do |b|
|
427
432
|
# b.link(:id, 'trigger_ajax_call').click
|
@@ -439,8 +444,9 @@ module Celerity
|
|
439
444
|
end
|
440
445
|
|
441
446
|
#
|
442
|
-
# Allows you to temporarliy switch to HtmlUnit's default AjaxController, so
|
443
|
-
# This is useful if you have created
|
447
|
+
# Allows you to temporarliy switch to HtmlUnit's default AjaxController, so
|
448
|
+
# ajax calls are performed asynchronously. This is useful if you have created
|
449
|
+
# the Browser with :resynchronize => true, but want to switch it off temporarily.
|
444
450
|
#
|
445
451
|
# @yieldparam [Celerity::Browser] browser The current browser object.
|
446
452
|
# @see Celerity::Browser#new
|
@@ -485,6 +491,16 @@ module Celerity
|
|
485
491
|
# :incorrectness => IncorrectnessListener
|
486
492
|
# :confirm => ConfirmHandler ( window.confirm() )
|
487
493
|
# :prompt => PromptHandler ( window.prompt() )
|
494
|
+
#
|
495
|
+
# Examples:
|
496
|
+
#
|
497
|
+
# browser.add_listener(:status) { |page, message| ... }
|
498
|
+
# browser.add_listener(:alert) { |page, message| ... }
|
499
|
+
# browser.add_listener(:web_window_event) { |web_window_event| ... }
|
500
|
+
# browser.add_listener(:html_parser) { |message, url, line, column, key| ... }
|
501
|
+
# browser.add_listener(:incorrectness) { |message, origin| ... }
|
502
|
+
# browser.add_listener(:confirm) { |page, message| ...; true }
|
503
|
+
# browser.add_listener(:prompt) { |page, message| ... }
|
488
504
|
#
|
489
505
|
#
|
490
506
|
# @param [Symbol] type One of the above symbols.
|
@@ -551,18 +567,18 @@ module Celerity
|
|
551
567
|
end
|
552
568
|
|
553
569
|
#
|
554
|
-
# Set Java log level (default is :warning)
|
570
|
+
# Set Java log level (default is :warning, can be any of :all, :finest, :finer, :fine, :config, :info, :warning, :severe, :off)
|
555
571
|
#
|
556
|
-
# @param [Symbol] level
|
572
|
+
# @param [Symbol] level The new log level.
|
557
573
|
#
|
558
574
|
|
559
575
|
def log_level=(level)
|
560
576
|
log_level = java.util.logging.Level.const_get(level.to_s.upcase)
|
561
577
|
|
562
|
-
[
|
563
|
-
|
564
|
-
|
565
|
-
].each { |
|
578
|
+
[ 'com.gargoylesoftware.htmlunit',
|
579
|
+
'com.gargoylesoftware.htmlunit.html',
|
580
|
+
'org.apache.commons.httpclient'
|
581
|
+
].each { |package| logger_for(package).level = log_level }
|
566
582
|
|
567
583
|
level
|
568
584
|
end
|
@@ -707,8 +723,7 @@ module Celerity
|
|
707
723
|
|
708
724
|
if ua = opts.delete(:user_agent)
|
709
725
|
browser_version.setUserAgent(ua)
|
710
|
-
end
|
711
|
-
|
726
|
+
end
|
712
727
|
|
713
728
|
if proxy = opts.delete(:proxy)
|
714
729
|
phost, pport = proxy.split(":")
|
@@ -757,6 +772,9 @@ module Celerity
|
|
757
772
|
#
|
758
773
|
|
759
774
|
def find_viewer
|
775
|
+
# needed to avoid DRb raising and rescuing lots exceptions
|
776
|
+
DRb.start_service unless DRb.primary_server
|
777
|
+
|
760
778
|
viewer = DRbObject.new_with_uri("druby://127.0.0.1:6429")
|
761
779
|
if viewer.respond_to?(:render_html)
|
762
780
|
@viewer = viewer
|
@@ -772,11 +790,8 @@ module Celerity
|
|
772
790
|
#
|
773
791
|
|
774
792
|
def element_from_dom_node(obj)
|
775
|
-
|
776
|
-
|
777
|
-
else
|
778
|
-
Element.new(self, :object, obj)
|
779
|
-
end
|
793
|
+
element_class = Celerity::Util.htmlunit2celerity(obj.class) || Element
|
794
|
+
element_class.new(self, :object, obj)
|
780
795
|
end
|
781
796
|
|
782
797
|
def logger_for(class_string)
|
@@ -37,12 +37,27 @@ module Celerity
|
|
37
37
|
|
38
38
|
def click_and_attach
|
39
39
|
assert_exists_and_enabled
|
40
|
-
browser = Browser.new(
|
40
|
+
browser = Browser.new(@browser.options.dup)
|
41
|
+
browser.webclient.set_cookie_manager(
|
42
|
+
@browser.webclient.get_cookie_manager
|
43
|
+
) # hirobumi: we do want cookies as well.
|
44
|
+
|
41
45
|
rescue_status_code_exception { browser.update_page(@object.click) }
|
42
46
|
|
43
47
|
browser
|
44
48
|
end
|
45
49
|
|
50
|
+
#
|
51
|
+
# Click the element and just return the content as IO. Current page stays unchanged.
|
52
|
+
#
|
53
|
+
# @return [IO]
|
54
|
+
#
|
55
|
+
|
56
|
+
def download
|
57
|
+
assert_exists_and_enabled
|
58
|
+
@object.click.getWebResponse.getContentAsStream.to_io
|
59
|
+
end
|
60
|
+
|
46
61
|
private
|
47
62
|
|
48
63
|
def assert_exists_and_enabled
|
data/lib/celerity/collections.rb
CHANGED
@@ -51,7 +51,7 @@ module Celerity
|
|
51
51
|
class Dts < ElementCollection
|
52
52
|
def element_class; Dt; end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
class Ems < ElementCollection
|
56
56
|
def element_class; Em; end
|
57
57
|
end
|
@@ -113,7 +113,7 @@ module Celerity
|
|
113
113
|
class Spans < ElementCollection
|
114
114
|
def element_class; Span; end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
class Strongs < ElementCollection
|
118
118
|
def element_class; Strong; end
|
119
119
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# Mixed in to all elements that can have the 'disabled' attribute.
|
5
5
|
#
|
6
6
|
|
7
7
|
module DisabledElement
|
8
8
|
include Celerity::Exception
|
9
|
-
|
9
|
+
|
10
10
|
#
|
11
11
|
# Returns false if the element is disabled.
|
12
12
|
#
|
@@ -17,14 +17,14 @@ module Celerity
|
|
17
17
|
|
18
18
|
#
|
19
19
|
# Returns true if the element is disabled.
|
20
|
-
#
|
21
|
-
|
20
|
+
#
|
21
|
+
|
22
22
|
def disabled?
|
23
23
|
assert_exists unless defined?(@object) && @object
|
24
24
|
@object.isDisabled
|
25
25
|
end
|
26
26
|
alias_method :disabled, :disabled?
|
27
|
-
|
27
|
+
|
28
28
|
#
|
29
29
|
# Used internally.
|
30
30
|
# @api private
|
data/lib/celerity/element.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# Superclass for all HTML elements.
|
5
|
-
#
|
6
|
-
|
5
|
+
#
|
6
|
+
|
7
7
|
class Element
|
8
8
|
include Exception
|
9
9
|
include Container
|
@@ -57,7 +57,7 @@ module Celerity
|
|
57
57
|
#
|
58
58
|
# Get the parent element
|
59
59
|
# @return [Celerity::Element, nil] subclass of Celerity::Element, or nil if no parent was found
|
60
|
-
#
|
60
|
+
#
|
61
61
|
|
62
62
|
def parent
|
63
63
|
assert_exists
|
@@ -73,13 +73,13 @@ module Celerity
|
|
73
73
|
|
74
74
|
#
|
75
75
|
# Sets the focus to this element.
|
76
|
-
#
|
76
|
+
#
|
77
77
|
|
78
78
|
def focus
|
79
79
|
assert_exists
|
80
80
|
@object.focus
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
#
|
84
84
|
# Fires the given event for this element
|
85
85
|
#
|
@@ -92,12 +92,16 @@ module Celerity
|
|
92
92
|
#
|
93
93
|
# Used internally. Find the element on the page.
|
94
94
|
# @api private
|
95
|
-
#
|
95
|
+
#
|
96
96
|
|
97
97
|
def locate
|
98
98
|
@object = ElementLocator.new(@container, self.class).find_by_conditions(@conditions)
|
99
99
|
end
|
100
100
|
|
101
|
+
#
|
102
|
+
# Returns the HtmlUnit object backing this element
|
103
|
+
#
|
104
|
+
|
101
105
|
def object
|
102
106
|
@object || locate
|
103
107
|
end
|
@@ -114,7 +118,7 @@ module Celerity
|
|
114
118
|
#
|
115
119
|
# @param [String, #to_s] The attribute.
|
116
120
|
# @return [String] The value of the given attribute.
|
117
|
-
#
|
121
|
+
#
|
118
122
|
|
119
123
|
def attribute_value(attribute)
|
120
124
|
assert_exists
|
@@ -127,7 +131,7 @@ module Celerity
|
|
127
131
|
# its parents) into account - styles from applied CSS is not considered.
|
128
132
|
#
|
129
133
|
# @return [boolean]
|
130
|
-
#
|
134
|
+
#
|
131
135
|
|
132
136
|
def visible?
|
133
137
|
assert_exists
|
@@ -139,7 +143,7 @@ module Celerity
|
|
139
143
|
#
|
140
144
|
# @raise [Celerity::Exception::UnknownObjectException] if the element can't be found.
|
141
145
|
# @api private
|
142
|
-
#
|
146
|
+
#
|
143
147
|
|
144
148
|
def assert_exists
|
145
149
|
locate
|
@@ -147,11 +151,11 @@ module Celerity
|
|
147
151
|
raise UnknownObjectException, "Unable to locate #{self.class.name[/::(.*)$/, 1]}, using #{identifier_string}"
|
148
152
|
end
|
149
153
|
end
|
150
|
-
|
154
|
+
|
151
155
|
#
|
152
156
|
# Checks if the element exists.
|
153
157
|
# @return [true, false]
|
154
|
-
#
|
158
|
+
#
|
155
159
|
|
156
160
|
def exists?
|
157
161
|
assert_exists
|
@@ -160,13 +164,13 @@ module Celerity
|
|
160
164
|
false
|
161
165
|
end
|
162
166
|
alias_method :exist?, :exists?
|
163
|
-
|
167
|
+
|
164
168
|
#
|
165
169
|
# Return a text representation of the element as it would appear in a browser.
|
166
170
|
#
|
167
171
|
# @see inner_text
|
168
172
|
# @return [String]
|
169
|
-
#
|
173
|
+
#
|
170
174
|
|
171
175
|
def text
|
172
176
|
assert_exists
|
@@ -180,7 +184,7 @@ module Celerity
|
|
180
184
|
#
|
181
185
|
# @see text
|
182
186
|
# @return [String]
|
183
|
-
#
|
187
|
+
#
|
184
188
|
|
185
189
|
def inner_text
|
186
190
|
assert_exists
|
@@ -189,7 +193,7 @@ module Celerity
|
|
189
193
|
|
190
194
|
#
|
191
195
|
# @return [String] The normative XML representation of the element (including children).
|
192
|
-
#
|
196
|
+
#
|
193
197
|
|
194
198
|
def to_xml
|
195
199
|
assert_exists
|
@@ -201,7 +205,7 @@ module Celerity
|
|
201
205
|
|
202
206
|
#
|
203
207
|
# @return [String] A string representation of the element's attributes.
|
204
|
-
#
|
208
|
+
#
|
205
209
|
|
206
210
|
def attribute_string
|
207
211
|
assert_exists
|
@@ -216,7 +220,7 @@ module Celerity
|
|
216
220
|
|
217
221
|
#
|
218
222
|
# return the canonical xpath for this element (Celerity-specific)
|
219
|
-
#
|
223
|
+
#
|
220
224
|
|
221
225
|
def xpath
|
222
226
|
assert_exists
|
@@ -230,7 +234,7 @@ module Celerity
|
|
230
234
|
#
|
231
235
|
# @return [String] The resulting attribute.
|
232
236
|
# @raise [NoMethodError] if the element doesn't support this attribute.
|
233
|
-
#
|
237
|
+
#
|
234
238
|
|
235
239
|
def method_missing(meth, *args, &blk)
|
236
240
|
assert_exists
|
@@ -243,9 +247,9 @@ module Celerity
|
|
243
247
|
Log.warn "Element\#method_missing calling super with #{meth.inspect}"
|
244
248
|
super
|
245
249
|
end
|
246
|
-
|
250
|
+
|
247
251
|
def methods(*args)
|
248
|
-
ms = super
|
252
|
+
ms = super
|
249
253
|
ms += self.class::ATTRIBUTES.map { |e| e.to_s }
|
250
254
|
ms.sort
|
251
255
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# This class is the superclass for the iterator classes (Buttons, Links, Spans etc.)
|
5
5
|
# It would normally only be accessed by the iterator methods (Browser#spans, Browser#links, ...).
|
6
|
-
#
|
7
|
-
|
6
|
+
#
|
7
|
+
|
8
8
|
class ElementCollection
|
9
9
|
include Enumerable
|
10
|
-
|
10
|
+
|
11
11
|
#
|
12
12
|
# @api private
|
13
13
|
#
|
@@ -17,10 +17,10 @@ module Celerity
|
|
17
17
|
@object = (how == :object ? what : nil)
|
18
18
|
@length = length
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
#
|
22
22
|
# @return [Fixnum] The number of elements in this collection.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
|
25
25
|
def length
|
26
26
|
if @object
|
@@ -45,7 +45,7 @@ module Celerity
|
|
45
45
|
|
46
46
|
@length
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
#
|
50
50
|
# Get the element at the given index.
|
51
51
|
# This is 1-indexed to keep compatibility with Watir - subject to change.
|
@@ -54,7 +54,7 @@ module Celerity
|
|
54
54
|
#
|
55
55
|
# @param [Fixnum] n Index of wanted element, 1-indexed.
|
56
56
|
# @return [Celerity::Element] Returns a subclass of Celerity::Element
|
57
|
-
#
|
57
|
+
#
|
58
58
|
|
59
59
|
def [](n)
|
60
60
|
if @elements && @elements[n - INDEX_OFFSET]
|
@@ -68,8 +68,8 @@ module Celerity
|
|
68
68
|
# Get the first element in this collection. (Celerity-specific)
|
69
69
|
#
|
70
70
|
# @return [Celerity::Element] Returns a subclass of Celerity::Element
|
71
|
-
#
|
72
|
-
|
71
|
+
#
|
72
|
+
|
73
73
|
def first
|
74
74
|
self[INDEX_OFFSET]
|
75
75
|
end
|
@@ -78,8 +78,8 @@ module Celerity
|
|
78
78
|
# Get the last element in this collection. (Celerity-specific)
|
79
79
|
#
|
80
80
|
# @return [Celerity::Element] Returns a subclass of Celerity::Element
|
81
|
-
#
|
82
|
-
|
81
|
+
#
|
82
|
+
|
83
83
|
def last
|
84
84
|
self[INDEX_OFFSET - 1]
|
85
85
|
end
|
@@ -90,8 +90,8 @@ module Celerity
|
|
90
90
|
# puts browser.text_fields
|
91
91
|
#
|
92
92
|
# @return [String] A string representation of all elements in this collection.
|
93
|
-
#
|
94
|
-
|
93
|
+
#
|
94
|
+
|
95
95
|
def to_s
|
96
96
|
map { |e| e.to_s }.join("\n")
|
97
97
|
end
|