celerity 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/History.txt +33 -0
  2. data/README.txt +19 -9
  3. data/Rakefile +9 -3
  4. data/lib/celerity.rb +39 -39
  5. data/lib/celerity/browser.rb +538 -153
  6. data/lib/celerity/clickable_element.rb +48 -7
  7. data/lib/celerity/collections.rb +155 -131
  8. data/lib/celerity/container.rb +766 -385
  9. data/lib/celerity/default_viewer.rb +10 -0
  10. data/lib/celerity/disabled_element.rb +19 -2
  11. data/lib/celerity/element.rb +152 -83
  12. data/lib/celerity/element_collection.rb +106 -0
  13. data/lib/celerity/element_locator.rb +89 -66
  14. data/lib/celerity/elements/button.rb +23 -13
  15. data/lib/celerity/elements/file_field.rb +17 -5
  16. data/lib/celerity/elements/form.rb +21 -16
  17. data/lib/celerity/elements/frame.rb +75 -53
  18. data/lib/celerity/elements/image.rb +76 -63
  19. data/lib/celerity/elements/label.rb +4 -2
  20. data/lib/celerity/elements/link.rb +30 -18
  21. data/lib/celerity/elements/meta.rb +6 -0
  22. data/lib/celerity/{non_control_elements.rb → elements/non_control_elements.rb} +106 -76
  23. data/lib/celerity/elements/option.rb +16 -2
  24. data/lib/celerity/elements/radio_check.rb +55 -20
  25. data/lib/celerity/elements/select_list.rb +65 -29
  26. data/lib/celerity/elements/table.rb +141 -94
  27. data/lib/celerity/elements/table_cell.rb +13 -6
  28. data/lib/celerity/elements/{table_body.rb → table_elements.rb} +20 -8
  29. data/lib/celerity/elements/table_row.rb +23 -7
  30. data/lib/celerity/elements/text_field.rb +89 -33
  31. data/lib/celerity/exception.rb +77 -41
  32. data/lib/celerity/extra/method_generator.rb +42 -24
  33. data/lib/celerity/htmlunit.rb +49 -0
  34. data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  35. data/lib/celerity/htmlunit/htmlunit-2.5-SNAPSHOT.jar +0 -0
  36. data/lib/celerity/htmlunit/htmlunit-core-js-2.5-SNAPSHOT.jar +0 -0
  37. data/lib/celerity/htmlunit/nekohtml-1.9.12-20090308.130127-11.jar +0 -0
  38. data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  39. data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  40. data/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
  41. data/lib/celerity/identifier.rb +3 -2
  42. data/lib/celerity/input_element.rb +5 -5
  43. data/lib/celerity/listener.rb +135 -0
  44. data/lib/celerity/resources/no_viewer.png +0 -0
  45. data/lib/celerity/util.rb +88 -0
  46. data/lib/celerity/version.rb +4 -3
  47. data/lib/celerity/watir_compatibility.rb +35 -25
  48. data/tasks/jar.rake +57 -0
  49. metadata +35 -142
  50. data.tar.gz.sig +0 -0
  51. data/Manifest.txt +0 -150
  52. data/lib/celerity/element_collections.rb +0 -54
  53. data/lib/celerity/element_map.rb +0 -51
  54. data/lib/celerity/elements/table_footer.rb +0 -30
  55. data/lib/celerity/elements/table_header.rb +0 -30
  56. data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
  57. data/lib/celerity/htmlunit/download.sh +0 -23
  58. data/lib/celerity/htmlunit/htmlunit-2.2.jar +0 -0
  59. data/lib/celerity/htmlunit/htmlunit-core-js-2.2.jar +0 -0
  60. data/lib/celerity/htmlunit/nekohtml-1.9.8.jar +0 -0
  61. data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
  62. data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
  63. data/spec/area_spec.rb +0 -97
  64. data/spec/areas_spec.rb +0 -40
  65. data/spec/browser_spec.rb +0 -266
  66. data/spec/button_spec.rb +0 -227
  67. data/spec/buttons_spec.rb +0 -39
  68. data/spec/checkbox_spec.rb +0 -302
  69. data/spec/checkboxes_spec.rb +0 -38
  70. data/spec/div_spec.rb +0 -207
  71. data/spec/divs_spec.rb +0 -39
  72. data/spec/element_spec.rb +0 -79
  73. data/spec/filefield_spec.rb +0 -123
  74. data/spec/filefields_spec.rb +0 -40
  75. data/spec/form_spec.rb +0 -59
  76. data/spec/forms_spec.rb +0 -41
  77. data/spec/frame_spec.rb +0 -121
  78. data/spec/frames_spec.rb +0 -71
  79. data/spec/hidden_spec.rb +0 -127
  80. data/spec/hiddens_spec.rb +0 -39
  81. data/spec/hn_spec.rb +0 -104
  82. data/spec/hns_spec.rb +0 -45
  83. data/spec/html/2000_spans.html +0 -2009
  84. data/spec/html/bug_duplicate_attributes.html +0 -14
  85. data/spec/html/bug_javascript_001.html +0 -11
  86. data/spec/html/form_js_bug.html +0 -11
  87. data/spec/html/forms_with_input_elements.html +0 -114
  88. data/spec/html/frame_1.html +0 -17
  89. data/spec/html/frame_2.html +0 -16
  90. data/spec/html/frames.html +0 -11
  91. data/spec/html/iframes.html +0 -12
  92. data/spec/html/images.html +0 -27
  93. data/spec/html/images/1.gif +0 -0
  94. data/spec/html/images/2.gif +0 -0
  95. data/spec/html/images/3.gif +0 -0
  96. data/spec/html/images/button.jpg +0 -0
  97. data/spec/html/images/circle.jpg +0 -0
  98. data/spec/html/images/map.gif +0 -0
  99. data/spec/html/images/map2.gif +0 -0
  100. data/spec/html/images/minus.gif +0 -0
  101. data/spec/html/images/originaltriangle.jpg +0 -0
  102. data/spec/html/images/plus.gif +0 -0
  103. data/spec/html/images/square.jpg +0 -0
  104. data/spec/html/images/triangle.jpg +0 -0
  105. data/spec/html/invalid_js.html +0 -11
  106. data/spec/html/latin1_text.html +0 -17
  107. data/spec/html/non_control_elements.html +0 -115
  108. data/spec/html/simple_ajax.html +0 -22
  109. data/spec/html/tables.html +0 -119
  110. data/spec/html/utf8_text.html +0 -15
  111. data/spec/htmlunit_spec.rb +0 -26
  112. data/spec/image_spec.rb +0 -220
  113. data/spec/images_spec.rb +0 -39
  114. data/spec/label_spec.rb +0 -79
  115. data/spec/labels_spec.rb +0 -40
  116. data/spec/li_spec.rb +0 -139
  117. data/spec/link_spec.rb +0 -189
  118. data/spec/links_spec.rb +0 -43
  119. data/spec/lis_spec.rb +0 -40
  120. data/spec/map_spec.rb +0 -102
  121. data/spec/maps_spec.rb +0 -40
  122. data/spec/meta_spec.rb +0 -8
  123. data/spec/ol_spec.rb +0 -87
  124. data/spec/ols_spec.rb +0 -40
  125. data/spec/option_spec.rb +0 -154
  126. data/spec/p_spec.rb +0 -171
  127. data/spec/pre_spec.rb +0 -135
  128. data/spec/pres_spec.rb +0 -40
  129. data/spec/ps_spec.rb +0 -40
  130. data/spec/radio_spec.rb +0 -299
  131. data/spec/radios_spec.rb +0 -42
  132. data/spec/select_list_spec.rb +0 -299
  133. data/spec/select_lists_spec.rb +0 -47
  134. data/spec/span_spec.rb +0 -184
  135. data/spec/spans_spec.rb +0 -64
  136. data/spec/spec.opts +0 -1
  137. data/spec/spec_helper.rb +0 -55
  138. data/spec/table_bodies_spec.rb +0 -57
  139. data/spec/table_body_spec.rb +0 -111
  140. data/spec/table_cell_spec.rb +0 -74
  141. data/spec/table_cells_spec.rb +0 -59
  142. data/spec/table_footer_spec.rb +0 -101
  143. data/spec/table_footers_spec.rb +0 -55
  144. data/spec/table_header_spec.rb +0 -101
  145. data/spec/table_headers_spec.rb +0 -55
  146. data/spec/table_row_spec.rb +0 -104
  147. data/spec/table_rows_spec.rb +0 -58
  148. data/spec/table_spec.rb +0 -160
  149. data/spec/tables_spec.rb +0 -42
  150. data/spec/text_field_spec.rb +0 -323
  151. data/spec/text_fields_spec.rb +0 -44
  152. data/spec/ul_spec.rb +0 -88
  153. data/spec/uls_spec.rb +0 -40
  154. data/spec/watir_compatibility_spec.rb +0 -260
  155. data/support/spec_server.rb +0 -73
  156. data/tasks/rspec.rake +0 -30
  157. data/tasks/specserver.rake +0 -21
  158. metadata.gz.sig +0 -0
