watir 3.0.0.rc2 → 3.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGES +19 -0
  2. data/VERSION +1 -1
  3. data/lib/watir/close_all.rb +2 -2
  4. data/lib/watir/container.rb +6 -4
  5. data/lib/watir/cookies.rb +80 -0
  6. data/lib/watir/core.rb +7 -3
  7. data/lib/watir/dialogs/file_field.rb +0 -4
  8. data/lib/watir/drag_and_drop_helper.rb +68 -0
  9. data/lib/watir/element.rb +58 -156
  10. data/lib/watir/element_collection.rb +109 -0
  11. data/lib/watir/form.rb +7 -14
  12. data/lib/watir/frame.rb +11 -26
  13. data/lib/watir/ie-class.rb +17 -307
  14. data/lib/watir/ie.rb +0 -9
  15. data/lib/watir/image.rb +8 -25
  16. data/lib/watir/input_elements.rb +32 -81
  17. data/lib/watir/link.rb +2 -17
  18. data/lib/watir/locator.rb +29 -25
  19. data/lib/watir/modal_dialog.rb +26 -40
  20. data/lib/watir/non_control_elements.rb +111 -79
  21. data/lib/watir/page-container.rb +12 -1
  22. data/lib/watir/supported_elements.rb +172 -0
  23. data/lib/watir/table.rb +61 -89
  24. data/lib/watir/win32ole.rb +2 -3
  25. data/lib/watir/win32ole/1.9.3/win32ole.so +0 -0
  26. data/lib/watir/xpath_locator.rb +52 -0
  27. data/rakefile.rb +1 -1
  28. data/unittests/checkbox_test.rb +22 -32
  29. data/unittests/css_selector_test.rb +1 -6
  30. data/unittests/css_test.rb +1 -4
  31. data/unittests/div_test.rb +3 -21
  32. data/unittests/document_standards.rb +0 -4
  33. data/unittests/element_collections_test.rb +2 -2
  34. data/unittests/element_test.rb +1 -1
  35. data/unittests/form_test.rb +0 -30
  36. data/unittests/frame_test.rb +8 -49
  37. data/unittests/ie_test.rb +5 -9
  38. data/unittests/images_test.rb +6 -6
  39. data/unittests/index_specifier_test.rb +0 -1
  40. data/unittests/js_events_test.rb +1 -1
  41. data/unittests/links_multi_test.rb +0 -14
  42. data/unittests/links_test.rb +8 -51
  43. data/unittests/lists_test.rb +0 -9
  44. data/unittests/navigate_test.rb +1 -1
  45. data/unittests/nbsp_xpath_test.rb +1 -1
  46. data/unittests/no_wait_test.rb +3 -3
  47. data/unittests/parent_child_test.rb +0 -17
  48. data/unittests/pre_test.rb +0 -3
  49. data/unittests/radios_test.rb +31 -42
  50. data/unittests/selectbox_test.rb +18 -21
  51. data/unittests/selectbox_xpath_test.rb +11 -26
  52. data/unittests/table_test.rb +14 -79
  53. data/unittests/textfields_test.rb +8 -47
  54. data/unittests/windows/attach_to_new_window_test.rb +0 -8
  55. data/unittests/windows/frame_links_test.rb +5 -5
  56. data/unittests/windows/ie-each_test.rb +1 -1
  57. data/unittests/windows/modal_dialog_test.rb +2 -2
  58. data/watir.gemspec +3 -3
  59. metadata +81 -126
  60. data/lib/watir/camel_case.rb +0 -67
  61. data/lib/watir/collections.rb +0 -48
  62. data/lib/watir/cookiemanager.rb +0 -56
  63. data/lib/watir/element_collections.rb +0 -81
  64. data/lib/watir/html_element.rb +0 -30
  65. data/unittests/defer_test.rb +0 -47
  66. data/unittests/multiple_specifiers_test.rb +0 -29
  67. data/unittests/table_and_tablerow_to_a_test.rb +0 -117
  68. data/unittests/windows/iedialog_test.rb +0 -53
@@ -1,82 +1,114 @@
1
1
  module Watir
