firewatir 1.6.2 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +32 -0
- data/lib/firewatir.rb +40 -50
- data/lib/firewatir/container.rb +491 -534
- data/lib/firewatir/document.rb +239 -0
- data/lib/firewatir/element.rb +1365 -0
- data/lib/firewatir/element_collections.rb +314 -0
- data/lib/firewatir/elements/button.rb +15 -0
- data/lib/firewatir/elements/file_field.rb +29 -0
- data/lib/firewatir/elements/form.rb +40 -0
- data/lib/firewatir/elements/frame.rb +55 -0
- data/lib/firewatir/elements/hidden.rb +56 -0
- data/lib/firewatir/elements/image.rb +139 -0
- data/lib/firewatir/elements/input_element.rb +44 -0
- data/lib/firewatir/elements/link.rb +76 -0
- data/lib/firewatir/elements/non_control_element.rb +53 -0
- data/lib/firewatir/elements/non_control_elements.rb +108 -0
- data/lib/firewatir/elements/not_used.rb +278 -0
- data/lib/firewatir/elements/option.rb +131 -0
- data/lib/firewatir/elements/radio_check_common.rb +163 -0
- data/lib/firewatir/elements/select_list.rb +188 -0
- data/lib/firewatir/elements/table.rb +218 -0
- data/lib/firewatir/elements/table_cell.rb +54 -0
- data/lib/firewatir/elements/table_row.rb +100 -0
- data/lib/firewatir/elements/text_field.rb +218 -0
- data/lib/firewatir/exceptions.rb +10 -10
- data/lib/firewatir/firefox.rb +1040 -1127
- data/lib/firewatir/jssh_socket.rb +101 -0
- data/lib/firewatir/version.rb +5 -5
- data/unittests/attach_to_new_window_test.rb +49 -42
- data/unittests/bug_fixes_test.rb +195 -198
- data/unittests/buttons_xpath_test.rb +88 -88
- data/unittests/checkbox_test.rb +158 -155
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/div_test.rb +275 -276
- data/unittests/filefield_test.rb +49 -45
- data/unittests/filefield_xpath_test.rb +35 -35
- data/unittests/form_test.rb +296 -308
- data/unittests/frame_test.rb +159 -152
- data/unittests/hidden_test.rb +85 -85
- data/unittests/hidden_xpath_test.rb +72 -72
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +61 -61
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/div.html +72 -72
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +45 -45
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/iframeTest.html +14 -14
- data/unittests/html/iframeTest1.html +13 -13
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/links1.html +42 -42
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +1 -0
- data/unittests/html/new_browser_popup.html +8 -0
- data/unittests/html/pass.html +9 -9
- data/unittests/html/pre.html +27 -27
- data/unittests/html/redirect.html +10 -10
- data/unittests/html/redirect1.html +8 -8
- data/unittests/html/redirect2.html +8 -8
- data/unittests/html/redirect3.html +8 -8
- data/unittests/html/simple_table_columns.html +74 -74
- data/unittests/html/table1.html +165 -165
- data/unittests/html/textfields1.html +62 -62
- data/unittests/images_test.rb +198 -205
- data/unittests/images_xpath_test.rb +118 -119
- data/unittests/javascript_test.rb +75 -75
- data/unittests/links_test.rb +231 -232
- data/unittests/links_xpath_test.rb +79 -79
- data/unittests/mozilla_all_tests.rb +7 -7
- data/unittests/pre_test.rb +75 -76
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/redirect_test.rb +41 -41
- data/unittests/selectbox_test.rb +142 -142
- data/unittests/selectbox_xpath_test.rb +129 -129
- data/unittests/setup.rb +29 -30
- data/unittests/table_test.rb +385 -373
- data/unittests/table_xpath_test.rb +185 -185
- data/unittests/textfields_test.rb +234 -233
- data/unittests/textfields_xpath_test.rb +113 -113
- metadata +33 -11
- data/lib/firewatir/MozillaBaseElement.rb +0 -1863
- data/lib/firewatir/htmlelements.rb +0 -1911
- data/unittests/iostring.rb +0 -30
- data/unittests/iostring_test.rb +0 -48
data/LICENSE
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
---------------------------------------------------------------------------
|
2
|
+
Copyright (c) 2004 - 2005, Paul Rogers and Bret Pettichord
|
3
|
+
Copyright (c) 2006 - 2007, Angrez Singh
|
4
|
+
Copyright (c) 2008, Bret Pettichord
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer in the
|
14
|
+
documentation and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the names Angrez Singh nor the names of contributors to
|
17
|
+
this software may be used to endorse or promote products derived from this
|
18
|
+
software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
21
|
+
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
23
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
24
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
25
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
26
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
27
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
28
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
29
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
30
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
--------------------------------------------------------------------------
|
32
|
+
(based on BSD Open Source License)
|
data/lib/firewatir.rb
CHANGED
@@ -1,50 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
require 'firewatir/MozillaBaseElement'
|
42
|
-
require 'firewatir/htmlelements'
|
43
|
-
require 'watir/matches'
|
44
|
-
require 'firewatir/firefox'
|
45
|
-
require 'firewatir/version'
|
46
|
-
require 'watir'
|
47
|
-
|
48
|
-
# this only has an effect if firewatir is required before anyone invokes
|
49
|
-
# Browser.new. Thus it has no effect when Browser.new itself autoloads this library.
|
50
|
-
Watir::Browser.default = 'firefox'
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'active_support'
|
5
|
+
|
6
|
+
require 'firewatir/exceptions'
|
7
|
+
require 'firewatir/jssh_socket'
|
8
|
+
require 'firewatir/container'
|
9
|
+
require "firewatir/element"
|
10
|
+
require "firewatir/document"
|
11
|
+
|
12
|
+
require "firewatir/elements/form"
|
13
|
+
require "firewatir/elements/frame"
|
14
|
+
require "firewatir/elements/non_control_element"
|
15
|
+
require "firewatir/elements/non_control_elements"
|
16
|
+
require "firewatir/elements/table"
|
17
|
+
require "firewatir/elements/table_row"
|
18
|
+
require "firewatir/elements/table_cell"
|
19
|
+
require "firewatir/elements/image"
|
20
|
+
require "firewatir/elements/link"
|
21
|
+
require "firewatir/elements/input_element"
|
22
|
+
require "firewatir/elements/select_list"
|
23
|
+
require "firewatir/elements/option"
|
24
|
+
require "firewatir/elements/button"
|
25
|
+
require "firewatir/elements/text_field"
|
26
|
+
require "firewatir/elements/hidden"
|
27
|
+
require "firewatir/elements/file_field"
|
28
|
+
require "firewatir/elements/radio_check_common"
|
29
|
+
require "firewatir/element_collections"
|
30
|
+
|
31
|
+
require 'watir/matches'
|
32
|
+
require 'firewatir/firefox'
|
33
|
+
require 'firewatir/version'
|
34
|
+
require 'watir'
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
# this only has an effect if firewatir is required before anyone invokes
|
39
|
+
# Browser.new. Thus it has no effect when Browser.new itself autoloads this library.
|
40
|
+
Watir::Browser.default = 'firefox'
|
data/lib/firewatir/container.rb
CHANGED
@@ -1,534 +1,491 @@
|
|
1
|
-
=begin
|
2
|
-
#
|
3
|
-
# This module contains the factory methods that are used to access most html objects
|
4
|
-
#
|
5
|
-
# For example, to access a button on a web page that has the following html
|
6
|
-
# <input type = button name= 'b1' value='Click Me' onClick='javascript:doSomething()'>
|
7
|
-
#
|
8
|
-
# the following Firewatir code could be used
|
9
|
-
#
|
10
|
-
# ff.button(:name, 'b1').click
|
11
|
-
#
|
12
|
-
# or
|
13
|
-
#
|
14
|
-
# ff.button(:value, 'Click Me').to_s
|
15
|
-
#
|
16
|
-
# One can use any attribute to uniquely identify an element including the user defined attributes
|
17
|
-
# that is rendered on the HTML screen. Though, Attribute used to access an element depends on the type of element,
|
18
|
-
# attributes used frequently to address an element are listed below
|
19
|
-
#
|
20
|
-
# :index - find the item using the index in the container ( a container can be a document,
|
21
|
-
# a TableCell, a Span, a Div or a P)
|
22
|
-
# index is 1 based
|
23
|
-
# :name - find the item using the name attribute
|
24
|
-
# :id - find the item using the id attribute
|
25
|
-
# :value - find the item using the value attribute
|
26
|
-
# :caption - same as value
|
27
|
-
# :xpath - finds the item using xpath query
|
28
|
-
#
|
29
|
-
# Typical Usage
|
30
|
-
#
|
31
|
-
# ff.button(:id, 'b_1') # access the button with an ID of b_1
|
32
|
-
# ff.button(:name, 'verify_data') # access the button with a name of verify_data
|
33
|
-
# ff.button(:value, 'Login') # access the button with a value (the text displayed on the button) of Login
|
34
|
-
# ff.button(:caption, 'Login') # same as above
|
35
|
-
# ff.button(:value, /Log/) # access the button that has text matching /Log/
|
36
|
-
# ff.button(:index, 2) # access the second button on the page ( 1 based, so the first button is accessed with :index,1)
|
37
|
-
#
|
38
|
-
=end
|
39
|
-
|
40
|
-
require 'firewatir/exceptions'
|
41
|
-
|
42
|
-
module FireWatir
|
43
|
-
module Container
|
44
|
-
include FireWatir
|
45
|
-
include Watir::Exception
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
#
|
126
|
-
#
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
#
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
#
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
#
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
#
|
235
|
-
#
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
#
|
256
|
-
#
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
#
|
263
|
-
#
|
264
|
-
#
|
265
|
-
#
|
266
|
-
#
|
267
|
-
#
|
268
|
-
#
|
269
|
-
#
|
270
|
-
#
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
#
|
277
|
-
#
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
#
|
298
|
-
#
|
299
|
-
#
|
300
|
-
#
|
301
|
-
#
|
302
|
-
#
|
303
|
-
#
|
304
|
-
#
|
305
|
-
#
|
306
|
-
#
|
307
|
-
#
|
308
|
-
#
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
#
|
315
|
-
#
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
#
|
321
|
-
#
|
322
|
-
#
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
#
|
329
|
-
#
|
330
|
-
#
|
331
|
-
#
|
332
|
-
#
|
333
|
-
#
|
334
|
-
#
|
335
|
-
#
|
336
|
-
#
|
337
|
-
#
|
338
|
-
#
|
339
|
-
#
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
#
|
346
|
-
#
|
347
|
-
#
|
348
|
-
#
|
349
|
-
#
|
350
|
-
#
|
351
|
-
#
|
352
|
-
#
|
353
|
-
#
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
#
|
360
|
-
#
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
#
|
367
|
-
#
|
368
|
-
#
|
369
|
-
#
|
370
|
-
#
|
371
|
-
#
|
372
|
-
#
|
373
|
-
#
|
374
|
-
#
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
#
|
381
|
-
#
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
#
|
389
|
-
#
|
390
|
-
#
|
391
|
-
#
|
392
|
-
#
|
393
|
-
#
|
394
|
-
#
|
395
|
-
#
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
#
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
#
|
410
|
-
|
411
|
-
|
412
|
-
#
|
413
|
-
#
|
414
|
-
#
|
415
|
-
#
|
416
|
-
#
|
417
|
-
#
|
418
|
-
#
|
419
|
-
#
|
420
|
-
#
|
421
|
-
#
|
422
|
-
#
|
423
|
-
#
|
424
|
-
#
|
425
|
-
def
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
#
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
def
|
455
|
-
|
456
|
-
end
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
#
|
461
|
-
#
|
462
|
-
#
|
463
|
-
#
|
464
|
-
#
|
465
|
-
#
|
466
|
-
#
|
467
|
-
#
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
end
|
493
|
-
|
494
|
-
# If received data is less than 1024 characters or for last data
|
495
|
-
# we read in the above loop
|
496
|
-
#return_value += data
|
497
|
-
|
498
|
-
# Get the command prompt inserted by JSSH
|
499
|
-
#s = Kernel.select([socket] , nil , nil, 0.3)
|
500
|
-
|
501
|
-
#if(s != nil)
|
502
|
-
# for stream in s[0]
|
503
|
-
# return_value += socket.recv(1024)
|
504
|
-
# end
|
505
|
-
#end
|
506
|
-
|
507
|
-
length = return_value.length
|
508
|
-
#puts "Return value before removing command prompt is : #{return_value}"
|
509
|
-
|
510
|
-
#Remove the command prompt. Every result returned by JSSH has "\n> " at the end.
|
511
|
-
if length <= 3
|
512
|
-
return_value = ""
|
513
|
-
elsif(return_value[0..2] == "\n> ")
|
514
|
-
return_value = return_value[3..length-1]
|
515
|
-
else
|
516
|
-
#return_value = return_value[0..length-3]
|
517
|
-
return_value = return_value[0..length-4]
|
518
|
-
end
|
519
|
-
#puts "Return value after removing command prompt is : #{return_value}"
|
520
|
-
#socket.flush
|
521
|
-
|
522
|
-
# make sure that command prompt doesn't get there.
|
523
|
-
if(return_value[return_value.length - 3..return_value.length - 1] == "\n> ")
|
524
|
-
return_value = return_value[0..return_value.length - 4]
|
525
|
-
end
|
526
|
-
if(return_value[0..2] == "\n> ")
|
527
|
-
return_value = return_value[3..return_value.length - 1]
|
528
|
-
end
|
529
|
-
#puts "return value is : #{return_value}"
|
530
|
-
return return_value
|
531
|
-
end
|
532
|
-
end
|
533
|
-
end # module
|
534
|
-
|
1
|
+
=begin
|
2
|
+
#
|
3
|
+
# This module contains the factory methods that are used to access most html objects
|
4
|
+
#
|
5
|
+
# For example, to access a button on a web page that has the following html
|
6
|
+
# <input type = button name= 'b1' value='Click Me' onClick='javascript:doSomething()'>
|
7
|
+
#
|
8
|
+
# the following Firewatir code could be used
|
9
|
+
#
|
10
|
+
# ff.button(:name, 'b1').click
|
11
|
+
#
|
12
|
+
# or
|
13
|
+
#
|
14
|
+
# ff.button(:value, 'Click Me').to_s
|
15
|
+
#
|
16
|
+
# One can use any attribute to uniquely identify an element including the user defined attributes
|
17
|
+
# that is rendered on the HTML screen. Though, Attribute used to access an element depends on the type of element,
|
18
|
+
# attributes used frequently to address an element are listed below
|
19
|
+
#
|
20
|
+
# :index - find the item using the index in the container ( a container can be a document,
|
21
|
+
# a TableCell, a Span, a Div or a P)
|
22
|
+
# index is 1 based
|
23
|
+
# :name - find the item using the name attribute
|
24
|
+
# :id - find the item using the id attribute
|
25
|
+
# :value - find the item using the value attribute
|
26
|
+
# :caption - same as value
|
27
|
+
# :xpath - finds the item using xpath query
|
28
|
+
#
|
29
|
+
# Typical Usage
|
30
|
+
#
|
31
|
+
# ff.button(:id, 'b_1') # access the button with an ID of b_1
|
32
|
+
# ff.button(:name, 'verify_data') # access the button with a name of verify_data
|
33
|
+
# ff.button(:value, 'Login') # access the button with a value (the text displayed on the button) of Login
|
34
|
+
# ff.button(:caption, 'Login') # same as above
|
35
|
+
# ff.button(:value, /Log/) # access the button that has text matching /Log/
|
36
|
+
# ff.button(:index, 2) # access the second button on the page ( 1 based, so the first button is accessed with :index,1)
|
37
|
+
#
|
38
|
+
=end
|
39
|
+
|
40
|
+
require 'firewatir/exceptions'
|
41
|
+
|
42
|
+
module FireWatir
|
43
|
+
module Container
|
44
|
+
include FireWatir
|
45
|
+
include Watir::Exception
|
46
|
+
include JsshSocket
|
47
|
+
|
48
|
+
# IP Address of the machine where the script is to be executed. Default to localhost.
|
49
|
+
MACHINE_IP = "127.0.0.1"
|
50
|
+
|
51
|
+
# The default color for highlighting objects as they are accessed.
|
52
|
+
DEFAULT_HIGHLIGHT_COLOR = "yellow"
|
53
|
+
|
54
|
+
public
|
55
|
+
#
|
56
|
+
# Description:
|
57
|
+
# Used to access a frame element. Usually an <frame> or <iframe> HTML tag.
|
58
|
+
#
|
59
|
+
# Input:
|
60
|
+
# - how - The attribute used to identify the framet.
|
61
|
+
# - what - The value of that attribute.
|
62
|
+
# If only one parameter is supplied, "how" is by default taken as name and the
|
63
|
+
# parameter supplied becomes the value of the name attribute.
|
64
|
+
#
|
65
|
+
# Typical usage:
|
66
|
+
#
|
67
|
+
# ff.frame(:index, 1)
|
68
|
+
# ff.frame(:name , 'main_frame')
|
69
|
+
# ff.frame('main_frame') # in this case, just a name is supplied.
|
70
|
+
#
|
71
|
+
# Output:
|
72
|
+
# Frame object.
|
73
|
+
#
|
74
|
+
def frame(how, what = nil)
|
75
|
+
locate if respond_to?(:locate)
|
76
|
+
if(what == nil)
|
77
|
+
what = how
|
78
|
+
how = :name
|
79
|
+
end
|
80
|
+
Frame.new(self, how, what)
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Description:
|
85
|
+
# Used to access a form element. Usually an <form> HTML tag.
|
86
|
+
#
|
87
|
+
# Input:
|
88
|
+
# - how - The attribute used to identify the form.
|
89
|
+
# - what - The value of that attribute.
|
90
|
+
# If only one parameter is supplied, "how" is by default taken as name and the
|
91
|
+
# parameter supplied becomes the value of the name attribute.
|
92
|
+
#
|
93
|
+
# Typical usage:
|
94
|
+
#
|
95
|
+
# ff.form(:index, 1)
|
96
|
+
# ff.form(:name , 'main_form')
|
97
|
+
# ff.form('main_form') # in this case, just a name is supplied.
|
98
|
+
#
|
99
|
+
# Output:
|
100
|
+
# Form object.
|
101
|
+
#
|
102
|
+
def form(how, what=nil)
|
103
|
+
locate if respond_to?(:locate)
|
104
|
+
if(what == nil)
|
105
|
+
what = how
|
106
|
+
how = :name
|
107
|
+
end
|
108
|
+
Form.new(self, how, what)
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Description:
|
113
|
+
# Used to access a table. Usually an <table> HTML tag.
|
114
|
+
#
|
115
|
+
# Input:
|
116
|
+
# - how - The attribute used to identify the table.
|
117
|
+
# - what - The value of that attribute.
|
118
|
+
#
|
119
|
+
# Typical usage:
|
120
|
+
#
|
121
|
+
# ff.table(:index, 1) #index starts from 1.
|
122
|
+
# ff.table(:id, 'main_table')
|
123
|
+
#
|
124
|
+
# Output:
|
125
|
+
# Table object.
|
126
|
+
#
|
127
|
+
def table(how, what=nil)
|
128
|
+
locate if respond_to?(:locate)
|
129
|
+
Table.new(self, how, what)
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Description:
|
134
|
+
# Used to access a table cell. Usually an <td> HTML tag.
|
135
|
+
#
|
136
|
+
# Input:
|
137
|
+
# - how - The attribute used to identify the cell.
|
138
|
+
# - what - The value of that attribute.
|
139
|
+
#
|
140
|
+
# Typical Usage:
|
141
|
+
# ff.cell(:id, 'tb_cell')
|
142
|
+
# ff.cell(:index, 1)
|
143
|
+
#
|
144
|
+
# Output:
|
145
|
+
# TableCell Object
|
146
|
+
#
|
147
|
+
def cell(how, what=nil)
|
148
|
+
locate if respond_to?(:locate)
|
149
|
+
TableCell.new(self, how, what)
|
150
|
+
end
|
151
|
+
|
152
|
+
#
|
153
|
+
# Description:
|
154
|
+
# Used to access a table row. Usually an <tr> HTML tag.
|
155
|
+
#
|
156
|
+
# Input:
|
157
|
+
# - how - The attribute used to identify the row.
|
158
|
+
# - what - The value of that attribute.
|
159
|
+
#
|
160
|
+
# Typical Usage:
|
161
|
+
# ff.row(:id, 'tb_row')
|
162
|
+
# ff.row(:index, 1)
|
163
|
+
#
|
164
|
+
# Output:
|
165
|
+
# TableRow object
|
166
|
+
#
|
167
|
+
def row(how, what=nil)
|
168
|
+
locate if respond_to?(:locate)
|
169
|
+
TableRow.new(self, how, what)
|
170
|
+
end
|
171
|
+
|
172
|
+
#
|
173
|
+
# Description:
|
174
|
+
# Used to access a button element. Usually an <input type = "button"> HTML tag.
|
175
|
+
#
|
176
|
+
# Input:
|
177
|
+
# - how - The attribute used to identify the row.
|
178
|
+
# - what - The value of that attribute.
|
179
|
+
#
|
180
|
+
# Typical Usage:
|
181
|
+
# ff.button(:id, 'b_1') # access the button with an ID of b_1
|
182
|
+
# ff.button(:name, 'verify_data') # access the button with a name of verify_data
|
183
|
+
#
|
184
|
+
# if only a single parameter is supplied, then :value is used as 'how' and parameter supplied is used as what.
|
185
|
+
#
|
186
|
+
# ff.button('Click Me') # access the button with a value of Click Me
|
187
|
+
#
|
188
|
+
# Output:
|
189
|
+
# Button element.
|
190
|
+
#
|
191
|
+
def button(how, what=nil)
|
192
|
+
locate if respond_to?(:locate)
|
193
|
+
if what.nil? && String === how
|
194
|
+
what = how
|
195
|
+
how = :value
|
196
|
+
end
|
197
|
+
Button.new(self, how, what)
|
198
|
+
end
|
199
|
+
|
200
|
+
#
|
201
|
+
# Description:
|
202
|
+
# Used for accessing a file field. Usually an <input type = file> HTML tag.
|
203
|
+
#
|
204
|
+
# Input:
|
205
|
+
# - how - Attribute used to identify the file field element
|
206
|
+
# - what - Value of that attribute.
|
207
|
+
#
|
208
|
+
# Typical Usage:
|
209
|
+
# ff.file_field(:id, 'up_1') # access the file upload fff.d with an ID of up_1
|
210
|
+
# ff.file_field(:name, 'upload') # access the file upload fff.d with a name of upload
|
211
|
+
#
|
212
|
+
# Output:
|
213
|
+
# FileField object
|
214
|
+
#
|
215
|
+
def file_field(how, what = nil)
|
216
|
+
locate if respond_to?(:locate)
|
217
|
+
FileField.new(self, how, what)
|
218
|
+
end
|
219
|
+
|
220
|
+
#
|
221
|
+
# Description:
|
222
|
+
# Used for accessing a text field. Usually an <input type = text> HTML tag. or a text area - a <textarea> tag
|
223
|
+
#
|
224
|
+
# Input:
|
225
|
+
# - how - Attribute used to identify the text field element.
|
226
|
+
# - what - Value of that attribute.
|
227
|
+
#
|
228
|
+
# Typical Usage:
|
229
|
+
#
|
230
|
+
# ff.text_field(:id, 'user_name') # access the text field with an ID of user_name
|
231
|
+
# ff.text_field(:name, 'address') # access the text field with a name of address
|
232
|
+
#
|
233
|
+
# Output:
|
234
|
+
# TextField object.
|
235
|
+
#
|
236
|
+
def text_field(how, what = nil)
|
237
|
+
locate if respond_to?(:locate)
|
238
|
+
TextField.new(self, how, what)
|
239
|
+
end
|
240
|
+
|
241
|
+
#
|
242
|
+
# Description:
|
243
|
+
# Used to access hidden field element. Usually an <input type = hidden> HTML tag
|
244
|
+
#
|
245
|
+
# Input:
|
246
|
+
# - how - Attribute used to identify the hidden element.
|
247
|
+
# - what - Value of that attribute.
|
248
|
+
#
|
249
|
+
# Typical Usage:
|
250
|
+
#
|
251
|
+
# ff.hidden(:id, 'user_name') # access the hidden element with an ID of user_name
|
252
|
+
# ff.hidden(:name, 'address') # access the hidden element with a name of address
|
253
|
+
#
|
254
|
+
# Output:
|
255
|
+
# Hidden object.
|
256
|
+
#
|
257
|
+
def hidden(how, what=nil)
|
258
|
+
locate if respond_to?(:locate)
|
259
|
+
return Hidden.new(self, how, what)
|
260
|
+
end
|
261
|
+
|
262
|
+
#
|
263
|
+
# Description:
|
264
|
+
# Used to access select list element. Usually an <select> HTML tag.
|
265
|
+
#
|
266
|
+
# Input:
|
267
|
+
# - how - Attribute used to identify the select element.
|
268
|
+
# - what - Value of that attribute.
|
269
|
+
#
|
270
|
+
# Typical Usage:
|
271
|
+
#
|
272
|
+
# ff.select_list(:id, 'user_name') # access the select list with an ID of user_name
|
273
|
+
# ff.select_list(:name, 'address') # access the select list with a name of address
|
274
|
+
#
|
275
|
+
# Output:
|
276
|
+
# Select List object.
|
277
|
+
#
|
278
|
+
def select_list(how, what=nil)
|
279
|
+
locate if respond_to?(:locate)
|
280
|
+
return SelectList.new(self, how, what)
|
281
|
+
end
|
282
|
+
|
283
|
+
#
|
284
|
+
# Description:
|
285
|
+
# Used to access checkbox element. Usually an <input type = checkbox> HTML tag.
|
286
|
+
#
|
287
|
+
# Input:
|
288
|
+
# - how - Attribute used to identify the check box element.
|
289
|
+
# - what - Value of that attribute.
|
290
|
+
#
|
291
|
+
# Typical Usage:
|
292
|
+
#
|
293
|
+
# ff.checkbox(:id, 'user_name') # access the checkbox element with an ID of user_name
|
294
|
+
# ff.checkbox(:name, 'address') # access the checkbox element with a name of address
|
295
|
+
# In many instances, checkboxes on an html page have the same name, but are identified by different values. An example is shown next.
|
296
|
+
#
|
297
|
+
# <input type = checkbox name = email_frequency value = 'daily' > Daily Email
|
298
|
+
# <input type = checkbox name = email_frequency value = 'Weekly'> Weekly Email
|
299
|
+
# <input type = checkbox name = email_frequency value = 'monthly'>Monthly Email
|
300
|
+
#
|
301
|
+
# FireWatir can access these using the following:
|
302
|
+
#
|
303
|
+
# ff.checkbox(:id, 'day_to_send' , 'monday' ) # access the check box with an id of day_to_send and a value of monday
|
304
|
+
# ff.checkbox(:name ,'email_frequency', 'weekly') # access the check box with a name of email_frequency and a value of 'weekly'
|
305
|
+
#
|
306
|
+
# Output:
|
307
|
+
# Checkbox object.
|
308
|
+
#
|
309
|
+
def checkbox(how, what=nil, value = nil)
|
310
|
+
locate if respond_to?(:locate)
|
311
|
+
return CheckBox.new(self, how, what, value)
|
312
|
+
end
|
313
|
+
|
314
|
+
#
|
315
|
+
# Description:
|
316
|
+
# Used to access radio button element. Usually an <input type = radio> HTML tag.
|
317
|
+
#
|
318
|
+
# Input:
|
319
|
+
# - how - Attribute used to identify the radio button element.
|
320
|
+
# - what - Value of that attribute.
|
321
|
+
#
|
322
|
+
# Typical Usage:
|
323
|
+
#
|
324
|
+
# ff.radio(:id, 'user_name') # access the radio button element with an ID of user_name
|
325
|
+
# ff.radio(:name, 'address') # access the radio button element with a name of address
|
326
|
+
# In many instances, radio buttons on an html page have the same name, but are identified by different values. An example is shown next.
|
327
|
+
#
|
328
|
+
# <input type = radio name = email_frequency value = 'daily' > Daily Email
|
329
|
+
# <input type = radio name = email_frequency value = 'Weekly'> Weekly Email
|
330
|
+
# <input type = radio name = email_frequency value = 'monthly'>Monthly Email
|
331
|
+
#
|
332
|
+
# FireWatir can access these using the following:
|
333
|
+
#
|
334
|
+
# ff.radio(:id, 'day_to_send' , 'monday' ) # access the radio button with an id of day_to_send and a value of monday
|
335
|
+
# ff.radio(:name ,'email_frequency', 'weekly') # access the radio button with a name of email_frequency and a value of 'weekly'
|
336
|
+
#
|
337
|
+
# Output:
|
338
|
+
# Radio button object.
|
339
|
+
#
|
340
|
+
def radio(how, what=nil, value = nil)
|
341
|
+
locate if respond_to?(:locate)
|
342
|
+
return Radio.new(self, how, what, value)
|
343
|
+
end
|
344
|
+
|
345
|
+
#
|
346
|
+
# Description:
|
347
|
+
# Used to access link element. Usually an <a> HTML tag.
|
348
|
+
#
|
349
|
+
# Input:
|
350
|
+
# - how - Attribute used to identify the link element.
|
351
|
+
# - what - Value of that attribute.
|
352
|
+
#
|
353
|
+
# Typical Usage:
|
354
|
+
#
|
355
|
+
# ff.link(:id, 'user_name') # access the link element with an ID of user_name
|
356
|
+
# ff.link(:name, 'address') # access the link element with a name of address
|
357
|
+
#
|
358
|
+
# Output:
|
359
|
+
# Link object.
|
360
|
+
#
|
361
|
+
def link(how, what=nil)
|
362
|
+
locate if respond_to?(:locate)
|
363
|
+
return Link.new(self, how, what)
|
364
|
+
end
|
365
|
+
|
366
|
+
#
|
367
|
+
# Description:
|
368
|
+
# Used to access image element. Usually an <img> HTML tag.
|
369
|
+
#
|
370
|
+
# Input:
|
371
|
+
# - how - Attribute used to identify the image element.
|
372
|
+
# - what - Value of that attribute.
|
373
|
+
#
|
374
|
+
# Typical Usage:
|
375
|
+
#
|
376
|
+
# ff.image(:id, 'user_name') # access the image element with an ID of user_name
|
377
|
+
# ff.image(:name, 'address') # access the image element with a name of address
|
378
|
+
#
|
379
|
+
# Output:
|
380
|
+
# Image object.
|
381
|
+
#
|
382
|
+
def image(how, what = nil)
|
383
|
+
locate if respond_to?(:locate)
|
384
|
+
Image.new(self, how, what)
|
385
|
+
end
|
386
|
+
|
387
|
+
|
388
|
+
#
|
389
|
+
# Description:
|
390
|
+
# Used to access a definition list element - a <dl> HTML tag.
|
391
|
+
#
|
392
|
+
# Input:
|
393
|
+
# - how - Attribute used to identify the definition list element.
|
394
|
+
# - what - Value of that attribute.
|
395
|
+
#
|
396
|
+
# Typical Usage:
|
397
|
+
#
|
398
|
+
# ff.dl(:id, 'user_name') # access the dl element with an ID of user_name
|
399
|
+
# ff.dl(:title, 'address') # access the dl element with a title of address
|
400
|
+
#
|
401
|
+
# Returns:
|
402
|
+
# Dl object.
|
403
|
+
#
|
404
|
+
def dl(how, what = nil)
|
405
|
+
locate if respond_to?(:locate)
|
406
|
+
Dl.new(self, how, what)
|
407
|
+
end
|
408
|
+
|
409
|
+
#
|
410
|
+
# Description:
|
411
|
+
# Used to access a definition term element - a <dt> HTML tag.
|
412
|
+
#
|
413
|
+
# Input:
|
414
|
+
# - how - Attribute used to identify the image element.
|
415
|
+
# - what - Value of that attribute.
|
416
|
+
#
|
417
|
+
# Typical Usage:
|
418
|
+
#
|
419
|
+
# ff.dt(:id, 'user_name') # access the dt element with an ID of user_name
|
420
|
+
# ff.dt(:title, 'address') # access the dt element with a title of address
|
421
|
+
#
|
422
|
+
# Returns:
|
423
|
+
# Dt object.
|
424
|
+
#
|
425
|
+
def dt(how, what = nil)
|
426
|
+
locate if respond_to?(:locate)
|
427
|
+
Dt.new(self, how, what)
|
428
|
+
end
|
429
|
+
|
430
|
+
#
|
431
|
+
# Description:
|
432
|
+
# Used to access a definition description element - a <dd> HTML tag.
|
433
|
+
#
|
434
|
+
# Input:
|
435
|
+
# - how - Attribute used to identify the image element.
|
436
|
+
# - what - Value of that attribute.
|
437
|
+
#
|
438
|
+
# Typical Usage:
|
439
|
+
#
|
440
|
+
# ff.dd(:id, 'user_name') # access the dd element with an ID of user_name
|
441
|
+
# ff.dd(:title, 'address') # access the dd element with a title of address
|
442
|
+
#
|
443
|
+
# Returns:
|
444
|
+
# Dd object.
|
445
|
+
#
|
446
|
+
def dd(how, what = nil)
|
447
|
+
locate if respond_to?(:locate)
|
448
|
+
Dd.new(self, how, what)
|
449
|
+
end
|
450
|
+
|
451
|
+
# Description:
|
452
|
+
# Searching for Page Elements. Not for external consumption.
|
453
|
+
#
|
454
|
+
# def ole_inner_elements
|
455
|
+
# return document.body.all
|
456
|
+
# end
|
457
|
+
# private :ole_inner_elements
|
458
|
+
|
459
|
+
|
460
|
+
#
|
461
|
+
# Description:
|
462
|
+
# This method shows the available objects on the current page.
|
463
|
+
# This is usually only used for debugging or writing new test scripts.
|
464
|
+
# This is a nice feature to help find out what HTML objects are on a page
|
465
|
+
# when developing a test case using FireWatir.
|
466
|
+
#
|
467
|
+
# Typical Usage:
|
468
|
+
# ff.show_all_objects
|
469
|
+
#
|
470
|
+
# Output:
|
471
|
+
# Prints all the available elements on the page.
|
472
|
+
#
|
473
|
+
def show_all_objects
|
474
|
+
puts "-----------Objects in the current context-------------"
|
475
|
+
locate if respond_to?(:locate)
|
476
|
+
elements = Document.new(self).all
|
477
|
+
puts elements.length
|
478
|
+
elements.each do |n|
|
479
|
+
puts n.tagName
|
480
|
+
puts n.to_s
|
481
|
+
puts "------------------------------------------"
|
482
|
+
end
|
483
|
+
puts "Total number of objects in the current context : #{elements.length}"
|
484
|
+
return elements
|
485
|
+
# Test the index access.
|
486
|
+
# puts doc[35].to_s
|
487
|
+
end
|
488
|
+
|
489
|
+
end
|
490
|
+
end # module
|
491
|
+
|