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,7 +1,8 @@
1
1
  module Celerity
2
2
  class TableRow < Element
3
- include Enumerable # specs for this?
4
-
3
+ include Enumerable
4
+ include ClickableElement
5
+
5
6
  TAGS = [ Identifier.new('tr') ]
6
7
  DEFAULT_HOW = :id
7
8
 
@@ -10,23 +11,38 @@ module Celerity
10
11
  @cells = @object.getCells if @object
11
12
  end
12
13
 
14
+ #
15
+ # Yields each TableCell in this row to the given block.
16
+ #
17
+
13
18
  def each
14
19
  assert_exists
15
20
  @cells.each { |cell| yield TableCell.new(self, :object, cell) }
16
21
  end
17
22
 
23
+ #
24
+ # Get the child cell at the given index
25
+ #
26
+
18
27
  def child_cell(index)
19
28
  assert_exists
20
- raise UnknownCellException, "Unable to locate a cell at index #{index}" if @cells.length < index
21
-
22
- TableCell.new(self, :object, @cells[index-1])
29
+
30
+ if (index - INDEX_OFFSET) >= @cells.length
31
+ raise UnknownCellException, "Unable to locate a cell at index #{index}"
32
+ end
33
+
34
+ TableCell.new(self, :object, @cells[index - INDEX_OFFSET])
23
35
  end
24
36
  alias_method :[], :child_cell
25
37
 
38
+ #
39
+ # Number of cells in this row.
40
+ #
41
+
26
42
  def column_count
27
43
  assert_exists
28
44
  @cells.length
29
45
  end
30
46
 
31
- end
32
- end
47
+ end # TableRow
48
+ end # Celerity
@@ -1,27 +1,32 @@
1
1
  module Celerity
2
+
2
3
  #
3
4
  # Class representing text field elements
4
5
  #
5
6
  # This class is the main class for Text Fields
6
7
  # Normally a user would not need to create this object as it is returned by the Watir::Container#text_field method
8
+ #
9
+
7
10
  class TextField < InputElement