@@ -1,70 +1,106 @@
1
1
  module Celerity
2
- #
3
- # Input: Select
4
- #
5
- # This class is the way in which select boxes are manipulated
6
- # Normally a user would not need to create this object as it is returned by the Watir::Container#select_list method
7
2
  class SelectList < InputElement
8
3
  TAGS = [ Identifier.new('select') ]
9
4
  DEFAULT_HOW = :name
10
-
11
- # Returns an array strings representing the text value of the select list's options.
12
- def get_all_contents
5
+
6
+ #
7
+ # @return [Array<String>] An array of strings representing the text value of the select list's options.
8
+ #
9
+
10
+ def options
13
11
  assert_exists
14
12
  @object.getOptions.map { |e| e.asText }
15
13
  end
16
-
17
- # Returns an array strings representing the text value of the currently selected options.
18
- def get_selected_items
14
+
15
+ #
16
+ # @return [Array<String>] An array of strings representing the text value of the currently selected options.
17
+ #
18
+
19
+ def selected_options
19
20
  assert_exists
20
21
  @object.getSelectedOptions.map { |e| e.asText }
21
22
  end
22
-
23
+
24
+ #
23
25
  # Clear all selected options
24
- # FIXME: should update page for each option changed?
25
- def clear_selection
26
+ #
27
+
28
+ def clear
26
29
  # assert_exists called by SelectList#type here
