celerity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +10 -0
  2. data/README.txt +8 -11
  3. data/Rakefile +5 -3
  4. data/benchmark/bm_2000_spans.rb +48 -0
  5. data/benchmark/bm_digg.rb +26 -0
  6. data/benchmark/bm_google_images.rb +36 -0
  7. data/benchmark/bm_input_locator.rb +69 -0
  8. data/benchmark/loader.rb +9 -0
  9. data/lib/celerity.rb +3 -1
  10. data/lib/celerity/container.rb +23 -171
  11. data/lib/celerity/disabled_element.rb +1 -1
  12. data/lib/celerity/element.rb +78 -47
  13. data/lib/celerity/element_collections.rb +16 -32
  14. data/lib/celerity/element_locator.rb +135 -0
  15. data/lib/celerity/elements/button.rb +15 -0
  16. data/lib/celerity/elements/file_field.rb +1 -1
  17. data/lib/celerity/elements/form.rb +2 -1
  18. data/lib/celerity/elements/frame.rb +18 -21
  19. data/lib/celerity/elements/image.rb +2 -8
  20. data/lib/celerity/elements/label.rb +1 -3
  21. data/lib/celerity/elements/link.rb +1 -1
  22. data/lib/celerity/elements/option.rb +16 -0
  23. data/lib/celerity/elements/radio_check.rb +18 -7
  24. data/lib/celerity/elements/select_list.rb +1 -17
  25. data/lib/celerity/elements/table.rb +4 -4
  26. data/lib/celerity/elements/table_body.rb +6 -8
  27. data/lib/celerity/elements/table_cell.rb +3 -14
  28. data/lib/celerity/elements/table_row.rb +4 -10
  29. data/lib/celerity/elements/text_field.rb +16 -4
  30. data/lib/celerity/extra/method_generator.rb +144 -0
  31. data/lib/celerity/identifier.rb +10 -0
  32. data/lib/celerity/ie.rb +28 -13
  33. data/lib/celerity/input_element.rb +0 -4
  34. data/lib/celerity/non_control_elements.rb +12 -12
  35. data/lib/celerity/version.rb +1 -1
  36. data/spec/area_spec.rb +41 -41
  37. data/spec/areas_spec.rb +11 -11
  38. data/spec/button_spec.rb +73 -68
  39. data/spec/buttons_spec.rb +10 -10
  40. data/spec/checkbox_spec.rb +102 -96
  41. data/spec/checkboxes_spec.rb +10 -10
  42. data/spec/div_spec.rb +78 -73
  43. data/spec/divs_spec.rb +10 -10
  44. data/spec/element_spec.rb +20 -11
  45. data/spec/filefield_spec.rb +36 -41
  46. data/spec/filefields_spec.rb +10 -10
  47. data/spec/form_spec.rb +29 -29
  48. data/spec/forms_spec.rb +11 -11
  49. data/spec/frame_spec.rb +54 -49
  50. data/spec/hidden_spec.rb +43 -43
  51. data/spec/hiddens_spec.rb +10 -10
  52. data/spec/html/2000_spans.html +2009 -0
  53. data/spec/html/forms_with_input_elements.html +15 -9
  54. data/spec/html/non_control_elements.html +4 -2
  55. data/spec/ie_spec.rb +82 -48
  56. data/spec/image_spec.rb +83 -100
  57. data/spec/images_spec.rb +10 -10
  58. data/spec/label_spec.rb +29 -29
  59. data/spec/labels_spec.rb +10 -10
  60. data/spec/li_spec.rb +41 -41
  61. data/spec/link_spec.rb +65 -59
  62. data/spec/links_spec.rb +11 -11
  63. data/spec/lis_spec.rb +10 -10
  64. data/spec/map_spec.rb +30 -30
  65. data/spec/maps_spec.rb +10 -10
  66. data/spec/p_spec.rb +49 -49
  67. data/spec/pre_spec.rb +41 -41
  68. data/spec/pres_spec.rb +10 -10
  69. data/spec/ps_spec.rb +10 -10
  70. data/spec/radio_spec.rb +104 -97
  71. data/spec/radios_spec.rb +11 -11
  72. data/spec/select_list_spec.rb +118 -106
  73. data/spec/select_lists_spec.rb +15 -15
  74. data/spec/span_spec.rb +54 -54
  75. data/spec/spans_spec.rb +11 -11
  76. data/spec/spec.opts +1 -1
  77. data/spec/spec_helper.rb +23 -3
  78. data/spec/table_bodies.rb +8 -8
  79. data/spec/table_bodies_spec.rb +9 -9
  80. data/spec/table_body_spec.rb +28 -27
  81. data/spec/table_cell_spec.rb +25 -25
  82. data/spec/table_cells_spec.rb +16 -16
  83. data/spec/table_row_spec.rb +16 -16
  84. data/spec/table_rows_spec.rb +12 -12
  85. data/spec/table_spec.rb +36 -36
  86. data/spec/tables_spec.rb +12 -12
  87. data/spec/text_field_spec.rb +111 -92
  88. data/spec/text_fields_spec.rb +13 -13
  89. data/tasks/benchmark.rake +3 -0
  90. data/tasks/rspec.rake +2 -2
  91. data/tasks/testserver.rake +15 -0
  92. metadata +58 -46
  93. data/tasks/simple_ci.rake +0 -94
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.0.2 2008-05-15
2
+ * 3 major enhancements:
3
+ * Support for multiple how => what conditions
4
+ * Fixed performance issue with collections
5
+ * Specs will now run on Windows
6
+ * 3 minor enhancements:
7
+ * Benchmark scripts
8
+ * Method generator
9
+ * Fixed multi-byte characters issue for text fields
10
+
1
11
  == 0.0.1 2008-05-07
