watir 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ module Watir
2
+ # POPUP object
3
+ class PopUp
4
+ def initialize(container)
5
+ @container = container
6
+ @page_container = container.page_container
7
+ end
8
+
9
+ def button(caption)
10
+ return JSButton.new(@container.getIE.hwnd, caption)
11
+ end
12
+ end
13
+
14
+ class JSButton
15
+ def initialize(hWnd, caption)
16
+ @hWnd = hWnd
17
+ @caption = caption
18
+ end
19
+
20
+ def startClicker(waitTime=3)
21
+ clicker = WinClicker.new
22
+ clicker.clickJSDialog_Thread
23
+ # clickerThread = Thread.new(@caption) {
24
+ # sleep waitTime
25
+ # puts "After the wait time in startClicker"
26
+ # clickWindowsButton_hwnd(hwnd, buttonCaption)
27
+ #}
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,356 @@
1
+ module Watir
2
+
3
+ # This class is used for dealing with tables.
4
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#table method
5
+ #
6
+ # many of the methods available to this object are inherited from the Element class
7
+ #
8
+ class Table < Element
9
+ include Container
10
+
11
+ # Returns the table object containing anElement
12
+ # * container - an instance of an IE object
13
+ # * anElement - a Watir object (TextField, Button, etc.)
14
+ def Table.create_from_element(container, anElement)
15
+ anElement.locate if defined?(anElement.locate)
16
+ o = anElement.ole_object.parentElement
17
+ o = o.parentElement until o.tagName == 'TABLE'
18
+ new container, :ole_object, o
19
+ end
20
+
21
+ # Returns an initialized instance of a table object
22
+ # * container - the container
23
+ # * how - symbol - how we access the table
24
+ # * what - what we use to access the table - id, name index etc
25
+ def initialize(container, how, what)
26
+ set_container container
27
+ @how = how
28
+ @what = what
29
+ super nil
30
+ end
31
+
32
+ def locate
33
+ if @how == :xpath
34
+ @o = @container.element_by_xpath(@what)
35
+ elsif @how == :ole_object
36
+ @o = @what
37
+ else
38
+ @o = @container.locate_tagged_element('TABLE', @how, @what)
39
+ end
40
+ end
41
+
42
+ # override the highlight method, as if the tables rows are set to have a background color,
43
+ # this will override the table background color, and the normal flash method won't work
44
+ def highlight(set_or_clear)
45
+
46
+ if set_or_clear == :set
47
+ begin
48
+ @original_border = @o.border.to_i
49
+ if @o.border.to_i==1
50
+ @o.border = 2
51
+ else
52
+ @o.border = 1
53
+ end
54
+ rescue
55
+ @original_border = nil
56
+ end
57
+ else
58
+ begin
59
+ @o.border= @original_border unless @original_border == nil
60
+ @original_border = nil
61
+ rescue
62
+ # we could be here for a number of reasons...
63
+ ensure
64
+ @original_border = nil
65
+ end
66
+ end
67
+ super
68
+ end
69
+
70
+ # this method is used to populate the properties in the to_s method
71
+ def table_string_creator
72
+ n = []
73
+ n << "rows:".ljust(TO_S_SIZE) + self.row_count.to_s
74
+ n << "cols:".ljust(TO_S_SIZE) + self.column_count.to_s
75
+ return n
76
+ end
77
+ private :table_string_creator
78
+
79
+ # returns the properties of the object in a string
80
+ # raises an ObjectNotFound exception if the object cannot be found
81
+ def to_s
82
+ assert_exists
83
+ r = string_creator
84
+ r += table_string_creator
85
+ return r.join("\n")
86
+ end
87
+
88
+ # iterates through the rows in the table. Yields a TableRow object
89
+ def each
90
+ assert_exists
91
+ 1.upto(@o.getElementsByTagName("TR").length) { |i| yield TableRow.new(@container, :ole_object, row(i)) }
92
+ end
93
+
94
+ # Returns a row in the table
95
+ # * index - the index of the row
96
+ def [](index)
97
+ assert_exists
98
+ return TableRow.new(@container, :ole_object, row(index))
99
+ end
100
+
101
+ # This method returns the number of rows in the table.
102
+ # Raises an UnknownObjectException if the table doesnt exist.
103
+ def row_count
104
+ assert_exists
105
+ #return table_body.children.length
106
+ return @o.getElementsByTagName("TR").length
107
+ end
108
+
109
+ # This method returns the number of columns in a row of the table.
110
+ # Raises an UnknownObjectException if the table doesn't exist.
111
+ # * index - the index of the row
112
+ def column_count(index=1)
113
+ assert_exists
114
+ row(index).cells.length
115
+ end
116
+
117
+ # This method returns the table as a 2 dimensional array. Dont expect too much if there are nested tables, colspan etc.
118
+ # Raises an UnknownObjectException if the table doesn't exist.
119
+ # http://www.w3.org/TR/html4/struct/tables.html
120
+ def to_a
121
+ assert_exists
122
+ y = []
123
+ table_rows = @o.getElementsByTagName("TR")
124
+ for row in table_rows
125
+ x = []
126
+ for td in row.getElementsbyTagName("TD")
127
+ x << td.innerText.strip
128
+ end
129
+ y << x
130
+ end
131
+ return y
132
+ end
133
+
134
+ def table_body(index=1)
135
+ return @o.getElementsByTagName('TBODY')[index]
136
+ end
137
+ private :table_body
138
+
139
+ # returns a watir object
140
+ def body(how, what)
141
+ return TableBody.new(@container, how, what, self)
142
+ end
143
+
144
+ # returns a watir object
145
+ def bodies
146
+ assert_exists
147
+ return TableBodies.new(@container, @o)
148
+ end
149
+
150
+ # returns an ole object
151
+ def row(index)
152
+ return @o.invoke("rows")[(index-1).to_s]
153
+ end
154
+ private :row
155
+
156
+ # Returns an array containing all the text values in the specified column
157
+ # Raises an UnknownCellException if the specified column does not exist in every
158
+ # Raises an UnknownObjectException if the table doesn't exist.
159
+ # row of the table
160
+ # * columnnumber - column index to extract values from
161
+ def column_values(columnnumber)
162
+
163
+ return(1..row_count).collect {|idx| self[idx][columnnumber].text}
164
+ end
165
+
166
+ # Returns an array containing all the text values in the specified row
167
+ # Raises an UnknownObjectException if the table doesn't exist.
168
+ # * rownumber - row index to extract values from
169
+ def row_values(rownumber)
170
+ return(1..column_count(rownumber)).collect {|idx| self[rownumber][idx].text}
171
+ end
172
+
173
+ end
174
+
175
+ # this class is a collection of the table body objects that exist in the table
176
+ # it wouldnt normally be created by a user, but gets returned by the bodies method of the Table object
177
+ # many of the methods available to this object are inherited from the Element class
178
+ #
179
+ class TableBodies < Element
180
+ def initialize(container, parent_table)
181
+ set_container container
182
+ @o = parent_table # in this case, @o is the parent table
183
+ end
184
+
185
+ # returns the number of TableBodies that exist in the table
186
+ def length
187
+ assert_exists
188
+ return @o.tBodies.length
189
+ end
190
+
191
+ # returns the n'th Body as a Watir TableBody object
192
+ def []n
193
+ assert_exists
194
+ return TableBody.new(@container, :ole_object, ole_table_body_at_index(n))
195
+ end
196
+
197
+ # returns an ole table body
198
+ def ole_table_body_at_index(n)
199
+ return @o.tBodies[(n-1).to_s]
200
+ end
201
+
202
+ # iterates through each of the TableBodies in the Table. Yields a TableBody object
203
+ def each
204
+ 1.upto(@o.tBodies.length) { |i| yield TableBody.new(@container, :ole_object, ole_table_body_at_index(i)) }
205
+ end
206
+
207
+ end
208
+
209
+ # this class is a table body
210
+ class TableBody < Element
211
+ def locate
212
+ @o = nil
213
+ if @how == :ole_object
214
+ @o = @what # in this case, @o is the table body
215
+ elsif @how == :index
216
+ @o = @parent_table.bodies.ole_table_body_at_index(@what)
217
+ end
218
+ @rows = []
219
+ if @o
220
+ @o.rows.each do |oo|
221
+ @rows << TableRow.new(@container, :ole_object, oo)
222
+ end
223
+ end
224
+ end
225
+
226
+ def initialize(container, how, what, parent_table=nil)
227
+ set_container container
228
+ @how = how
229
+ @what = what
230
+ @parent_table = parent_table
231
+ super nil
232
+ end
233
+
234
+ # returns the specified row as a TableRow object
235
+ def [](n)
236
+ assert_exists
237
+ return @rows[n - 1]
238
+ end
239
+
240
+ # iterates through all the rows in the table body
241
+ def each
242
+ locate
243
+ 0.upto(@rows.length - 1) { |i| yield @rows[i] }
244
+ end
245
+
246
+ # returns the number of rows in this table body.
247
+ def length
248
+ return @rows.length
249
+ end
250
+ end
251
+
252
+
253
+ # this class is a table row
254
+ class TableRow < Element
255
+
256
+ def locate
257
+ @o = nil
258
+ if @how == :ole_object
259
+ @o = @what
260
+ elsif @how == :xpath
261
+ @o = @container.element_by_xpath(@what)
262
+ else
263
+ @o = @container.locate_tagged_element("TR", @how, @what)
264
+ end
265
+ if @o # cant call the assert_exists here, as an exists? method call will fail
266
+ @cells = []
267
+ @o.cells.each do |oo|
268
+ @cells << TableCell.new(@container, :ole_object, oo)
269
+ end
270
+ end
271
+ end
272
+
273
+ # Returns an initialized instance of a table row
274
+ # * o - the object contained in the row
275
+ # * container - an instance of an IE object
276
+ # * how - symbol - how we access the row
277
+ # * what - what we use to access the row - id, index etc. If how is :ole_object then what is a Internet Explorer Raw Row
278
+ def initialize(container, how, what)
279
+ set_container container
280
+ @how = how
281
+ @what = what
282
+ super nil
283
+ end
284
+
285
+ # this method iterates through each of the cells in the row. Yields a TableCell object
286
+ def each
287
+ locate
288
+ 0.upto(@cells.length-1) { |i| yield @cells[i] }
289
+ end
290
+
291
+ # Returns an element from the row as a TableCell object
292
+ def [](index)
293
+ assert_exists
294
+ raise UnknownCellException, "Unable to locate a cell at index #{index}" if @cells.length < index
295
+ return @cells[(index - 1)]
296
+ end
297
+
298
+ # defaults all missing methods to the array of elements, to be able to
299
+ # use the row as an array
300
+ # def method_missing(aSymbol, *args)
301
+ # return @o.send(aSymbol, *args)
302
+ # end
303
+
304
+ def column_count
305
+ locate
306
+ @cells.length
307
+ end
308
+ end
309
+
310
+ # this class is a table cell - when called via the Table object
311
+ class TableCell < Element
312
+ include Watir::Exception
313
+ include Container
314
+
315
+ def locate
316
+ if @how == :xpath
317
+ @o = @container.element_by_xpath(@what)
318
+ elsif @how == :ole_object
319
+ @o = @what
320
+ else
321
+ @o = @container.locate_tagged_element("TD", @how, @what)
322
+ end
323
+ end
324
+
325
+ # Returns an initialized instance of a table cell
326
+ # * container - an IE object
327
+ # * how - symbol - how we access the cell
328
+ # * what - what we use to access the cell - id, name index etc
329
+ def initialize(container, how, what)
330
+ set_container container
331
+ @how = how
332
+ @what = what
333
+ super nil
334
+ end
335
+
336
+ def ole_inner_elements
337
+ locate
338
+ return @o.all
339
+ end
340
+ private :ole_inner_elements
341
+
342
+ def document
343
+ locate
344
+ return @o
345
+ end
346
+
347
+ alias to_s text
348
+
349
+ def colspan
350
+ locate
351
+ @o.colSpan
352
+ end
353
+
354
+ end
355
+
356
+ end
@@ -0,0 +1,29 @@
1
+ module Watir
2
+ module Win32
3
+ # this will find the IEDialog.dll file in its build location
4
+ @@iedialog_file = (File.expand_path(File.dirname(__FILE__) + '/..') + "/watir/IEDialog/Release/IEDialog.dll").gsub('/', '\\')
5
+
6
+ GetUnknown = Win32API.new(@@iedialog_file, 'GetUnknown', ['l', 'p'], 'v')
7
+ User32 = DL.dlopen('user32')
8
+ FindWindowEx = User32['FindWindowEx', 'LLLpp']
9
+ # method for this found in wet-winobj/wet/winobjects/WinUtils.rb
10
+ GetWindow = User32['GetWindow', 'ILL']
11
+
12
+ ## GetWindows Constants
13
+ GW_HWNDFIRST = 0
14
+ GW_HWNDLAST = 1
15
+ GW_HWNDNEXT = 2
16
+ GW_HWNDPREV = 3
17
+ GW_OWNER = 4
18
+ GW_CHILD = 5
19
+ GW_ENABLEDPOPUP = 6
20
+ GW_MAX = 6
21
+
22
+ IsWindow = User32['IsWindow', 'II']
23
+ # Does the window with the specified window handle (hwnd) exist?
24
+ def self.window_exists? hwnd
25
+ rtn, junk = IsWindow[hwnd]
26
+ rtn == 1
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: watir
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.5.2
7
- date: 2007-09-03 00:00:00 -05:00
6
+ version: 1.5.3
7
+ date: 2007-10-22 00:00:00 -05:00
8
8
  summary: Automated testing tool for web applications.