30
+ # TODO: should update page for each option changed?
27
31
  @object.getSelectedOptions.each { |e| e.setSelected(false) } unless type() == 'select-one'
28
32
  end
29
-
33
+
34
+ #
30
35
  # Select the option(s) matching the given value.
31
- # value can be a String or Regexp.
32
- #
33
36
  # If several options match the value given, all will be selected.
37
+ #
38
+ # @param [String, Regexp] value A value.
39
+ # @raise [Celerity::Exception::NoValueFoundException] if the value does not exist.
40
+ # @return [String, nil] The option selected. If multiple options match, returns the first match
41
+ #
42
+ #
43
+
34
44
  def select(value)
35
45
  assert_exists
36
- raise NoValueFoundException, "unknown option with value #{value.inspect}" unless include?(value)
46
+ raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value)
47
+
48
+ selected = nil
37
49
  @object.getOptions.select { |e| matches?(e.asText, value) }.each do |option|
38
- @container.update_page(option.click)
50
+ selected ||= option.asText
51
+ @container.update_page option.click
39
52
  end
53
+
54
+ selected
40
55
  end
41
56
  alias_method :set, :select
42
-
57
+
58
+ #
43
59
  # Returns true if the select list has one or more options matching the given value.
44
- # value can be a String or Regexp.
60
+ #
61
+ # @param [String, Regexp] value A value.
62
+ # @return [true, false]
63
+ #
64
+
45
65
  def include?(value)
46
66
  assert_exists
47
67
  !!@object.getOptions.find { |e| matches?(e.asText, value) }
48
68
  end
49
-
69
+
70
+ #
50
71
  # Returns true if any of the selected options match the given value.