2
+ class Area < Element
3
+ attr_ole :alt
4
+ attr_ole :type
5
+ attr_ole :href
6
+ end
7
+
8
+ class Audio < Element
9
+ attr_ole :src
10
+ end
11
+
12
+ class Base < Element
13
+ attr_ole :href
14
+ end
15
+
16
+ class Command < Element
17
+ attr_ole :disabled?
18
+ attr_ole :type
19
+ end
20
+
21
+ class Data < Element
22
+ attr_ole :value
23
+ end
24
+
25
+ class Embed < Element
26
+ attr_ole :src
27
+ attr_ole :type
28
+ end
29
+
30
+ class FieldSet < Element
31
+ attr_ole :name
32
+ attr_ole :disabled?
33
+ end
34
+
35
+ class Font < Element
36
+ attr_ole :color
37
+ attr_ole :face
38
+ attr_ole :size
39
+ end
40
+
41
+ class Keygen < Element
42
+ attr_ole :name
43
+ attr_ole :disabled?
44
+ end
45
+
46
+ class Label < Element
47
+ attr_ole :for, :htmlFor
48
+ end
49
+
50
+ class Li < Element
51
+ attr_ole :value
52
+ end
53
+
54
+ class Map < Element
55
+ attr_ole :name
56
+ end
57
+
58
+ class Menu < Element
59
+ attr_ole :type
60
+ end
61
+
62
+ class Meta < Element
63
+ attr_ole :http_equiv, :httpEquiv
64
+ attr_ole :content
65
+ attr_ole :name
66
+ end
67
+
68
+ class Meter < Element
69
+ attr_ole :value
70
+ end
71
+
72
+ class Object < Element
73
+ attr_ole :name
74
+ attr_ole :type
75
+ end
76
+
77
+ class Optgroup < Element
78
+ attr_ole :disabled?
79
+ end
80
+
81
+ class Output < Element
82
+ attr_ole :name
83
+ end
84
+
85
+ class Param < Element
86
+ attr_ole :name
87
+ attr_ole :value
88
+ end
89
+
90
+ class Progress < Element
91
+ attr_ole :value
92
+ end
93
+
94
+ class Script < Element
95
+ attr_ole :src
96
+ attr_ole :type
97
+ end
98
+
99
+ class Source < Element
100
+ attr_ole :type
101
+ end
102
+
103
+ class Style < Element
104
+ attr_ole :type
105
+ end
2
106
 
3
- # this class contains items that are common between the span, div, and pre objects
4
- # it would not normally be used directly
5
- #
6
- # many of the methods available to this object are inherited from the Element class
7
- #
8
- class NonControlElement < Element
9
- include Watir::Exception
10
-
11
- def initialize(container, how, what)
12
- set_container container
13
- @how = how
14
- @what = what
15
- super nil
16
- end
17
-
18
- # this method is used to populate the properties in the to_s method
19
- def span_div_string_creator
20
- n = []
21
- n << "class:".ljust(TO_S_SIZE) + self.class_name
22
- n << "text:".ljust(TO_S_SIZE) + self.text
23
- return n
24
- end
25
- private :span_div_string_creator
26
-
27
- # returns the properties of the object in a string
28
- # raises an ObjectNotFound exception if the object cannot be found
29
- def to_s
30
- assert_exists
31
- r = string_creator
32
- r += span_div_string_creator
33
- return r.join("\n")
34
- end
35
- end
36
-
37
- # Accesses Label element on the html page - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/label.asp?frame=true
38
- class Label < NonControlElement
39
- # this method is used to populate the properties in the to_s method
40
- def label_string_creator
41
- n = []
42
- n << "for:".ljust(TO_S_SIZE) + self.for
43
- n << "text:".ljust(TO_S_SIZE) + self.text
44
- return n
45
- end
46
- private :label_string_creator
47
-
48
- # returns the properties of the object in a string
49
- # raises an ObjectNotFound exception if the object cannot be found
50
- def to_s
51
- assert_exists
52
- r = string_creator
53
- r += label_string_creator
54
- return r.join("\n")
55
- end
56
- end
57
-
58
- class Ins < NonControlElement
59
- Watir::Container.module_eval do
60
- remove_method :inss
61
-
62
- def inses(how={}, what=nil)
63
- Inses.new(self, how, what)
64
- end
65
- end
66
- end
67
-
68
- class FieldSet < NonControlElement
69
- Watir::Container.module_eval do
70
- alias_method :fieldset, :field_set
71
- alias_method :fieldsets, :field_sets
72
- end
73
- end
74
-
75
- %w[Pre P Div Span Map Area Li Ul H1 H2 H3 H4 H5 H6
76
- Dl Dt Dd Strong Em Del Ol Body Meta Font Frameset].each do |elem|
77
- module_eval %Q{
78
- class #{elem} < NonControlElement; end
79
- }
80
- end
81
-
107
+ class Track < Element
108
+ attr_ole :src
109
+ end
110
+
111
+ class Video < Element
112
+ attr_ole :src
113
+ end
82
114
  end