2
12
 
3
13
  * 1 major enhancement:
data/README.txt CHANGED
@@ -7,9 +7,14 @@
7
7
  Celerity is a JRuby/RJB wrapper around the HtmlUnit Java library (http://htmlunit.sourceforge.net/).
8
8
  The goal of the project is to implement the Watir API (http://wtf.rubyforge.org/) on top of HtmlUnit.
9
9
 
10
- == FEATURES/PROBLEMS:
11
10
 
12
- * FIX (list of features or problems)
11
+ == FEATURES:
12
+
13
+ * Fast: No time-consuming GUI rendering or unessential downloads
14
+ * Scalable: Java threads lets you run tests in parallel
15
+ * Easy to use: Simple API
16
+ * Portable: Cross-platform
17
+ * Unintrusive: No browser window interrupting your workflow (runs in background)
13
18
 
14
19
  == SYNOPSIS:
15
20
 
@@ -25,20 +30,12 @@
25
30
 
26
31
  * JRuby 1.1
27
32
 
28
- or
29
-
30
- * Ruby Java Bridge (on MRI)
31
-
32
- NOTE: RJB currently has problems with threading. Use JRuby if you want to run your tests concurrently.
33
+ * Java 6
33
34
 
34
35
  == INSTALL:
35
36
 
36
37
  * jruby -S gem install celerity
37
38
 
38
- or
39
-
40
- * (sudo) gem install rjb celerity
41
-
42
39
  == LICENSE:
43
40
 
44
41
  Celerity - JRuby wrapper for HtmlUnit
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
3
-
1
+ begin
2
+ require 'config/requirements'
3
+ require 'config/hoe' # setup Hoe + all gem configuration
4
+ rescue LoadError
5
+ end
4
6
  Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + "/loader"
2
+
3
+ # Create browser object
4
+ browser = FRAMEWORK::IE.new
5
+ browser.goto(TEST_HOST + "/2000_spans.html")
6
+
7
+ TESTS = 100
8
+ res = Benchmark.bmbm do |results|
9
+ results.report("Loop through all spans (n = 1)") do
10
+ 1.times do # Hard coded 1 run
11
+ browser.spans.each do |span|
12
+ span.text
13
+ end
14
+ end
15
+ end
16
+
17
+ # results.report("Loop through all spans (raw)") do
18
+ # TESTS.times do
19
+ # if RUBY_PLATFORM =~ /java/
20
+ # browser.document.getHtmlElementsByTagName("span").each do |span|
21
+ # span.asText
22
+ # end
23
+ # else
24
+ # browser.document.getElementsByTagName("span").each do |span|
25
+ # span.innerText
26
+ # end
27
+ # end
28
+ # end
29
+ # end
30
+
31
+ results.report("Last span by id (String)") do
32
+ TESTS.times do
33
+ browser.span(:id, "id_2000").exists?
34
+ end
35
+ end
36
+
37
+ results.report("Last span by id (Regexp)") do
38
+ TESTS.times do
39
+ browser.span(:id, "/2000/").exists?
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ puts
46
+ total = res.inject(0.0) { |mem, bm| mem + bm.real }
47
+ puts "total : " + total.to_s
48
+ puts "average: " + (total/res.size.to_f).to_s
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + "/loader"
2
+
3
+ TESTS = 5
4
+ res = Benchmark.bmbm do |results|
5
+ results.report("Diggs on front page") do
6
+ TESTS.times do
7
+ # Create browser object
8
+ browser = FRAMEWORK::IE.new
9
+
10
+ # Go to digg.com
11
+ browser.goto('http://digg.com/')
12
+
13
+ # Gather statistics
14
+ total_diggs = 0
15
+ digg_number_elements = browser.links.select { |link| link.id =~ /diggs/ }
16
+ digg_numbers = digg_number_elements.collect { |digg_number_element| digg_number_element.text }
17
+ digg_numbers.each { |digg_number| total_diggs += digg_number.to_i }
18
+ #puts "Found #{digg_numbers.size} stories, with a total of #{total_diggs} diggs."
19
+ end
20
+ end
21
+ end
22
+
23
+ puts
24
+ total = res.inject(0.0) { |mem, bm| mem + bm.real }
25
+ puts "total : " + total.to_s
26
+ puts "average: " + (total/res.size.to_f).to_s
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + "/loader"
2
+
3
+ TESTS = 5
4
+ res = Benchmark.bmbm do |results|
5
+ results.report("Google image search results") do
6
+ TESTS.times do
7
+ # Create browser object
8
+ browser = FRAMEWORK::IE.new
9
+
10
+ # Goto images.google.com
11
+ browser.goto('http://images.google.com/ncr')
12
+
13
+ # Search for Watir
14
+ browser.text_field(:name, 'q').set('Watir')
15
+ browser.button(:value, 'Search Images').click
16
+
17
+ src_pool = []
18
+ pages = 1
19
+ # Gather statistics and click Next if there are more results
20
+ while browser.link(:text, 'Next').exists?
21
+ pages += 1
22
+ browser.link(:text, 'Next').click unless src_pool.empty?
23
+ table_cells = browser.cells.select { |cell| cell.id =~ /tDataImage\d+/ }
24
+ table_cells.each do |cell|
25
+ src_pool << cell.image(:index, 1).src if cell.image(:index, 1).exists?
26
+ end
27
+ end
28
+ #puts "Looked at #{pages} pages of image search results. Got #{src_pool.size} images."
29
+ end
30
+ end
31
+ end
32
+
33
+ puts
34
+ total = res.inject(0.0) { |mem, bm| mem + bm.real }
35
+ puts "total : " + total.to_s
36
+ puts "average: " + (total/res.size.to_f).to_s
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + "/loader"
2
+
3
+ browser = FRAMEWORK::IE.new
4
+ browser.goto(TEST_HOST + "/forms_with_input_elements.html")
5
+
6
+ TESTS = 1000
7
+ res = Benchmark.bmbm do |results|
8
+ results.report("text input by id (String)") do
9
+ TESTS.times { browser.text_field(:id, "new_user_first_name").exists? }
10
+ end
11
+ results.report("text input by id (Regexp)") do
12
+ TESTS.times { browser.text_field(:id, /first_name/).exists? }
13
+ end
14
+ results.report("text input by name (String)") do
15
+ TESTS.times { browser.text_field(:name, "new_user_email").exists? }
16
+ end
17
+ results.report("text input by name (Regexp)") do
18
+ TESTS.times { browser.text_field(:name, /user_email/).exists? }
19
+ end
20
+
21
+ results.report("select list by id (String)") do
22
+ TESTS.times { browser.select_list(:id, 'new_user_country').exists? }
23
+ end
24
+ results.report("select list by id (Regexp)") do
25
+ TESTS.times { browser.select_list(:id, /user_country/).exists? }
26
+ end
27
+ results.report("select list by name (String)") do
28
+ TESTS.times { browser.select_list(:name, 'new_user_country').exists? }
29
+ end
30
+ results.report("select list by name (Regexp)") do
31
+ TESTS.times { browser.select_list(:name, /user_country/).exists? }
32
+ end
33
+
34
+ results.report("checkbox by id (String)") do
35
+ TESTS.times { browser.checkbox(:id, 'new_user_interests_books').exists? }
36
+ end
37
+ results.report("checkbox by id (Regexp)") do
38
+ TESTS.times { browser.checkbox(:id, /interests_books/).exists? }
39
+ end
40
+
41
+ results.report("checkbox by name (String)") do
42
+ TESTS.times { browser.checkbox(:name, 'new_user_interests').exists? }
43
+ end
44
+ results.report("checkbox by name (Regexp)") do
45
+ TESTS.times { browser.checkbox(:name, /user_interests/).exists? }
46
+ end
47
+
48
+ results.report("checkbox by id (String) and value (String)") do
49
+ TESTS.times { browser.checkbox(:id, 'new_user_interests_books', 'cars').exists? }
50
+ end
51
+ results.report("checkbox by id (Regexp) and value (Regexp)") do
52
+ TESTS.times { browser.checkbox(:id, /interests_books/, /car/).exists? }
53
+ end
54
+
55
+ results.report("checkbox by name (String) and value (String)") do
56
+ TESTS.times { browser.checkbox(:name, 'new_user_interests', 'dancing').exists? }
57
+ end
58
+ results.report("checkbox by name (Regexp) and value (Regexp)") do
59
+ TESTS.times { browser.checkbox(:name, /user_interests/, /danc/).exists? }
60
+ end
61
+
62
+
63
+
64
+ end
65
+
66
+ puts
67
+ total = res.inject(0.0) { |mem, bm| mem + bm.real }
68
+ puts "total : " + total.to_s
69
+ puts "average: " + (total/res.size.to_f).to_s
@@ -0,0 +1,9 @@
1
+ require 'benchmark'
2
+ require File.dirname(__FILE__) + "/../spec/spec_helper"
3
+
4
+ if RUBY_PLATFORM =~ /java/
5
+ FRAMEWORK = Celerity
6
+ else
7
+ require 'watir'
8
+ FRAMEWORK = Watir
9
+ end
data/lib/celerity.rb CHANGED
@@ -27,6 +27,8 @@ require "celerity/clickable_element"
27
27
  require "celerity/disabled_element"
28
28
  require "celerity/element_collections"
29
29
  require "celerity/collections"
30
+ require "celerity/element_locator"
31
+ require "celerity/identifier"
30
32
  require "celerity/container"
31
33
  require "celerity/element"
32
34
  require "celerity/input_element"
@@ -34,7 +36,6 @@ require "celerity/non_control_elements"
34
36
  Dir[File.dirname(__FILE__) + "/celerity/elements/*.rb"].each { |f| require(f) }
35
37
  require "celerity/ie"
36
38
 
37
-
38
39
  require "logger"
39
40
  require "uri"
40
41
  require "pp"
@@ -45,3 +46,4 @@ Log.level = Logger::DEBUG
45
46
  # undefine deprecated methods to use them for Element attributes
46
47
  Object.send :undef_method, :id
47
48
  Object.send :undef_method, :type
49
+
@@ -1,29 +1,16 @@
1
1
  module Celerity
2
2
  module Container
3
3
  include Celerity::Exception
4
-
5
4
  attr_accessor :page_container
6
5
 
7
6
  def set_container(container)
8
7
  @container = container
9
8
  @page_container = container.page_container
10
9
  end
11
-
10
+
12
11
  def update_page(page)
13
12
  @page_container.set_page(page)
14
13
  end
15
-
16
- def contains_text(expected_text)
17
- assert_exists
18
- case expected_text
19
- when Regexp
20
- text().match(expected_text)
21
- when String
22
- text().index(expected_text)
23
- else
24
- raise ArgumentError, "Argument #{expected_text.inspect} should be a String or Regexp."
25
- end
26
- end
27
14
 
28
15
  def frame(*args)
29
16
  assert_exists
@@ -33,21 +20,21 @@ module Celerity
33
20
  def table(*args)
34
21
  assert_exists
35
22
  Table.new(self, *args)
36
- end
23
+ end
37
24
  def tables
38
25
  assert_exists
39
26
  Tables.new(self)
40
27
  end
41
-
28
+
42
29
  def cell(*args)
43
- assert_exists
30
+ assert_exists
44
31
  TableCell.new(self, *args)
45
32
  end
46
33
  def cells
47
34
  assert_exists
48
35
  TableCells.new(self)
49
36
  end
50
-
37
+
51
38
  def row(*args)
52
39
  assert_exists
53
40
  TableRow.new(self, *args)
@@ -56,7 +43,7 @@ module Celerity
56
43
  assert_exists
57
44
  TableRows.new(self)
58
45
  end
59
-
46
+
60
47
  def button(*args)
61
48
  assert_exists
62
49
  Button.new(self, *args)
@@ -74,7 +61,7 @@ module Celerity
74
61
  assert_exists
75
62
  FileFields.new(self)
76
63
  end
77
-
64
+
78
65
  def text_field(*args)
79
66
  assert_exists
80
67
  TextField.new(self, *args)
@@ -83,7 +70,7 @@ module Celerity
83
70
  assert_exists
84
71
  TextFields.new(self)
85
72
  end
86
-
73
+
87
74
  def hidden(*args)
88
75
  assert_exists
89
76
  Hidden.new(self, *args)
@@ -92,7 +79,7 @@ module Celerity
92
79
  assert_exists
93
80
  Hiddens.new(self)
94
81
  end
95
-
82
+
96
83
  def select_list(*args)
97
84
  assert_exists
98
85
  SelectList.new(self, *args)
@@ -101,28 +88,28 @@ module Celerity
101
88
  assert_exists
102
89
  SelectLists.new(self)
103
90
  end
104
-
105
- def check_box(how, what, value = nil)
91
+
92
+ def check_box(*args)
106
93
  assert_exists
107
- CheckBox.new(self, how, what, ["checkbox"], value)
94
+ CheckBox.new(self, *args)
108
95
  end
109
96
  alias_method :checkbox, :check_box
110
97
  alias_method :checkBox, :check_box
111
-
98
+
112
99
  def checkboxes
113
100
  assert_exists
114
101
  CheckBoxes.new(self)
115
102
  end
116
-
117
- def radio(how, what, value = nil)
103
+
104
+ def radio(*args)
118
105
  assert_exists
119
- Radio.new(self, how, what, ["radio"], value)
106
+ Radio.new(self, *args)
120
107
  end
121
108
  def radios
122
109
  assert_exists
123
110
  Radios.new(self)
124
111
  end
125
-
112
+
126
113
  def link(*args)
127
114
  assert_exists
128
115
  Link.new(self, *args)
@@ -141,7 +128,7 @@ module Celerity
141
128
  assert_exists
142
129
  Lis.new(self)
143
130
  end
144
-
131
+
145
132
  def map(*args)
146
133
  assert_exists
147
134
  Map.new(self, *args)
@@ -150,7 +137,7 @@ module Celerity
150
137
  assert_exists
151
138
  Maps.new(self)
152
139
  end
153
-
140
+
154
141
  def area(*args)
155
142
  assert_exists
156
143
  Area.new(self, *args)
@@ -159,7 +146,7 @@ module Celerity
159
146
  assert_exists
160
147
  Areas.new(self)
161
148
  end
162
-
149
+
163
150
  def image(*args)
164
151
  assert_exists
165
152
  Image.new(self, *args)
@@ -168,9 +155,7 @@ module Celerity
168
155
  assert_exists
169
156
  Images.new(self)
170
157
  end
171
-
172
- #TODO: Popup method here?
173
-
158
+
174
159
  def div(*args)
175
160
  assert_exists
176
161
  Div.new(self, *args)
@@ -216,7 +201,7 @@ module Celerity
216
201
  assert_exists
217
202
  Pres.new(self)
218
203
  end
219
-
204
+
220
205
  def label(*args)
221
206
  assert_exists
222
207
  Label.new(self, *args)
@@ -225,145 +210,12 @@ module Celerity
225
210
  assert_exists
226
211
  Labels.new(self)
227
212
  end
228
-
229
- #
230
- # Locator Methods
231
- #
232
-
233
- # Returns the specified ole object for input elements on a web page.
234
- #
235
- # This method is used internally by Watir and should not be used externally. It cannot be marked as private because of the way mixins and inheritance work in watir
236
- # * element_instance - an Element subclass instance
237
- # * how - symbol - the way we look for the object. Supported values are
238
- # - :name
239
- # - :id
240
- # - :index
241
- # - :value etc
242
- # * what - string that we are looking for, ex. the name, or id tag attribute or index of the object we are looking for.
243
- # * value - used for objects that have one name, but many values. ex. radio lists and checkboxes
244
- def locate_input_element(element_instance, how, what, value = nil)
245
- idents = element_instance.class::TAGS
246
- tags = idents.map { |e| e.tag }
247
- begin
248
- case how
249
- when :id
250
- case what
251
- when Regexp
252
- elements_by_tag_names(tags).find { |elem| elem.getIdAttribute =~ what }
253
- when String
254
- @object.getHtmlElementById(what)
255
- else
256
- raise ArgumentError, "Argument #{what.inspect} should be a String or Regexp"
257
- end
258
- when :name, :value
259
- elements_by_idents(idents).find do |e|
260
- matches?(e.getAttribute(how.to_s), what) && (value ? matches?(e.getValueAttribute, value) : true)
261
- end
262
- when :caption
263
- elements_by_idents(idents).find { |e| matches?(e.getValueAttribute, what) }
264
- when :class
265
- elements_by_idents(idents).find { |e| matches?(e.getClassAttribute, what) }
266
- when :text
267
- elements_by_idents(idents).find { |e| matches?(e.asText, what) }
268
- when :index
269
- elements_by_idents(idents)[what.to_i - 1]
270
- when :xpath
271
- what = ".#{what}" if what[0] == ?/
272
- @object.getByXPath(what).to_a.first
273
- else
274
- raise MissingWayOfFindingObjectException
275
- end
276
- rescue HtmlUnit::ElementNotFoundException
277
- end
278
- end
279
213
 
280
- def locate_tagged_element(element_instance, how, what)
281
- tags = element_instance.class::TAGS
282
- begin
283
- case how
284
- when :id
285
- case what
286
- when Regexp
287
- elements_by_tag_names(tags).find { |elem| elem.getIdAttribute =~ what }
288
- when String
289
- @object.getHtmlElementById(what)
290
- else
291
- raise ArgumentError, "Argument #{what.inspect} should be a String or Regexp"
292
- end
293
- when :name, :value, :title
294
- elements_by_tag_names(tags).find { |elem| matches?(elem.getAttributeValue(how.to_s), what) }
295
- when :class
296
- elements_by_tag_names(tags).find { |elem| matches?(elem.getClassAttribute, what)}
297
- when :text
298
- elements_by_tag_names(tags).find { |elem| matches?(elem.asText, what) }
299
- when :index
300
- elements_by_tag_names(tags)[what.to_i-1]
301
- when :xpath
302
- what = ".#{what}" if what[0] == ?/
303
- @object.getByXPath(what).to_a.first
304
- when :url
305
- case element_instance
306
- when Celerity::Link, Celerity::Map, Celerity::Area
307
- elements_by_tag_names(tags).find { |elem| matches?(elem.getHrefAttribute, what) }
308
- end
309
- when :src
310
- case element_instance
311
- when Celerity::Image
312
- elements_by_tag_names(tags).find { |elem| matches?(elem.getSrcAttribute, what) }
313
- end
314
- when :alt
315
- case element_instance
316
- when Celerity::Image
317
- elements_by_tag_names(tags).find { |elem| matches?(elem.getAltAttribute, what) }
318
- end
319
- when :action
320
- case element_instance
321
- when Celerity::Form
322
- elements_by_tag_names(tags).find { |elem| matches?(elem.getActionAttribute, what) }
323
- end
324
- when :method
325
- case element_instance
326
- when Celerity::Form
327
- elements_by_tag_names(tags).find { |elem| matches?(elem.getMethodAttribute, what) }
328
- end
329
- else
330
- raise MissingWayOfFindingObjectException, "No how #{how.inspect}"
331
- end
332
- rescue HtmlUnit::ElementNotFoundException
333
- end
334
- end
335
-
336
214
  private
337
-
338
- # this could be optimized when iterating - we don't need to check the class of 'what' for each element
339
- # perhaps something like this
340
- # find_matching_element(collection, method = :to_s, what)
215
+
341
216
  def matches?(string, what)
342
217
  Regexp === what ? string.match(what) : string == what.to_s
343
218
  end
344
219
 
345
- def elements_by_tag_names(tags)
346
- # HtmlUnit's getHtmlElementsByTagNames won't get elements in the correct order, making :index fail
347
- tags.map! { |t| t.downcase }
348
- @object.getAllHtmlChildElements.iterator.to_a.select do |elem|
349
- tags.include?(elem.getTagName)
350
- end
351
- end
352
-
353
- def elements_by_idents(idents)
354
- elements = elements_by_tag_names(idents.map { |i| i.tag })
355
- # Log.debug elements.inspect
356
- elements.select do |e|
357
- idents.any? do |ident|
358
- next unless ident.tag == e.getTagName
359
- if ident.attributes.empty?
360
- true
361
- else
362
- ident.attributes.any? { |key, value| value.include?(e.getAttributeValue(key.to_s)) }
363
- end
364
- end
365
- end
366
- end
367
-
368
220
  end # Container
369
221
  end # Celerity