51
- # value can be a String or Regexp.
72
+ #
73
+ # @param [String, Regexp] value A value.
74
+ # @raise [Celerity::Exception::UnknownObjectException] if the value does not exist.
75
+ # @return [true, false]
76
+ #
77
+
52
78
  def selected?(value)
53
79
  assert_exists
54
- raise UnknownObjectException, "unknown option with value #{value.inspect}" unless include?(value)
80
+ raise UnknownObjectException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value)
55
81
  !!@object.getOptions.find { |e| matches?(e.asText, value) && e.isSelected }
56
82
  end
57
83
 
58
- # Returns 'select-multiple' if the select list has the 'multiple' attribute defined.
59
- # Retunrs 'select-one' otherwise.
84
+ #
85
+ # Returns 'select-multiple' if the select list has the 'multiple' attribute,
86
+ # defined, otherwise 'select-one'.
87
+ #
88
+ # @return [String]
60
89
  # TODO: Move to watir_compatibility or delete it 2008-05-23 Alexander
90
+ #
91
+
61
92
  def type
62
93
  assert_exists
63
94
  'select-' + (@object.isAttributeDefined('multiple') ? 'multiple' : 'one')
64
95
  end
65
-
96
+
97
+ #
66
98
  # Returns the value of the first selected option in the select list.
67
99
  # Returns nil if no option is selected.
100
+ #
101
+ # @return [String, nil]
102
+ #
103
+
68
104
  def value
69
105
  assert_exists
70
106
  if (optn = @object.getSelectedOptions.to_a.first)
@@ -72,5 +108,5 @@ module Celerity
72
108
  end
73
109
  end
74
110
 