@@ -33,6 +33,17 @@ module Watir
33
33
 
34
34
  private :page
35
35
 
36
+ # Execute the given JavaScript string
37
+ def execute_script(source)
38
+ document.parentWindow.eval(source.to_s)
39
+ rescue WIN32OLERuntimeError, NoMethodError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround
40
+ escaped_src = source.to_s.gsub(/[\r\n']/) {|m| "\\#{m}"}
41
+ wrapper = "_watir_helper_div_#{::Time.now.to_i + ::Time.now.usec}"
42
+ cmd = "var e = document.createElement('DIV'); e.style.display='none'; e.id='#{wrapper}'; e.innerHTML = eval('#{escaped_src}'); document.body.appendChild(e);"
43
+ document.parentWindow.execScript(cmd)
44
+ document.getElementById(wrapper).innerHTML
45
+ end
46
+
36
47
  # The HTML of the current page
37
48
  def html
38
49
  page.outerhtml
@@ -94,4 +105,4 @@ module Watir
94
105
  end
95
106
 
96
107
  end # module
97
- end
108
+ end
@@ -0,0 +1,172 @@
1
+ module Watir
2
+ module Container
3
+
4
+ class << self
5
+ def support_element method_name, args={}
6
+ klass = args[:class] || method_name.to_s.capitalize
7
+ super_class = args[:super_class] || "Element"
8
+
9
+ unless Watir.const_defined? klass
10
+ Watir.class_eval %Q[class #{klass} < #{super_class}; end]
11
+ end
12
+
13
+ unless Watir.const_defined? "#{klass}Collection"
14
+ Watir.class_eval %Q[class #{klass}Collection < #{args[:super_collection] || super_class}Collection; end]
15
+ end
16
+
17
+ tag_name = args[:tag_name] || method_name
18
+
19
+ Watir::Container.module_eval %Q[
20
+ def #{method_name}(how={}, what=nil)
21
+ #{klass}.new(self, format_specifiers(#{tag_name.inspect}, how, what))
22
+ end
23
+
24
+ def #{args.delete(:plural) || method_name.to_s + "s"}(how={}, what=nil)
25
+ specifiers = format_specifiers(#{tag_name.inspect}, how, what)
26
+ #{klass}Collection.new(self, specifiers)
27
+ end
28
+ ]
29
+ end
30
+
31
+ private :support_element
32
+ end
33
+
34
+ def format_specifiers(tag_name, how, what)
35
+ defaults = {:tag_name => [tag_name].flatten.map(&:to_s)}
36
+ formatted_specifiers = defaults.merge(what ? {how => what} : how)
37
+ if (formatted_specifiers[:css] || formatted_specifiers[:xpath]) && formatted_specifiers.size > 2
38
+ raise ArgumentError, ":xpath and :css specifiers should be the only one when used in #{formatted_specifiers.inspect}"
39
+ end
40
+ formatted_specifiers
41
+ end
42
+
43
+ private :format_specifiers
44
+
45
+ support_element :a, :class => :Link
46
+ alias_method :link, :a
47
+ alias_method :links, :as
48
+ support_element :abbr
49
+ support_element :address, :plural => :addresses
50
+ support_element :area
51
+ support_element :article
52
+ support_element :aside
53
+ support_element :audio
54
+ support_element :b
55
+ support_element :base
56
+ support_element :bdi
57
+ support_element :bdo
58
+ support_element :blockquote
59
+ support_element :body
60
+ support_element :br
61
+ support_element :button, :tag_name => [:button, :submit, :image, :reset], :super_class => :InputElement
62
+ support_element :canvas, :plural => :canvases
63
+ support_element :caption
64
+ support_element :checkbox, :plural => :checkboxes, :class => :CheckBox, :super_class => :InputElement
65
+ support_element :cite
66
+ support_element :code
67
+ support_element :col
68
+ support_element :colgroup
69
+ support_element :command
70
+ support_element :data
71
+ support_element :datalist
72
+ support_element :dd
73
+ support_element :del
74
+ support_element :details, :plural => :detailses
75
+ support_element :dfn
76
+ support_element :div
77
+ support_element :dl
78
+ support_element :dt
79
+ support_element :element, :tag_name => "*", :class => :HTMLElement
80
+ support_element :em
81
+ support_element :embed
82
+ support_element :fieldset, :class => :FieldSet
83
+ alias_method :field_set, :fieldset
84
+ alias_method :field_sets, :fieldsets
85
+ support_element :figcaption
86
+ support_element :figure
87
+ support_element :file_field, :tag_name => :file, :class => :FileField, :super_collection => :InputElement
88
+ support_element :font
89
+ support_element :footer
90
+ support_element :form
91
+ support_element :frame, :tag_name => [:frame, :iframe]
92
+ alias_method :iframe, :frame
93
+ alias_method :iframes, :frames
94
+ support_element :frameset
95
+ support_element :h1
96
+ support_element :h2
97
+ support_element :h3
98
+ support_element :h4
99
+ support_element :h5
100
+ support_element :h6
101
+ support_element :head
102
+ support_element :header
103
+ support_element :hgroup
104
+ support_element :hidden, :super_class => :TextField, :super_collection => :InputElement
105
+ support_element :hr
106
+ # html and htmls?!
107
+ support_element :i
108
+ support_element :img, :class => :Image
109
+ alias_method :image, :img
110
+ alias_method :images, :imgs
111
+ support_element :input, :super_class => :InputElement
112
+ support_element :ins, :plural => :inses
113
+ support_element :kbd
114
+ support_element :keygen
115
+ support_element :label
116
+ support_element :legend
117
+ support_element :li
118
+ support_element :map
119
+ support_element :mark
120
+ support_element :menu
121
+ support_element :meta
122
+ support_element :meter
123
+ support_element :nav
124
+ support_element :noscript
125
+ support_element :object
126
+ support_element :ol
127
+ support_element :optgroup
128
+ support_element :option
129
+ support_element :output
130
+ support_element :p
131
+ support_element :param
132
+ support_element :pre
133
+ support_element :progress, :plural => :progresses
134
+ support_element :q
135
+ support_element :radio, :super_class => :InputElement
136
+ support_element :rp
137
+ support_element :rt
138
+ support_element :ruby, :plural => :rubies
139
+ support_element :s
140
+ support_element :samp
141
+ support_element :script
142
+ support_element :section
143
+ support_element :select, :class => :SelectList, :super_class => :InputElement
144
+ alias_method :select_list, :select
145
+ alias_method :select_lists, :selects
146
+ support_element :small
147
+ support_element :source
148
+ support_element :span
149
+ support_element :strong
150
+ support_element :style
151
+ support_element :sub
152
+ support_element :summary, :plural => :summaries
153
+ support_element :sup
154
+ support_element :table
155
+ support_element :tbody, :class => :TableSection
156
+ support_element :td, :tag_name => [:th, :td], :class => :TableCell
157
+ support_element :text_field, :tag_name => [:text, :password, :textarea], :class => :TextField, :super_class => :InputElement
158
+ support_element :textarea, :class => :TextArea, :super_class => :TextField, :super_collection => :InputElement
159
+ support_element :tfoot, :class => :TableSection
160
+ support_element :th
161
+ support_element :thead, :class => :TableSection
162
+ support_element :time
163
+ support_element :title
164
+ support_element :tr, :class => :TableRow
165
+ support_element :track
166
+ support_element :u
167
+ support_element :ul
168
+ support_element :var
169
+ support_element :video
170
+ support_element :wbr
171
+ end
172
+ end
@@ -1,11 +1,11 @@
1
1
  module Watir
2
2
 
3
- module RowContainer
3
+ module TableContainer
4
4
  # Returns a row in the table
5
5
  # * index - the index of the row
6
6
  def [](index)
7
7
  assert_exists
8
- TableRow.new(self, :ole_object, @o.rows.item(index))
8
+ TableRow.new(self, :ole_object => @o.rows.item(index))
9
9
  end
10
10
 
11
11
  def strings
@@ -14,13 +14,51 @@ module Watir
14
14
  @o.rows.each do |row|
15
15
  cells_memo = []
16
16
  row.cells.each do |cell|
17
- cells_memo << TableCell.new(self, :ole_object, cell).text.gsub("\r\n","")
17
+ cells_memo << TableCell.new(self, :ole_object => cell).text.gsub("\r\n","")
18
18
  end
19
19
  rows_memo << cells_memo
20
20
  end
21
21
  rows_memo
22
22
  end
23
+ end
24
+
25
+ module TableElementsContainer
26
+ def table_elements(klass, tags, how, what, ole_collection)
27
+ specifiers = format_specifiers(tags, how, what)
28
+ klass.new(self, specifiers, ole_collection)
29
+ end
30
+
31
+ private :table_elements
32
+ end
33
+
34
+ module TableCellsContainer
35
+ include TableElementsContainer
36
+
37
+ def cells(how={}, what=nil)
38
+ assert_exists
39
+ table_elements(TableCellCollection, [:th, :td], how, what, @o.cells)
40
+ end
23
41
 
42
+ def cell(how={}, what=nil)
43
+ specifiers = format_specifiers([:th, :td], how, what)
44
+ index = specifiers.delete(:index) || 0
45
+ cells(specifiers)[index]
46
+ end
47
+ end
48
+
49
+ module TableRowsContainer
50
+ include TableElementsContainer
51
+
52
+ def rows(how={}, what=nil)
53
+ assert_exists
54
+ table_elements(TableRowCollection, [:tr], how, what, @o.rows)
55
+ end
56
+
57
+ def row(how={}, what=nil)
58
+ specifiers = format_specifiers([:tr], how, what)
59
+ index = specifiers.delete(:index) || 0
60
+ rows(specifiers)[index]
61
+ end
24
62
  end
25
63
 
26
64
  # This class is used for dealing with tables.
@@ -28,8 +66,12 @@ module Watir
28
66
  #
29
67
  # many of the methods available to this object are inherited from the Element class
30
68
  #
31
- class Table < NonControlElement
32
- include RowContainer
69
+ class Table < Element
70
+ include TableContainer
71
+ include TableRowsContainer
72
+ include TableCellsContainer
73
+
74
+ attr_ole :rules
33
75
 
34
76
  # override the highlight method, as if the tables rows are set to have a background color,
35
77
  # this will override the table background color, and the normal flash method won't work
@@ -76,14 +118,6 @@ module Watir
76
118
  return r.join("\n")
77
119
  end
78
120
 
79
- # iterates through the rows in the table. Yields a TableRow object
80
- def each
81
- assert_exists
82
- @o.rows.each do |row|
83
- yield TableRow.new(self, :ole_object, row)
84
- end
85
- end
86
-
87
121
  # Returns the number of rows inside the table, including rows in nested tables.
88
122
  def row_count
89
123
  assert_exists
@@ -95,7 +129,7 @@ module Watir
95
129
  # * index - the index of the row
96
130
  def column_count(index=0)
97
131
  assert_exists
98
- row[index].cells.length
132
+ rows[index].cells.length
99
133
  end
100
134
 
101
135
  # Returns an array containing all the text values in the specified column
@@ -119,7 +153,7 @@ module Watir
119
153
 
120
154
  headers = []
121
155
  @o.rows.item(0).cells.each do |cell|
122
- headers << TableCell.new(self, :ole_object, cell).text
156
+ headers << TableCell.new(self, :ole_object => cell).text
123
157
  end
124
158
 
125
159
  rows_memo = []
@@ -133,7 +167,7 @@ module Watir
133
167
 
134
168
  j = 0
135
169
  cells.each do |cell|
136
- cells_memo[headers[j]] = TableCell.new(self, :ole_object, cell).text
170
+ cells_memo[headers[j]] = TableCell.new(self, :ole_object => cell).text
137
171
  j += 1
138
172
  end
139
173
 
@@ -144,45 +178,15 @@ module Watir
144
178
  end
145
179
  end
146
180
 
147
- class TableSection < NonControlElement
148
- include RowContainer
149
-
150
- Watir::Container.module_eval do
151
- def tbody(how={}, what=nil)
152
- how = {how => what} if what
153
- TableSection.new(self, how.merge(:tag_name => "tbody"), nil)
154
- end
155
-
156
- def tbodys(how={}, what=nil)
157
- how = {how => what} if what
158
- TableSectionCollection.new(self, how.merge(:tag_name => "tbody"), nil)
159
- end
160
-
161
- def thead(how={}, what=nil)
162
- how = {how => what} if what
163
- TableSection.new(self, how.merge(:tag_name => "thead"), nil)
164
- end
165
-
166
- def theads(how={}, what=nil)
167
- how = {how => what} if what
168
- TableSectionCollection.new(self, how.merge(:tag_name => "thead"), nil)
169
- end
170
-
171
- def tfoot(how={}, what=nil)
172
- how = {how => what} if what
173
- TableSection.new(self, how.merge(:tag_name => "tfoot"), nil)
174
- end
175
-
176
- def tfoots(how={}, what=nil)
177
- how = {how => what} if what
178
- TableSectionCollection.new(self, how.merge(:tag_name => "tfoot"), nil)
179
- end
180
- end
181
+ class TableSection < Element
182
+ include TableContainer
183
+ include TableRowsContainer
184
+ include TableCellsContainer
181
185
  end
182
186
 
183
- class TableRow < NonControlElement
184
- TAG = "TR"
185
-
187
+ class TableRow < Element
188
+ include TableCellsContainer
189
+
186
190
  # this method iterates through each of the cells in the row. Yields a TableCell object
187
191
  def each
188
192
  locate
@@ -198,55 +202,23 @@ module Watir
198
202
  return cells[index]
199
203
  end
200
204
 
201
- # defaults all missing methods to the array of elements, to be able to
202
- # use the row as an array
203
- # def method_missing(aSymbol, *args)
204
- # return @o.send(aSymbol, *args)
205
- # end
206
205
  def column_count
207
- locate
206
+ assert_exists
208
207
  cells.length
209
208
  end
210
209
 
211
- Watir::Container.module_eval do
212
- def row(how={}, what=nil)
213
- TableRow.new(self, how, what)
214
- end
215
-
216
- alias_method :tr, :row
217
-
218
- def rows(how={}, what=nil)
219
- TableRows.new(self, how, what)
220
- end
221
-
222
- alias_method :trs, :rows
223
- end
224
210
  end
225
211
 
226
212
  # this class is a table cell - when called via the Table object
227
- class TableCell < NonControlElement
228
- TAGS = ["TH", "TD"]
213
+ class TableCell < Element
214
+ attr_ole :headers
229
215
 
230
- alias to_s text
216
+ alias_method :to_s, :text
231
217
 
232
218
  def colspan
233
219
  locate
234
220
  @o.colSpan
235
221
  end
236
-
237
- Watir::Container.module_eval do
238
- def cell(how={}, what=nil)
239
- TableCell.new(self, how, what)
240
- end
241
-
242
- alias_method :td, :cell
243
-
244
- def cells(how={}, what=nil)
245
- TableCells.new(self, how, what)
246
- end
247
-
248
- alias_method :tds, :cells
249
- end
250
222
  end
251
223
 
252
224
  end