9
9
  require_paths:
10
10
  - .
@@ -31,24 +31,42 @@ authors:
31
31
  files:
32
32
  - watir.rb
33
33
  - watir/assertions.rb
34
+ - watir/bonus-elements.rb
34
35
  - watir/camel_case.rb
35
36
  - watir/clickJSDialog.rb
36
37
  - watir/close_all.rb
38
+ - watir/collections.rb
39
+ - watir/container.rb
37
40
  - watir/cookiemanager.rb
38
41
  - watir/datahandler.rb
39
42
  - watir/dialog.rb
40
- - watir/elements.rb
43
+ - watir/element.rb
44
+ - watir/element_collections.rb
41
45
  - watir/exceptions.rb
46
+ - watir/form.rb
47
+ - watir/frame.rb
42
48
  - watir/ie-process.rb
49
+ - watir/ie.rb
50
+ - watir/image.rb
51
+ - watir/input_elements.rb
43
52
  - watir/irb-history.rb
53
+ - watir/link.rb
54
+ - watir/locator.rb
55
+ - watir/logger.rb
56
+ - watir/modal_dialog.rb
57
+ - watir/non_control_elements.rb
58
+ - watir/page-container.rb
59
+ - watir/popup.rb
44
60
  - watir/process.rb
45
61
  - watir/screen_capture.rb
46
62
  - watir/setFileDialog.rb
63
+ - watir/table.rb
47
64
  - watir/testcase.rb
48
65
  - watir/testUnitAddons.rb
49
66
  - watir/utils.rb
50
67
  - watir/waiter.rb
51
68
  - watir/watir_simple.rb
69
+ - watir/win32.rb
52
70
  - watir/win32ole.rb
53
71
  - watir/winClicker.rb
54
72
  - watir/WindowHelper.rb