8
- TAGS = [ Identifier.new('textarea'),
9
- Identifier.new('input', :type => ["text", "password", /^(?!(file|radio|checkbox|submit|reset|image|button|hidden)$)/]) ]
11
+ NON_TEXT_TYPES = %w[file radio checkbox submit reset image button hidden]
12
+ TAGS = [ Identifier.new('textarea'),
13
+ Identifier.new('input', :type => ["text", "password", /^(?!(#{ Regexp.union(*NON_TEXT_TYPES) })$)/]) ]
10
14
  DEFAULT_HOW = :name
11
-
15
+
16
+ #
12
17
  # Clear the text field.
18
+ #
19
+
13
20
  def clear
14
21
  assert_exists
15
- case @object.getTagName
16
- when 'textarea'
17
- @object.setText('')
18
- when 'input'
19
- @object.setValueAttribute('')
20
- end
22
+ insert_string ''
21
23
  end
22
-
23
- # Set the text field to the given value.
24
+
25
+ #
26
+ # Set the text field to the given value.
24
27
  # This ensures execution of JavaScript events (onkeypress etc.), but is slower than +value=+
28
+ #
29
+
25
30
  def set(value)
26
31
  assert_enabled
27
32
  assert_not_readonly
@@ -29,23 +34,25 @@ module Celerity
29
34
  type_string(value.to_s)
30
35
  end
31
36
 
37
+ #
32
38
  # This directly sets the text field to the given value, skipping exectuion of JavaScript events.
33
39
  # Use +set+ if you want to run events on text fields.
40
+ #
41
+
34
42
  def value=(value)
35
43
  assert_enabled
36
44
  assert_not_readonly
37
45
  clear
38
- case @object.getTagName
39
- when 'textarea'
40
- @object.setText(value.to_s)
41
- when 'input'
42
- @object.setValueAttribute(value.to_s)
43
- end
44
-
46
+
47
+ insert_string value.to_s
48
+
45
49
  value
46
50
  end
47
51
 
52
+ #
48
53
  # Returns the text in the text field.
54
+ #
55
+
49
56
  def value
50
57
  assert_exists
51
58
  case @object.getTagName
@@ -56,53 +63,102 @@ module Celerity
56
63
  end
57
64
  end
58
65
  alias_method :get_contents, :value
59
-
66
+
67
+ #
60
68
  # Append the given value to the text in the text field.
69
+ #
70
+
61
71
  def append(value)
62
72
  assert_enabled
63
73
  assert_not_readonly
64
74
  type_string(value)
65
75
  end
76
+
66
77
 
67
78
  def type
68
79
  assert_exists
69
80
  type = @object.getAttributeValue('type')
70
-
71
- if ['file', 'radio', 'checkbox', 'submit', 'reset', 'image', 'button', 'hidden'].include?(type)
81
+
82
+ if NON_TEXT_TYPES.include?(type)
72
83
  type
73
84
  else
74
85
  'text'
75
86
  end
76
87
  end
77
88
 
89
+ #
78
90
  # This bascially just moves the text to the other text field using TextField#append
79
- # Should check if the HtmlUnit API supports some kind of dragging.
91
+ # TODO: check if HtmlUnit supports some kind of dragging.
92
+ #
93
+
80
94
  def drag_contents_to(how, what)
81
95
  assert_exists # assert_enabled?
82
96
  val = self.value
83
97
  self.value = ''
84
98
  @container.text_field(how, what).append(val)
85
99
  end
100
+
101
+ #
102
+ # Check if the given text fields contains the given String or Regexp.
103
+ #
104
+
105
+ def contains_text(expected_text)
106
+ assert_exists
107
+
108
+ case expected_text
109
+ when Regexp
110
+ value() =~ expected_text
111
+ when String
112
+ value().index(expected_text)
113
+ else
114
+ raise TypeError, "expected String or Regexp, got #{expected_text.inspect}:#{expected_text.class}"
115
+ end
116
+ end
117
+
118
+ #
119
+ # A boolean version of TextField#contains_text
120
+ # @param [String, Regexp] expected_text The text to look for.
121
+ # @return [boolean]
122
+ #
86
123
 
87
- # A boolean version of Element#contains_text :P
88
124
  def verify_contains(expected)
89
125
  # assert_exists called by contains_text
90
126
  !!contains_text(expected)
91
127
  end
92
-
93
- private
128
+
129
+ private
130
+
94
131
  def type_string(value)
95
- JavaString.new(value.to_java_bytes, @container.page.getPageEncoding).toCharArray.each do |char|
96
- @container.update_page @object.type(char)
132
+ java.lang.String.new(value.to_java_bytes, @container.page.getPageEncoding).toCharArray.each do |char|
133
+ @container.update_page @object.type(char)
97
134
  end
98
135
  end
99
- end
100
-
101
- # this class can be used to access hidden field objects
136
+
137
+ def insert_string(value)
138
+ case @object.getTagName
139
+ when 'textarea'
140
+ @object.setText(value)
141
+ when 'input'
142
+ @object.setValueAttribute(value)
143
+ else
144
+ raise "unknown tag name #{@object.getTagName.inspect} for #{self.class}"
145
+ end
146
+ end
147
+
148
+ end # TextField
149
+
150
+ #
151
+ # This class can be used to access hidden field objects
102
152
  # Normally a user would not need to create this object as it is returned by the Celerity::Container#hidden method
153
+ #
154
+
103
155
  class Hidden < TextField
104
- TAGS = [ Identifier.new('input', :type => %w(hidden)) ]
156
+ TAGS = [ Identifier.new('input', :type => %w[hidden]) ]
105
157
  DEFAULT_HOW = :name
158
+
159
+ def visible?
160
+ false
161
+ end
106
162
  end
107
-
108
- end
163
+
164
+ end # Celerity
@@ -1,41 +1,77 @@
1
- module Celerity
2
- module Exception
3
-
4
- # Superclass for all Celerity exceptions.
5
- class CelerityException < StandardError
6
- def initialize(message="")
7
- super(message)
8
- end
9
- end
10
-
11
- # This exception is thrown if an attempt is made to access an object that doesn't exist
12
- class UnknownObjectException < CelerityException; end
13
-
14
- # This exception is thrown if an attempt is made to access an object that is in a disabled state
15
- class ObjectDisabledException < CelerityException; end
16
-
17
- # This exception is thrown if an attempt is made to access a frame that cannot be found
18
- class UnknownFrameException < CelerityException; end
19
-
20
- # This exception is thrown if an attempt is made to access a form that cannot be found
21
- class UnknownFormException < CelerityException; end
22
-
23
- # This exception is thrown if an attempt is made to access an object that is in a read-only state
24
- class ObjectReadOnlyException < CelerityException; end
25
-
26
- # This exception is thrown if an attempt is made to access an object when the specified value cannot be found
27
- class NoValueFoundException < CelerityException; end
28
-
29
- # This exception gets raised if the how argument is wrong.
30
- class MissingWayOfFindingObjectException < CelerityException; end
31
-
32
- # This exception is raised if an attempt is made to access a table row that doesn't exist
33
- class UnknownRowException < CelerityException; end
34
-
35
- # This exception is raised if an attempt is made to access a table cell that doesn't exist
36
- class UnknownCellException < CelerityException; end
37
-
38
- # This exception is thrown if an http error, such as a 404, 500 etc is encountered while navigating
39
- class NavigationException < CelerityException; end
40
- end
41
- end
1
+ module Celerity
2
+ module Exception
3
+
4
+ #
5
+ # Superclass for all Celerity exceptions.
6
+ #
7
+
8
+ class CelerityException < StandardError; end
9
+
10
+ #
11
+ # This exception is thrown if an attempt is made to access an object that doesn't exist
12
+ #
13
+
14
+ class UnknownObjectException < CelerityException; end
15
+
16
+ #
17
+ # This exception is thrown if an attempt is made to access an object that is in a disabled state
18
+ #
19
+
20
+ class ObjectDisabledException < CelerityException; end
21
+
22
+ #
23
+ # This exception is thrown if an attempt is made to access a frame that cannot be found
24
+ #
25
+
26
+ class UnknownFrameException < CelerityException; end
27
+
28
+ #
29
+ # This exception is thrown if an attempt is made to access a form that cannot be found
30
+ #
31
+
32
+ class UnknownFormException < CelerityException; end
33
+
34
+ #
35
+ # This exception is thrown if an attempt is made to access an object that is in a read-only state
36
+ #
37
+
38
+ class ObjectReadOnlyException < CelerityException; end
39
+
40
+ #
41
+ # This exception is thrown if an attempt is made to access an object when the specified value cannot be found
42
+ #
43
+
44
+ class NoValueFoundException < CelerityException; end
45
+
46
+ #
47
+ # This exception gets raised if the how argument is wrong.
48
+ #
49
+
50
+ class MissingWayOfFindingObjectException < CelerityException; end
51
+
52
+ #
53
+ # This exception is raised if an attempt is made to access a table row that doesn't exist
54
+ #
55
+
56
+ class UnknownRowException < CelerityException; end
57
+
58
+ #
59
+ # This exception is raised if an attempt is made to access a table cell that doesn't exist
60
+ #
61
+
62
+ class UnknownCellException < CelerityException; end
63
+
64
+ #
65
+ # This exception is thrown if an http error, such as a 404, 500 etc is encountered while navigating
66
+ #
67
+
68
+ class NavigationException < CelerityException; end
69
+
70
+ #
71
+ # This exception is thrown if an unexpected content type is returned by the server.
72
+ #
73
+
74
+ class UnexpectedPageException < CelerityException; end
75
+
76
+ end # Exception
77
+ end # Celerity
@@ -16,15 +16,23 @@ class String # :nodoc:
16
16
  end
17
17
 
18
18
  module Celerity
19
- # Experimental
19
+
20
+ #
21
+ # Experimental - generate a method definition for accessing elements on the current page.
22
+ #
23
+ # Usage:
24
+ #
25
+ # MethodGenerator.new(browser, opts).parse
26
+ #
27
+ #
20
28
  class MethodGenerator
21
29
 
22
30
  ELEMENTS = %w[text_field select_list radio checkbox button].map { |e| e.to_sym }
23
31
  BUGGY_ELEMENTS = %w[radio checkbox].map { |e| e.to_sym }
24
-
32
+
25
33
  def initialize(ie, opts = {})
26
- @ie = ie
27
- @opts = opts
34
+ @ie = ie
35
+ @opts = opts
28
36
  @browser = @opts[:browser] || '@ie'
29
37
 
30
38
  @docs = " # Fills in the page at #{@ie.url}\n #\n"
@@ -33,7 +41,7 @@ module Celerity
33
41
 
34
42
  @method = " def #{@opts[:method_name] || 'generated_method'}(opts = {})\n\n"
35
43
  end
36
-
44
+
37
45
  def parse
38
46
  ELEMENTS.each do |elem|
39
47
  @method << " # buggy!\n" if BUGGY_ELEMENTS.include?(elem)
@@ -50,18 +58,19 @@ module Celerity
50
58
  @docs << " #\n"*2
51
59
  @docs + @method
52
60
  end
53
-
61
+
54
62
  private
55
-
63
+
56
64
  def add_elements(symbol)
57
65
  symbol = symbol.to_sym
58
- symbol_pluralized = symbol.to_s.pluralize.to_sym
66
+ symbol_pluralized = symbol.to_s.pluralize.to_sym
59
67
  @ie.send(symbol_pluralized).each_with_index do |elem, idx|
60
68
  self.send("add_#{symbol}".to_sym, elem, idx)
61
69
  end
70
+
62
71
  @method << "\n"
63
72
  end
64
-
73
+
65
74
  def add_text_field(elem, idx)
66
75
  how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
67
76
  @method << " #{@browser}.text_field(#{how.inspect}, #{what.inspect}).value = "
@@ -69,7 +78,7 @@ module Celerity
69
78
  @method << "opts[#{symbol}]\n"
70
79
  @doc_elements << [symbol, "value for text field #{what.inspect}"]
71
80
  end
72
-
81
+
73
82
  def add_select_list(elem, idx)
74
83
  how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
75
84
  @method << " #{@browser}.select_list(#{how.inspect}, #{what.inspect}).select("
@@ -77,38 +86,41 @@ module Celerity
77
86
  @method << "opts[#{symbol}])\n"
78
87
  @doc_elements << [symbol, "option to select for select list #{what.inspect}"]
79
88
  end
80
-
89
+
81
90
  def add_radio(elem, idx)
82
91
  how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
83
92
  @method << " #{@browser}.radio(#{how.inspect}, #{what.inspect}, "
93
+
84
94
  if (value = elem.value).empty?
85
95
  symbol = (how == :index) ? ":radio_#{what.underscore}" : ":#{what.underscore}"
86
96
  else
87
97
  symbol = ":#{what.underscore}_#{value.underscore}"
88
98
  @method << "#{value.inspect}).set if opts[#{symbol}]\n"
89
99
  end
100
+
90
101
  @doc_elements << [symbol, "set the radio with id/value #{what.inspect}"]
91
102
  end
92
-
103
+
93
104
  def add_checkbox(elem, idx)
94
105
  how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
95
106
  @method << " #{@browser}.checkbox(#{how.inspect}, #{what.inspect}, "
96
107
  symbol = (how == :index) ? ":checkbox_#{what.underscore}" : ":#{what.underscore}"
97
108
  @method << "#{elem.value.inspect}).set if opts[#{symbol}]\n"
109
+
98
110
  @doc_elements << [symbol, "set the checkbox with id/value #{what.inspect}"]
99
111
  end
100
-
112
+
101
113
  def add_button(elem, idx)
102
114
  how, what = find_identifier(elem) || [:index, (idx + 1).to_s]
103
115
  @method << " #{@browser}.button(#{how.inspect}, #{what.inspect}).click\n"
104
116
  end
105
-
117
+
106
118
  def add_link(elem, idx)
107
119
  if (href = elem.href) =~ /javascript/
108
120
  how, what = :index, (idx + 1).to_s
109
121
  else
110
122
  how = :url
111
-
123
+
112
124
  begin
113
125
  uri = URI.parse(href)
114
126
  what = Regexp.new(Regexp.escape(uri.to_s.sub(/.*#{uri.host}\//, '')))
@@ -118,24 +130,30 @@ module Celerity
118
130
  end
119
131
  @method << " #{@browser}.link(#{how.inspect}, #{what.inspect}).click\n"
120
132
  end
121
-
133
+
122
134
  def find_identifier(element)
123
- # could use these if they were 'weighted' ?
135
+ # could use ATTRIBUTES if they were 'weighted' somehow?
124
136
  attrs = element.class::ATTRIBUTES
125
137
  [:id, :name].each do |attribute|
126
138
  return [attribute, element.send(attribute)] if attrs.include?(attribute) && !element.send(attribute).empty?
127
139
  end
128
140
  nil
129
141
  end
130
-
142
+
131
143
  end # MethodGenerator
132
-
144
+
133
145
  class Browser
146
+
147
+ #
148
+ # Experimental - generate a method definition for accessing elements on the current page
149
+ # Not loaded by default - need to require 'celerity/extra/method_generator'
150
+ #
151
+
134
152
  def generate_method(opts = {})
135
153
  MethodGenerator.new(self, opts).parse
136
154
  end
137
- end
138
-
155
+
156
+ end # Browser
139
157
  end # Celerity
140
158
 
141
159
 
@@ -144,9 +162,9 @@ end # Celerity
144
162
  # require File.dirname(__FILE__) + "/../spec/spec_helper"
145
163
  # $stdout.sync = true
146
164
  # @ie = Browser.new
147
- # @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
148
- #
165
+ # @ie.goto(HTML_DIR + "/forms_with_input_elements.html")
166
+ #
149
167
  # puts MethodGenerator.new(@ie).parse
150
- # @ie.goto(TEST_HOST + "/forms3.html")
168
+ # @ie.goto(HTML_DIR + "/forms3.html")
151
169
  # puts MethodGenerator.new(@ie).parse
152
170
  # end