75
- end
76
- end
111
+ end # SelectList
112
+ end # Celerity
@@ -1,94 +1,141 @@
1
- module Celerity
2
-
3
- class Table < Element
4
- include Enumerable # specs for this?
5
- include Container
6
-
7
- TAGS = [ Identifier.new('table') ]
8
- ATTRIBUTES = BASE_ATTRIBUTES | [:summary, :width, :border, :frame, :rules,
9
- :cellspacing, :cellpadding, :align, :bgcolor]
10
- DEFAULT_HOW = :id
11
-
12
- def locate
13
- super
14
- if @object # cant call assert_exists here, as an exists? method call will fail
15
- @rows = @object.getRows
16
- @cells = []
17
- @rows.each do |row|
18
- row.getCells.each do |c|
19
- @cells << c
20
- end
21
- end
22
- end
23
- end
24
-
25
- # Returns a TableRows object.
26
- def rows
27
- assert_exists
28
- TableRows.new(self, :object, @rows)
29
- end
30
-
31
- # Returns a TableCells object.
32
- def cells
33
- assert_exists
34
- TableCells.new(self, :object, @cells)
35
- end
36
-
37
- # Iterates through each row in the table, passing TableRow objects to the given block.
38
- def each
39
- assert_exists
40
- @rows.each { |row| yield TableRow.new(self, :object, row) }
41
- end
42
-
43
- # Returns the TableRow at the given index (1-indexed).
44
- #
45
- # browser.table(:foo, 'bar')[1] # => #<TableRow...>
46
- # browser.table(:foo, 'bar').child_row[1] # => #<TableRow...>
47
- def child_row(index)
48
- assert_exists
49
- raise UnknownRowException, "Unable to locate a row at index #{index}" if @cells.length < index
50
- TableRow.new(self, :object, @rows[index-1])
51
- end
52
- alias_method :[], :child_row
53
-
54
- # Returns the TableCell at the given index (1-indexed).
55
- #
56
- # In a 10-column row, table.child_cell[11] will return the first cell on the second row.
57
- def child_cell(index)
58
- assert_exists
59
- raise UnknownCellException, "Unable to locate a cell at index #{index}" if @cells.length < index
60
- TableCell.new(self, :object, @cells[index-1])
61
- end
62
-
63
- # The number of rows in the table
64
- def row_count
65
- assert_exists
66
- @object.getRowCount
67
- end
68
-
69
- # Returns the number of columns on the row at the given index. (1-indexed)
70
- # Default is the number of columns on the first row
71
- def column_count(index = 1)
72
- assert_exists
73
- @object.getRow(index-1).getCells.length
74
- end
75
-
76
- # Returns the text of each cell in the the table as a two-dimensional array.
77
- def to_a
78
- assert_exists
79
- @object.getRows.map do |table_row|
80
- table_row.getCells.map { |td| td.asText }
81
- end
82
- end
83
-
84
- def column_values(column_number)
85
- (1..row_count).map { |index| self[index][column_number].text }
86
- end
87
-
88
- def row_values(row_number)
89
- (1..column_count(row_number)).map { |index| self[row_number][index].text }
90
- end
91
-
92
- end
93
-
94
- end
1
+ module Celerity
2
+
3
+ class Table < Element
4
+ include ClickableElement
5
+ include Enumerable
6
+ include Container
7
+
8
+ TAGS = [ Identifier.new('table') ]
9
+ ATTRIBUTES = BASE_ATTRIBUTES | [:summary, :width, :border, :frame, :rules,
10
+ :cellspacing, :cellpadding, :align, :bgcolor]
11
+ DEFAULT_HOW = :id
12
+
13
+ def locate
14
+ super
15
+ if @object # cant call assert_exists here, as an exists? method call will fail
16
+ @rows = @object.getRows
17
+ @cells = []
18
+ @rows.each do |row|
19
+ row.getCells.each do |c|
20
+ @cells << c
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ #
27
+ # @return [Celerity::TableRows]
28
+ #
29
+
30
+ def rows
31
+ assert_exists
32
+ TableRows.new(self, :object, @rows)
33
+ end
34
+
35
+ #
36
+ # @return [Celerity::TableCells]
37
+ #
38
+
39
+ def cells
40
+ assert_exists
41
+ TableCells.new(self, :object, @cells)
42
+ end
43
+
44
+ #
45
+ # Iterates through each row in the table.
46
+ # @yieldparam [Celerity::TableRow] row A row.
47
+ #
48
+
49
+ def each
50
+ assert_exists
51
+ @rows.each { |row| yield TableRow.new(self, :object, row) }
52
+ end
53
+
54
+ #
55
+ # Returns the TableRow at the given index (1-indexed).
56
+ #
57
+ # browser.table(:foo, 'bar')[1] # => #<TableRow...>
58
+ # browser.table(:foo, 'bar').child_row[1] # => #<TableRow...>
59
+ #
60
+ # @param [Fixnum] index The index of the wanted row, 1-indexed.
61
+ # @raise [Celerity::Exception::UnknownRowException]
62
+ # @return [Celerity::TableRow]
63
+ #
64
+
65
+ def child_row(index)
66
+ assert_exists
67
+
68
+ if (index - INDEX_OFFSET) >= @rows.length
69
+ raise UnknownRowException, "Unable to locate a row at index #{index}"
70
+ end
71
+
72
+ TableRow.new(self, :object, @rows[index - INDEX_OFFSET])
73
+ end
74
+ alias_method :[], :child_row
75
+
76
+ #
77
+ # Returns the TableCell at the given index (1-indexed).
78
+ #
79
+ # In a 10-column row, table.child_cell[11] will return the first cell on the second row.
80
+ #
81
+ # @param [Fixnum] index The index of the wanted cell, 1-indexed.
82
+ # @raise [Celerity::Exception::UnknownCellException]
83
+ # @return [Celerity::TableCell]
84
+ #
85
+
86
+ def child_cell(index)
87
+ assert_exists
88
+
89
+ if (index - INDEX_OFFSET) >= @cells.length
90
+ raise UnknownCellException, "Unable to locate a cell at index #{index}"
91
+ end
92
+ TableCell.new(self, :object, @cells[index - INDEX_OFFSET])
93
+ end
94
+
95
+ #
96
+ # The number of rows in the table
97
+ # @return [Fixnum]
98
+ #
99
+
100
+ def row_count
101
+ assert_exists
102
+ @object.getRowCount
103
+ end
104
+
105
+ #
106
+ # Returns the number of columns on the row at the given index. (1-indexed)
107
+ # Default is the number of columns on the first row
108
+ # @param [Fixnum] index An index, 1-indexed (optional).
109
+ # @return [Fixnum]
110
+ #
111
+
112
+ def column_count(index = INDEX_OFFSET)
113
+ assert_exists
114
+ @object.getRow(index - INDEX_OFFSET).getCells.length
115
+ end
116
+
117
+ #
118
+ # Returns the text of each cell in the the table as a two-dimensional array.
119
+ # @return [Array<Array<String>>]
120
+ #
121
+
122
+ def to_a
123
+ assert_exists
124
+ # @object.getRows.map do |table_row|
125
+ # table_row.getCells.map { |td| td.asText.strip }
126
+ # end
127
+ rows.map do |table_row|
128
+ table_row.map { |td| td.text }
129
+ end
130
+ end
131
+
132
+ def column_values(column_number)
133
+ (1..row_count).map { |index| self[index][column_number].text }
134
+ end
135
+
136
+ def row_values(row_number)
137
+ (1..column_count(row_number)).map { |index| self[row_number][index].text }
138
+ end
139
+
140
+ end # Table
141
+ end # Celerity
@@ -1,16 +1,17 @@
1
1
  module Celerity
