celerity 0.0.6 → 0.0.7
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.
- data/History.txt +36 -0
- data/Manifest.txt +82 -0
- data/README.rdoc +78 -0
- data/Rakefile +25 -10
- data/celerity.gemspec +40 -0
- data/lib/celerity.rb +36 -20
- data/lib/celerity/browser.rb +396 -189
- data/lib/celerity/clickable_element.rb +25 -5
- data/lib/celerity/collections.rb +2 -2
- data/lib/celerity/container.rb +74 -61
- data/lib/celerity/default_viewer.rb +8 -4
- data/lib/celerity/disabled_element.rb +5 -5
- data/lib/celerity/element.rb +57 -35
- data/lib/celerity/element_collection.rb +22 -21
- data/lib/celerity/element_locator.rb +25 -18
- data/lib/celerity/elements/button.rb +13 -11
- data/lib/celerity/elements/file_field.rb +8 -4
- data/lib/celerity/elements/form.rb +7 -5
- data/lib/celerity/elements/frame.rb +6 -4
- data/lib/celerity/elements/image.rb +4 -4
- data/lib/celerity/elements/label.rb +1 -1
- data/lib/celerity/elements/link.rb +5 -5
- data/lib/celerity/elements/meta.rb +2 -1
- data/lib/celerity/elements/non_control_elements.rb +3 -3
- data/lib/celerity/elements/option.rb +7 -7
- data/lib/celerity/elements/radio_check.rb +18 -18
- data/lib/celerity/elements/select_list.rb +55 -25
- data/lib/celerity/elements/table.rb +21 -18
- data/lib/celerity/elements/table_cell.rb +1 -1
- data/lib/celerity/elements/table_elements.rb +1 -1
- data/lib/celerity/elements/table_row.rb +5 -5
- data/lib/celerity/elements/text_field.rb +33 -28
- data/lib/celerity/exception.rb +11 -5
- data/lib/celerity/htmlunit.rb +24 -8
- data/lib/celerity/htmlunit/commons-codec-1.4.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.6.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.6.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.13.jar +0 -0
- data/lib/celerity/htmlunit/{xercesImpl-2.8.1.jar → xercesImpl-2.9.1.jar} +0 -0
- data/lib/celerity/ignoring_web_connection.rb +15 -0
- data/lib/celerity/input_element.rb +1 -1
- data/lib/celerity/listener.rb +23 -17
- data/lib/celerity/short_inspect.rb +20 -0
- data/lib/celerity/util.rb +5 -2
- data/lib/celerity/version.rb +3 -10
- data/lib/celerity/viewer_connection.rb +89 -0
- data/lib/celerity/watir_compatibility.rb +2 -5
- data/lib/celerity/xpath_support.rb +48 -0
- data/spec/browser_authentication_spec.rb +16 -0
- data/spec/browser_spec.rb +300 -0
- data/spec/clickable_element_spec.rb +39 -0
- data/spec/default_viewer_spec.rb +23 -0
- data/spec/element_spec.rb +51 -0
- data/spec/filefield_spec.rb +18 -0
- data/spec/htmlunit_spec.rb +56 -0
- data/spec/index_offset_spec.rb +24 -0
- data/spec/listener_spec.rb +142 -0
- data/spec/spec_helper.rb +8 -0
- data/tasks/benchmark.rake +4 -0
- data/tasks/deployment.rake +43 -0
- data/tasks/environment.rake +7 -0
- data/tasks/fix.rake +25 -0
- data/tasks/jar.rake +4 -6
- data/tasks/rspec.rake +43 -0
- data/tasks/simple_ci.rake +94 -0
- data/tasks/snapshot.rake +22 -0
- data/tasks/website.rake +17 -0
- data/tasks/yard.rake +9 -0
- metadata +59 -26
- data/README.txt +0 -69
- data/lib/celerity/extra/method_generator.rb +0 -170
- data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.5-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.5-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.12-20090308.130127-11.jar +0 -0
@@ -7,7 +7,7 @@ module Celerity
|
|
7
7
|
|
8
8
|
def click
|
9
9
|
assert_exists_and_enabled
|
10
|
-
@
|
10
|
+
rescue_status_code_exception { @object.click }
|
11
11
|
end
|
12
12
|
|
13
13
|
#
|
@@ -16,7 +16,7 @@ module Celerity
|
|
16
16
|
|
17
17
|
def double_click
|
18
18
|
assert_exists_and_enabled
|
19
|
-
@
|
19
|
+
rescue_status_code_exception { @object.dblClick }
|
20
20
|
end
|
21
21
|
|
22
22
|
#
|
@@ -25,7 +25,7 @@ module Celerity
|
|
25
25
|
|
26
26
|
def right_click
|
27
27
|
assert_exists_and_enabled
|
28
|
-
@
|
28
|
+
rescue_status_code_exception { @object.rightClick }
|
29
29
|
end
|
30
30
|
|
31
31
|
#
|
@@ -37,12 +37,32 @@ module Celerity
|
|
37
37
|
|
38
38
|
def click_and_attach
|
39
39
|
assert_exists_and_enabled
|
40
|
-
browser = Browser.new(
|
41
|
-
browser.
|
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
|
+
|
45
|
+
@browser.disable_event_listener do
|
46
|
+
rescue_status_code_exception { browser.page = @object.click }
|
47
|
+
end
|
42
48
|
|
43
49
|
browser
|
44
50
|
end
|
45
51
|
|
52
|
+
#
|
53
|
+
# Click the element and just return the content as IO. Current page stays unchanged.
|
54
|
+
# This can be used to download content that normally isn't rendered in a browser.
|
55
|
+
#
|
56
|
+
# @return [IO]
|
57
|
+
#
|
58
|
+
|
59
|
+
def download
|
60
|
+
assert_exists_and_enabled
|
61
|
+
@browser.disable_event_listener do
|
62
|
+
@object.click.getWebResponse.getContentAsStream.to_io
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
46
66
|
private
|
47
67
|
|
48
68
|
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
|
data/lib/celerity/container.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Celerity
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# This class contains methods for accessing elements inside a container,
|
5
5
|
# usually the Browser object, meaning the current page.
|
@@ -30,6 +30,7 @@ module Celerity
|
|
30
30
|
|
31
31
|
module Container
|
32
32
|
include Celerity::Exception
|
33
|
+
include Celerity::ShortInspect
|
33
34
|
|
34
35
|
# Points back to the Browser instance that contains this element
|
35
36
|
attr_reader :browser
|
@@ -39,8 +40,8 @@ module Celerity
|
|
39
40
|
#
|
40
41
|
# @param [String, Regexp] expected_text The text to look for.
|
41
42
|
# @return [Fixnum, nil] The index of the matched text, or nil if it doesn't match.
|
42
|
-
#
|
43
|
-
|
43
|
+
#
|
44
|
+
|
44
45
|
def contains_text(expected_text)
|
45
46
|
assert_exists
|
46
47
|
return nil unless respond_to? :text
|
@@ -54,41 +55,26 @@ module Celerity
|
|
54
55
|
raise TypeError, "expected String or Regexp, got #{expected_text.inspect}:#{expected_text.class}"
|
55
56
|
end
|
56
57
|
end
|
57
|
-
|
58
|
+
|
59
|
+
#
|
60
|
+
# Override inspect for readability
|
61
|
+
#
|
62
|
+
|
63
|
+
def inspect
|
64
|
+
short_inspect :include => %w[@conditions @object]
|
65
|
+
end
|
66
|
+
|
58
67
|
#
|
59
68
|
# Used internally to update the container object.
|
60
69
|
# @api private
|
61
70
|
#
|
62
|
-
|
71
|
+
|
63
72
|
def container=(container)
|
64
73
|
@container = container
|
65
74
|
@browser = container.browser
|
66
75
|
container
|
67
76
|
end
|
68
77
|
|
69
|
-
#
|
70
|
-
# Used internally to update the page object.
|
71
|
-
# @api private
|
72
|
-
#
|
73
|
-
|
74
|
-
def update_page(page)
|
75
|
-
@browser.page = page
|
76
|
-
end
|
77
|
-
|
78
|
-
#
|
79
|
-
# Used internally.
|
80
|
-
#
|
81
|
-
# @param [String] string The string to match against.
|
82
|
-
# @param [Regexp, String, #to_s] what The match we're looking for.
|
83
|
-
# @return [Fixnum, true, false, nil]
|
84
|
-
#
|
85
|
-
# @api private
|
86
|
-
#
|
87
|
-
|
88
|
-
def matches?(string, what)
|
89
|
-
Regexp === what ? string =~ what : string == what.to_s
|
90
|
-
end
|
91
|
-
|
92
78
|
#--
|
93
79
|
# below methods sorted alphabetically
|
94
80
|
#++
|
@@ -96,23 +82,23 @@ module Celerity
|
|
96
82
|
#
|
97
83
|
# @return [Celerity::Area]
|
98
84
|
#
|
99
|
-
|
85
|
+
|
100
86
|
def area(*args)
|
101
87
|
Area.new(self, *args)
|
102
88
|
end
|
103
|
-
|
89
|
+
|
104
90
|
#
|
105
91
|
# @return [Celerity::Areas]
|
106
92
|
#
|
107
|
-
|
93
|
+
|
108
94
|
def areas
|
109
95
|
Areas.new(self)
|
110
96
|
end
|
111
|
-
|
97
|
+
|
112
98
|
#
|
113
99
|
# @return [Celerity::Button]
|
114
100
|
#
|
115
|
-
|
101
|
+
|
116
102
|
def button(*args)
|
117
103
|
Button.new(self, *args)
|
118
104
|
end
|
@@ -120,23 +106,23 @@ module Celerity
|
|
120
106
|
#
|
121
107
|
# @return [Celerity::Buttons]
|
122
108
|
#
|
123
|
-
|
109
|
+
|
124
110
|
def buttons
|
125
111
|
Buttons.new(self)
|
126
112
|
end
|
127
|
-
|
113
|
+
|
128
114
|
#
|
129
115
|
# @return [Celerity::TableCell]
|
130
116
|
#
|
131
|
-
|
117
|
+
|
132
118
|
def cell(*args)
|
133
119
|
TableCell.new(self, *args)
|
134
120
|
end
|
135
|
-
|
121
|
+
|
136
122
|
#
|
137
123
|
# @return [Celerity::TableCells]
|
138
124
|
#
|
139
|
-
|
125
|
+
|
140
126
|
def cells
|
141
127
|
TableCells.new(self)
|
142
128
|
end
|
@@ -172,7 +158,7 @@ module Celerity
|
|
172
158
|
def dd(*args)
|
173
159
|
Dd.new(self, *args)
|
174
160
|
end
|
175
|
-
|
161
|
+
|
176
162
|
#
|
177
163
|
# @return [Celerity::Dds]
|
178
164
|
#
|
@@ -180,7 +166,7 @@ module Celerity
|
|
180
166
|
def dds
|
181
167
|
Dds.new(self)
|
182
168
|
end
|
183
|
-
|
169
|
+
|
184
170
|
#
|
185
171
|
# @return [Celerity::Div]
|
186
172
|
#
|
@@ -188,7 +174,7 @@ module Celerity
|
|
188
174
|
def div(*args)
|
189
175
|
Div.new(self, *args)
|
190
176
|
end
|
191
|
-
|
177
|
+
|
192
178
|
#
|
193
179
|
# @return [Celerity::Divs]
|
194
180
|
#
|
@@ -196,7 +182,7 @@ module Celerity
|
|
196
182
|
def divs
|
197
183
|
Divs.new(self)
|
198
184
|
end
|
199
|
-
|
185
|
+
|
200
186
|
#
|
201
187
|
# @return [Celerity::Dl]
|
202
188
|
#
|
@@ -212,7 +198,7 @@ module Celerity
|
|
212
198
|
def dls
|
213
199
|
Dls.new(self)
|
214
200
|
end
|
215
|
-
|
201
|
+
|
216
202
|
#
|
217
203
|
# @return [Celerity::Dt]
|
218
204
|
#
|
@@ -228,19 +214,19 @@ module Celerity
|
|
228
214
|
def dts
|
229
215
|
Dts.new(self)
|
230
216
|
end
|
231
|
-
|
217
|
+
|
232
218
|
#
|
233
219
|
# @return [Celerity::Em]
|
234
|
-
#
|
235
|
-
|
220
|
+
#
|
221
|
+
|
236
222
|
def em(*args)
|
237
223
|
Em.new(self, *args)
|
238
224
|
end
|
239
|
-
|
225
|
+
|
240
226
|
#
|
241
227
|
# @return [Celerity::Ems]
|
242
|
-
#
|
243
|
-
|
228
|
+
#
|
229
|
+
|
244
230
|
def ems
|
245
231
|
Ems.new(self)
|
246
232
|
end
|
@@ -284,7 +270,7 @@ module Celerity
|
|
284
270
|
def frame(*args)
|
285
271
|
Frame.new(self, *args)
|
286
272
|
end
|
287
|
-
|
273
|
+
|
288
274
|
#
|
289
275
|
# @return [Celerity::Frames]
|
290
276
|
#
|
@@ -300,7 +286,7 @@ module Celerity
|
|
300
286
|
def h1(*args)
|
301
287
|
H1.new(self, *args)
|
302
288
|
end
|
303
|
-
|
289
|
+
|
304
290
|
#
|
305
291
|
# @return [Celerity::H1s]
|
306
292
|
#
|
@@ -340,7 +326,7 @@ module Celerity
|
|
340
326
|
def h3s
|
341
327
|
H3s.new(self)
|
342
328
|
end
|
343
|
-
|
329
|
+
|
344
330
|
#
|
345
331
|
# @return [Celerity::H4]
|
346
332
|
#
|
@@ -356,7 +342,7 @@ module Celerity
|
|
356
342
|
def h4s
|
357
343
|
H4s.new(self)
|
358
344
|
end
|
359
|
-
|
345
|
+
|
360
346
|
#
|
361
347
|
# @return [Celerity::H5]
|
362
348
|
#
|
@@ -372,7 +358,7 @@ module Celerity
|
|
372
358
|
def h5s
|
373
359
|
H5s.new(self)
|
374
360
|
end
|
375
|
-
|
361
|
+
|
376
362
|
#
|
377
363
|
# @return [Celerity::H6]
|
378
364
|
#
|
@@ -568,7 +554,7 @@ module Celerity
|
|
568
554
|
#
|
569
555
|
# @return [Celerity::Radio]
|
570
556
|
#
|
571
|
-
|
557
|
+
|
572
558
|
def radio(*args)
|
573
559
|
Radio.new(self, *args)
|
574
560
|
end
|
@@ -612,7 +598,7 @@ module Celerity
|
|
612
598
|
def select_lists
|
613
599
|
SelectLists.new(self)
|
614
600
|
end
|
615
|
-
|
601
|
+
|
616
602
|
#
|
617
603
|
# @return [Celerity::Span]
|
618
604
|
#
|
@@ -676,7 +662,7 @@ module Celerity
|
|
676
662
|
def tbodies
|
677
663
|
TableBodies.new(self)
|
678
664
|
end
|
679
|
-
|
665
|
+
|
680
666
|
#
|
681
667
|
# @return [Celerity::TextField]
|
682
668
|
#
|
@@ -692,7 +678,7 @@ module Celerity
|
|
692
678
|
def text_fields
|
693
679
|
TextFields.new(self)
|
694
680
|
end
|
695
|
-
|
681
|
+
|
696
682
|
#
|
697
683
|
# @return [Celerity::TableFooter]
|
698
684
|
#
|
@@ -709,14 +695,14 @@ module Celerity
|
|
709
695
|
TableFooters.new(self)
|
710
696
|
end
|
711
697
|
alias_method :tfeet, :tfoots # :-)
|
712
|
-
|
698
|
+
|
713
699
|
#
|
714
700
|
# Watir's cells() won't find <th> elements.
|
715
701
|
# This is a workaround.
|
716
702
|
#
|
717
703
|
# @return [Celerity::Th]
|
718
704
|
#
|
719
|
-
|
705
|
+
|
720
706
|
def th(*args)
|
721
707
|
Th.new(self, *args)
|
722
708
|
end
|
@@ -729,7 +715,7 @@ module Celerity
|
|
729
715
|
def ths
|
730
716
|
raise NotImplementedError
|
731
717
|
end
|
732
|
-
|
718
|
+
|
733
719
|
#
|
734
720
|
# @return [Celerity::TableHeader]
|
735
721
|
#
|
@@ -762,5 +748,32 @@ module Celerity
|
|
762
748
|
Uls.new(self)
|
763
749
|
end
|
764
750
|
|
751
|
+
private
|
752
|
+
|
753
|
+
#
|
754
|
+
# Used internally.
|
755
|
+
#
|
756
|
+
# @param [String] string The string to match against.
|
757
|
+
# @param [Regexp, String, #to_s] what The match we're looking for.
|
758
|
+
# @return [Fixnum, true, false, nil]
|
759
|
+
#
|
760
|
+
# @api private
|
761
|
+
#
|
762
|
+
|
763
|
+
def matches?(string, what)
|
764
|
+
Regexp === what ? string =~ what : string == what.to_s
|
765
|
+
end
|
766
|
+
|
767
|
+
#
|
768
|
+
# Rescues HtmlUnit::FailingHttpStatusCodeException and re-raises as
|
769
|
+
# Celerity::NavigationException to avoid the huge JRuby backtrace
|
770
|
+
#
|
771
|
+
|
772
|
+
def rescue_status_code_exception(&blk)
|
773
|
+
yield
|
774
|
+
rescue HtmlUnit::FailingHttpStatusCodeException => e
|
775
|
+
raise NavigationException, e.message, caller
|
776
|
+
end
|
777
|
+
|
765
778
|
end # Container
|
766
779
|
end # Celerity
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module Celerity
|
2
2
|
class DefaultViewer
|
3
3
|
IMAGE = "#{Celerity::DIR}/resources/no_viewer.png"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def save(path = nil)
|
7
|
+
return unless path
|
8
|
+
FileUtils.copy(IMAGE, path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def close; end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
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
|