2
-
2
+
3
3
  class TableCell < Element
4
4
  include Celerity::Exception
5
+ include ClickableElement
5
6
  include Container
6
7
 
7
8
  TAGS = [ Identifier.new('td') ]
8
- ATTRIBUTES = BASE_ATTRIBUTES | CELLHALIGN_ATTRIBUTES | CELLVALIGN_ATTRIBUTES |
9
- [:abbr, :axis, :headers, :scope, :rowspan, :colspan]
10
-
9
+ ATTRIBUTES = BASE_ATTRIBUTES | CELLHALIGN_ATTRIBUTES |
10
+ CELLVALIGN_ATTRIBUTES | [:abbr, :axis, :headers, :scope, :rowspan, :colspan]
11
+
11
12
  DEFAULT_HOW = :id
12
-
13
- alias_method :to_s, :text
13
+
14
+ alias_method :to_s, :text # why?
14
15
 
15
16
  def colspan
16
17
  assert_exists
@@ -19,4 +20,10 @@ module Celerity
19
20
  end
20
21
 
21
22
  end
23
+
24
+ #-- needs code review regarding attributes/correctness of this
25
+ class Th < TableCell
26
+ TAGS = [ Identifier.new('th')]
27
+ end
28
+
22
29
  end
@@ -1,30 +1,42 @@
1
1
  module Celerity
2
- class TableBody < Element
3
- include Enumerable # specs for this?
4
-
5
- TAGS = [ Identifier.new('tbody') ]
2
+ class TableElement < Element
3
+ include Enumerable
4
+ include ClickableElement
5
+
6
6
  ATTRIBUTES = BASE_ATTRIBUTES | CELLHALIGN_ATTRIBUTES | CELLVALIGN_ATTRIBUTES
7
7
  DEFAULT_HOW = :id
8
8
 
9
9
  def locate
10
10
  super
11
- @rows = @object.getRows if @object
11
+ @rows = @object.getRows if @object
12
12
  end
13
13
 
14
14
  def [](index)
15
15
  assert_exists
16
- TableRow.new(self, :object, @rows[index-1])
16
+ TableRow.new(self, :object, @rows[index - INDEX_OFFSET])
17
17
  end
18
18
 
19
19
  def length
20
20
  assert_exists
21
21
  @object.getRows.length
22
22
  end
23
-
23
+
24
24
  def each
25
25
  assert_exists
26
26
  @rows.each { |row| yield TableRow.new(self, :object, row) }
27
27
  end
28
+ end
29
+
30
+ class TableBody < TableElement
31
+ TAGS = [ Identifier.new('tbody') ]
32
+ end
28
33
 
34
+ class TableFooter < TableElement
35
+ TAGS = [ Identifier.new('tfoot') ]
29
36
  end
30
- end
37
+
38
+ class TableHeader < TableElement
39
+ TAGS = [ Identifier.new('thead') ]
40
+ end
41
+
42
+ end