firewatir 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MozillaBaseElement.rb +1778 -0
- data/container.rb +889 -0
- data/firewatir/exceptions.rb +44 -0
- data/firewatir/testUnitAddons.rb +8 -0
- data/firewatir.rb +1130 -0
- data/htmlelements.rb +2277 -0
- data/unittests/attach_to_new_window_test.rb +34 -0
- data/unittests/bug_fixes_test.rb +188 -0
- data/unittests/buttons_test.rb +215 -0
- data/unittests/buttons_xpath_test.rb +87 -0
- data/unittests/checkbox_test.rb +154 -0
- data/unittests/checkbox_xpath_test.rb +107 -0
- data/unittests/div_test.rb +274 -0
- data/unittests/filefield_test.rb +45 -0
- data/unittests/filefield_xpath_test.rb +35 -0
- data/unittests/form_test.rb +307 -0
- data/unittests/frame_test.rb +151 -0
- data/unittests/hidden_test.rb +85 -0
- data/unittests/hidden_xpath_test.rb +72 -0
- data/unittests/html/JavascriptClick.html +42 -0
- data/unittests/html/blankpage.html +12 -0
- data/unittests/html/buttons1.html +61 -0
- data/unittests/html/checkboxes1.html +71 -0
- data/unittests/html/complex_table.html +36 -0
- data/unittests/html/cssTest.html +42 -0
- data/unittests/html/div.html +72 -0
- data/unittests/html/div_xml.html +21 -0
- data/unittests/html/fileupload.html +45 -0
- data/unittests/html/formTest1.html +39 -0
- data/unittests/html/forms2.html +45 -0
- data/unittests/html/forms3.html +132 -0
- data/unittests/html/forms4.html +27 -0
- data/unittests/html/frame_buttons.html +4 -0
- data/unittests/html/frame_links.html +4 -0
- data/unittests/html/frame_multi.html +5 -0
- data/unittests/html/iframeTest.html +15 -0
- data/unittests/html/iframeTest1.html +14 -0
- data/unittests/html/iframeTest2.html +6 -0
- data/unittests/html/images/1.gif +0 -0
- data/unittests/html/images/2.GIF +0 -0
- data/unittests/html/images/3.GIF +0 -0
- data/unittests/html/images/button.jpg +0 -0
- data/unittests/html/images/circle.jpg +0 -0
- data/unittests/html/images/minus.GIF +0 -0
- data/unittests/html/images/originaltriangle.jpg +0 -0
- data/unittests/html/images/plus.gif +0 -0
- data/unittests/html/images/square.jpg +0 -0
- data/unittests/html/images/triangle.jpg +0 -0
- data/unittests/html/images1.html +67 -0
- data/unittests/html/javascriptevents.html +35 -0
- data/unittests/html/link_pass.html +11 -0
- data/unittests/html/links1.html +42 -0
- data/unittests/html/links2.html +11 -0
- data/unittests/html/modal_dialog.html +8 -0
- data/unittests/html/modal_dialog_launcher.html +12 -0
- data/unittests/html/nestedFrames.html +6 -0
- data/unittests/html/new_browser.html +17 -0
- data/unittests/html/pass.html +10 -0
- data/unittests/html/popups1.html +60 -0
- data/unittests/html/pre.html +28 -0
- data/unittests/html/radioButtons1.html +71 -0
- data/unittests/html/redirect.html +10 -0
- data/unittests/html/redirect1.html +9 -0
- data/unittests/html/redirect2.html +9 -0
- data/unittests/html/redirect3.html +9 -0
- data/unittests/html/select_tealeaf.html +54 -0
- data/unittests/html/selectboxes1.html +55 -0
- data/unittests/html/simple_table.html +26 -0
- data/unittests/html/simple_table_buttons.html +104 -0
- data/unittests/html/simple_table_columns.html +74 -0
- data/unittests/html/table1.html +165 -0
- data/unittests/html/tableCell_using_xpath.html +19 -0
- data/unittests/html/textarea.html +30 -0
- data/unittests/html/textfields1.html +62 -0
- data/unittests/html/textsearch.html +44 -0
- data/unittests/images_test.rb +204 -0
- data/unittests/images_xpath_test.rb +118 -0
- data/unittests/iostring.rb +30 -0
- data/unittests/iostring_test.rb +48 -0
- data/unittests/javascript_test.rb +71 -0
- data/unittests/links_test.rb +230 -0
- data/unittests/links_xpath_test.rb +79 -0
- data/unittests/mozilla_all_tests.rb +18 -0
- data/unittests/pre_test.rb +74 -0
- data/unittests/radios_test.rb +166 -0
- data/unittests/radios_xpath_test.rb +101 -0
- data/unittests/redirect_test.rb +40 -0
- data/unittests/selectbox_test.rb +141 -0
- data/unittests/selectbox_xpath_test.rb +127 -0
- data/unittests/setup.rb +35 -0
- data/unittests/table_test.rb +372 -0
- data/unittests/table_xpath_test.rb +184 -0
- data/unittests/textfields_test.rb +230 -0
- data/unittests/textfields_xpath_test.rb +112 -0
- metadata +144 -0
data/container.rb
ADDED
@@ -0,0 +1,889 @@
|
|
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 Container
|
43
|
+
include FireWatir::Exception
|
44
|
+
|
45
|
+
# IP Address of the machine where the script is to be executed. Default to localhost.
|
46
|
+
MACHINE_IP = "127.0.0.1"
|
47
|
+
# Name of the variable with which window is identified in JSSh.
|
48
|
+
WINDOW_VAR = "window"
|
49
|
+
# Name of the variable with which browser is identified in JSSh.
|
50
|
+
BROWSER_VAR = "browser"
|
51
|
+
# Name of the variable with which document is identified in JSSh.
|
52
|
+
DOCUMENT_VAR = "document"
|
53
|
+
# Name of the variable with which body is identified in JSSh.
|
54
|
+
BODY_VAR = "body"
|
55
|
+
|
56
|
+
|
57
|
+
# The delay when entering text on a web page when speed = :slow.
|
58
|
+
DEFAULT_TYPING_SPEED = 0.01
|
59
|
+
|
60
|
+
# The default time we wait after a page has loaded when speed = :slow.
|
61
|
+
DEFAULT_SLEEP_TIME = 0.1
|
62
|
+
|
63
|
+
# The default color for highlighting objects as they are accessed.
|
64
|
+
DEFAULT_HIGHLIGHT_COLOR = "yellow"
|
65
|
+
|
66
|
+
public
|
67
|
+
#
|
68
|
+
# Description:
|
69
|
+
# Used to access a frame element. Usually an <frame> or <iframe> HTML tag.
|
70
|
+
#
|
71
|
+
# Input:
|
72
|
+
# - how - The attribute used to identify the framet.
|
73
|
+
# - what - The value of that attribute.
|
74
|
+
# If only one parameter is supplied, "how" is by default taken as name and the
|
75
|
+
# parameter supplied becomes the value of the name attribute.
|
76
|
+
#
|
77
|
+
# Typical usage:
|
78
|
+
#
|
79
|
+
# ff.frame(:index, 1)
|
80
|
+
# ff.frame(:name , 'main_frame')
|
81
|
+
# ff.frame('main_frame') # in this case, just a name is supplied.
|
82
|
+
#
|
83
|
+
# Output:
|
84
|
+
# Frame object.
|
85
|
+
#
|
86
|
+
def frame(how, what = nil)
|
87
|
+
locate if defined?(locate)
|
88
|
+
if(what == nil)
|
89
|
+
what = how
|
90
|
+
how = :name
|
91
|
+
end
|
92
|
+
Frame.new(self, how, what)
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# Description:
|
97
|
+
# Used to access a form element. Usually an <form> HTML tag.
|
98
|
+
#
|
99
|
+
# Input:
|
100
|
+
# - how - The attribute used to identify the form.
|
101
|
+
# - what - The value of that attribute.
|
102
|
+
# If only one parameter is supplied, "how" is by default taken as name and the
|
103
|
+
# parameter supplied becomes the value of the name attribute.
|
104
|
+
#
|
105
|
+
# Typical usage:
|
106
|
+
#
|
107
|
+
# ff.form(:index, 1)
|
108
|
+
# ff.form(:name , 'main_form')
|
109
|
+
# ff.form('main_form') # in this case, just a name is supplied.
|
110
|
+
#
|
111
|
+
# Output:
|
112
|
+
# Form object.
|
113
|
+
#
|
114
|
+
def form(how, what=nil)
|
115
|
+
locate if defined?(locate)
|
116
|
+
if(what == nil)
|
117
|
+
what = how
|
118
|
+
how = :name
|
119
|
+
end
|
120
|
+
Form.new(self, how, what)
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Description:
|
125
|
+
# Used to access a table. Usually an <table> HTML tag.
|
126
|
+
#
|
127
|
+
# Input:
|
128
|
+
# - how - The attribute used to identify the table.
|
129
|
+
# - what - The value of that attribute.
|
130
|
+
#
|
131
|
+
# Typical usage:
|
132
|
+
#
|
133
|
+
# ff.table(:index, 1) #index starts from 1.
|
134
|
+
# ff.table(:id, 'main_table')
|
135
|
+
#
|
136
|
+
# Output:
|
137
|
+
# Table object.
|
138
|
+
#
|
139
|
+
def table(how, what)
|
140
|
+
locate if defined?(locate)
|
141
|
+
Table.new(self, how, what)
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Description:
|
146
|
+
# Gets the tables iterator. It returns a Tables object
|
147
|
+
#
|
148
|
+
# Typical usage:
|
149
|
+
#
|
150
|
+
# ff.tables.each { |t| puts t.to_s } # iterate through all the tables on the page
|
151
|
+
# ff.tables[1].to_s # goto the first table on the page
|
152
|
+
# ff.tables.length # show how many tables are on the page. Tables that are nested will be included in this
|
153
|
+
#
|
154
|
+
def tables
|
155
|
+
locate if defined?(locate)
|
156
|
+
return Tables.new(self)
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# Description:
|
161
|
+
# Used to access a table cell. Usually an <td> HTML tag.
|
162
|
+
#
|
163
|
+
# Input:
|
164
|
+
# - how - The attribute used to identify the cell.
|
165
|
+
# - what - The value of that attribute.
|
166
|
+
#
|
167
|
+
# Typical Usage:
|
168
|
+
# ff.cell(:id, 'tb_cell')
|
169
|
+
# ff.cell(:index, 1)
|
170
|
+
#
|
171
|
+
# Output:
|
172
|
+
# TableCell Object
|
173
|
+
#
|
174
|
+
def cell(how, what=nil)
|
175
|
+
locate if defined?(locate)
|
176
|
+
TableCell.new(self, how, what)
|
177
|
+
end
|
178
|
+
|
179
|
+
#
|
180
|
+
# Description:
|
181
|
+
# Used to access a table row. Usually an <tr> HTML tag.
|
182
|
+
#
|
183
|
+
# Input:
|
184
|
+
# - how - The attribute used to identify the row.
|
185
|
+
# - what - The value of that attribute.
|
186
|
+
#
|
187
|
+
# Typical Usage:
|
188
|
+
# ff.row(:id, 'tb_row')
|
189
|
+
# ff.row(:index, 1)
|
190
|
+
#
|
191
|
+
# Output:
|
192
|
+
# TableRow object
|
193
|
+
#
|
194
|
+
def row(how, what=nil)
|
195
|
+
locate if defined?(locate)
|
196
|
+
TableRow.new(self, how, what)
|
197
|
+
end
|
198
|
+
|
199
|
+
#
|
200
|
+
# Description:
|
201
|
+
# Used to access a button element. Usually an <input type = "button"> HTML tag.
|
202
|
+
#
|
203
|
+
# Input:
|
204
|
+
# - how - The attribute used to identify the row.
|
205
|
+
# - what - The value of that attribute.
|
206
|
+
#
|
207
|
+
# Typical Usage:
|
208
|
+
# ff.button(:id, 'b_1') # access the button with an ID of b_1
|
209
|
+
# ff.button(:name, 'verify_data') # access the button with a name of verify_data
|
210
|
+
#
|
211
|
+
# if only a single parameter is supplied, then :value is used as 'how' and parameter supplied is used as what.
|
212
|
+
#
|
213
|
+
# ff.button('Click Me') # access the button with a value of Click Me
|
214
|
+
#
|
215
|
+
# Output:
|
216
|
+
# Button element.
|
217
|
+
#
|
218
|
+
def button(how, what = nil)
|
219
|
+
locate if defined?(locate)
|
220
|
+
if(what == nil)
|
221
|
+
what = how
|
222
|
+
how = :value
|
223
|
+
end
|
224
|
+
Button.new(self, how, what)
|
225
|
+
end
|
226
|
+
|
227
|
+
#
|
228
|
+
# Description:
|
229
|
+
# Used for accessing all the buttons on the page. Returns a Buttons object
|
230
|
+
#
|
231
|
+
# Typical usage:
|
232
|
+
#
|
233
|
+
# ff.buttons.each { |b| puts b.to_s } # iterate through all the buttons on the page
|
234
|
+
# ff.buttons.length # show how many buttons are on the page.
|
235
|
+
#
|
236
|
+
# Output:
|
237
|
+
# Buttons object.
|
238
|
+
#
|
239
|
+
def buttons
|
240
|
+
locate if defined?(locate)
|
241
|
+
return Buttons.new(self)
|
242
|
+
end
|
243
|
+
|
244
|
+
#
|
245
|
+
# Description:
|
246
|
+
# Used for accessing a file field. Usually an <input type = file> HTML tag.
|
247
|
+
#
|
248
|
+
# Input:
|
249
|
+
# - how - Attribute used to identify the file field element
|
250
|
+
# - what - Value of that attribute.
|
251
|
+
#
|
252
|
+
# Typical Usage:
|
253
|
+
# ff.file_field(:id, 'up_1') # access the file upload fff.d with an ID of up_1
|
254
|
+
# ff.file_field(:name, 'upload') # access the file upload fff.d with a name of upload
|
255
|
+
#
|
256
|
+
# Output:
|
257
|
+
# FileField object
|
258
|
+
#
|
259
|
+
def file_field(how, what = nil)
|
260
|
+
locate if defined?(locate)
|
261
|
+
FileField.new(self, how, what)
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
# Description:
|
266
|
+
# Used for accessing all the file field elements on the page. Returns a FileFields object
|
267
|
+
#
|
268
|
+
# Typical usage:
|
269
|
+
#
|
270
|
+
# ff.file_fields.each { |f| puts f.to_s } # iterate through all the file fields on the page
|
271
|
+
# ff.file_fields[1].to_s # goto the first file field on the page
|
272
|
+
# ff.file_fields.length # show how many file fields are on the page.
|
273
|
+
#
|
274
|
+
# Output:
|
275
|
+
# FileFields object
|
276
|
+
#
|
277
|
+
def file_fields
|
278
|
+
locate if defined?(locate)
|
279
|
+
return FileFields.new(self)
|
280
|
+
end
|
281
|
+
|
282
|
+
#
|
283
|
+
# Description:
|
284
|
+
# Used for accessing a text field. Usually an <input type = text> HTML tag. or a text area - a <textarea> tag
|
285
|
+
#
|
286
|
+
# Input:
|
287
|
+
# - how - Attribute used to identify the text field element.
|
288
|
+
# - what - Value of that attribute.
|
289
|
+
#
|
290
|
+
# Typical Usage:
|
291
|
+
#
|
292
|
+
# ff.text_field(:id, 'user_name') # access the text field with an ID of user_name
|
293
|
+
# ff.text_field(:name, 'address') # access the text field with a name of address
|
294
|
+
#
|
295
|
+
# Output:
|
296
|
+
# TextField object.
|
297
|
+
#
|
298
|
+
def text_field(how, what = nil)
|
299
|
+
locate if defined?(locate)
|
300
|
+
TextField.new(self, how, what)
|
301
|
+
end
|
302
|
+
|
303
|
+
#
|
304
|
+
# Description:
|
305
|
+
# Used for accessing all the text fields on the page. Returns a TextFields object
|
306
|
+
#
|
307
|
+
# Typical usage:
|
308
|
+
#
|
309
|
+
# ff.text_fields.each { |t| puts t.to_s } # iterate through all the text fields on the page
|
310
|
+
# ff.text_fields[1].to_s # goto the first text fields on the page
|
311
|
+
# ff.text_fields.length # show how many text fields are on the page.
|
312
|
+
#
|
313
|
+
# Output:
|
314
|
+
# TextFields object.
|
315
|
+
#
|
316
|
+
def text_fields
|
317
|
+
locate if defined?(locate)
|
318
|
+
return TextFields.new(self)
|
319
|
+
end
|
320
|
+
|
321
|
+
#
|
322
|
+
# Description:
|
323
|
+
# Used to access hidden field element. Usually an <input type = hidden> HTML tag
|
324
|
+
#
|
325
|
+
# Input:
|
326
|
+
# - how - Attribute used to identify the hidden element.
|
327
|
+
# - what - Value of that attribute.
|
328
|
+
#
|
329
|
+
# Typical Usage:
|
330
|
+
#
|
331
|
+
# ff.hidden(:id, 'user_name') # access the hidden element with an ID of user_name
|
332
|
+
# ff.hidden(:name, 'address') # access the hidden element with a name of address
|
333
|
+
#
|
334
|
+
# Output:
|
335
|
+
# Hidden object.
|
336
|
+
#
|
337
|
+
def hidden(how, what)
|
338
|
+
locate if defined?(locate)
|
339
|
+
return Hidden.new(self, how, what)
|
340
|
+
end
|
341
|
+
|
342
|
+
#
|
343
|
+
# Description:
|
344
|
+
# Used for accessing all the hidden fields on the page. Returns a Hiddens object
|
345
|
+
#
|
346
|
+
# Typical usage:
|
347
|
+
#
|
348
|
+
# ff.hiddens.each { |t| puts t.to_s } # iterate through all the hidden fields on the page
|
349
|
+
# ff.hiddens[1].to_s # goto the first hidden fields on the page
|
350
|
+
# ff.hiddens.length # show how many hidden fields are on the page.
|
351
|
+
#
|
352
|
+
# Output:
|
353
|
+
# Hiddens object.
|
354
|
+
#
|
355
|
+
def hiddens
|
356
|
+
locate if defined?(locate)
|
357
|
+
return Hiddens.new(self)
|
358
|
+
end
|
359
|
+
|
360
|
+
#
|
361
|
+
# Description:
|
362
|
+
# Used to access select list element. Usually an <select> HTML tag.
|
363
|
+
#
|
364
|
+
# Input:
|
365
|
+
# - how - Attribute used to identify the select element.
|
366
|
+
# - what - Value of that attribute.
|
367
|
+
#
|
368
|
+
# Typical Usage:
|
369
|
+
#
|
370
|
+
# ff.select_list(:id, 'user_name') # access the select list with an ID of user_name
|
371
|
+
# ff.select_list(:name, 'address') # access the select list with a name of address
|
372
|
+
#
|
373
|
+
# Output:
|
374
|
+
# Select List object.
|
375
|
+
#
|
376
|
+
def select_list(how, what)
|
377
|
+
locate if defined?(locate)
|
378
|
+
return SelectList.new(self, how, what)
|
379
|
+
end
|
380
|
+
|
381
|
+
#
|
382
|
+
# Description:
|
383
|
+
# Used for accessing all the Listbox or dropdown elements on the page. Returns a SelectLists object
|
384
|
+
#
|
385
|
+
# Typical usage:
|
386
|
+
#
|
387
|
+
# ff.select_lists.each { |s| puts s.to_s } # iterate through all the select boxes on the page
|
388
|
+
# ff.select_lists[1].to_s # goto the first select boxes on the page
|
389
|
+
# ff.select_lists.length # show how many select boxes are on the page.
|
390
|
+
#
|
391
|
+
# Output:
|
392
|
+
# SelectLists object.
|
393
|
+
#
|
394
|
+
def select_lists
|
395
|
+
locate if defined?(locate)
|
396
|
+
return SelectLists.new(self)
|
397
|
+
end
|
398
|
+
|
399
|
+
#
|
400
|
+
# Description:
|
401
|
+
# Used to access checkbox element. Usually an <input type = checkbox> HTML tag.
|
402
|
+
#
|
403
|
+
# Input:
|
404
|
+
# - how - Attribute used to identify the check box element.
|
405
|
+
# - what - Value of that attribute.
|
406
|
+
#
|
407
|
+
# Typical Usage:
|
408
|
+
#
|
409
|
+
# ff.checkbox(:id, 'user_name') # access the checkbox element with an ID of user_name
|
410
|
+
# ff.checkbox(:name, 'address') # access the checkbox element with a name of address
|
411
|
+
# In many instances, checkboxes on an html page have the same name, but are identified by different values. An example is shown next.
|
412
|
+
#
|
413
|
+
# <input type = checkbox name = email_frequency value = 'daily' > Daily Email
|
414
|
+
# <input type = checkbox name = email_frequency value = 'Weekly'> Weekly Email
|
415
|
+
# <input type = checkbox name = email_frequency value = 'monthly'>Monthly Email
|
416
|
+
#
|
417
|
+
# FireWatir can access these using the following:
|
418
|
+
#
|
419
|
+
# ff.checkbox(:id, 'day_to_send' , 'monday' ) # access the check box with an id of day_to_send and a value of monday
|
420
|
+
# ff.checkbox(:name ,'email_frequency', 'weekly') # access the check box with a name of email_frequency and a value of 'weekly'
|
421
|
+
#
|
422
|
+
# Output:
|
423
|
+
# Checkbox object.
|
424
|
+
#
|
425
|
+
def checkbox(how, what, value = nil)
|
426
|
+
locate if defined?(locate)
|
427
|
+
return CheckBox.new(self, how, what, ["checkbox"], value)
|
428
|
+
end
|
429
|
+
|
430
|
+
#
|
431
|
+
# Description:
|
432
|
+
# Used for accessing all the Checkbox elements on the page. Returns a CheckBoxes object
|
433
|
+
#
|
434
|
+
# Typical usage:
|
435
|
+
#
|
436
|
+
# ff.checkboxes.each { |c| puts c.to_s } # iterate through all the check boxes on the page
|
437
|
+
# ff.checkboxes[1].to_s # goto the first check box on the page
|
438
|
+
# ff.checkboxes.length # show how many check boxes are on the page.
|
439
|
+
#
|
440
|
+
# Output:
|
441
|
+
# CheckBoxes object.
|
442
|
+
def checkboxes
|
443
|
+
locate if defined?(locate)
|
444
|
+
return CheckBoxes.new(self)
|
445
|
+
end
|
446
|
+
|
447
|
+
|
448
|
+
#
|
449
|
+
# Description:
|
450
|
+
# Used to access radio button element. Usually an <input type = radio> HTML tag.
|
451
|
+
#
|
452
|
+
# Input:
|
453
|
+
# - how - Attribute used to identify the radio button element.
|
454
|
+
# - what - Value of that attribute.
|
455
|
+
#
|
456
|
+
# Typical Usage:
|
457
|
+
#
|
458
|
+
# ff.radio(:id, 'user_name') # access the radio button element with an ID of user_name
|
459
|
+
# ff.radio(:name, 'address') # access the radio button element with a name of address
|
460
|
+
# In many instances, radio buttons on an html page have the same name, but are identified by different values. An example is shown next.
|
461
|
+
#
|
462
|
+
# <input type = radio name = email_frequency value = 'daily' > Daily Email
|
463
|
+
# <input type = radio name = email_frequency value = 'Weekly'> Weekly Email
|
464
|
+
# <input type = radio name = email_frequency value = 'monthly'>Monthly Email
|
465
|
+
#
|
466
|
+
# FireWatir can access these using the following:
|
467
|
+
#
|
468
|
+
# ff.radio(:id, 'day_to_send' , 'monday' ) # access the radio button with an id of day_to_send and a value of monday
|
469
|
+
# ff.radio(:name ,'email_frequency', 'weekly') # access the radio button with a name of email_frequency and a value of 'weekly'
|
470
|
+
#
|
471
|
+
# Output:
|
472
|
+
# Radio button object.
|
473
|
+
#
|
474
|
+
def radio(how, what, value = nil)
|
475
|
+
locate if defined?(locate)
|
476
|
+
return Radio.new(self, how, what, ["radio"], value)
|
477
|
+
end
|
478
|
+
|
479
|
+
#
|
480
|
+
# Description:
|
481
|
+
# Used for accessing all the Radiobutton elements on the page. Returns a Radios object
|
482
|
+
#
|
483
|
+
# Typical usage:
|
484
|
+
#
|
485
|
+
# ff.radios.each { |r| puts r.to_s } # iterate through all the radio buttons on the page
|
486
|
+
# ff.radios[1].to_s # goto the first radio button on the page
|
487
|
+
# ff.radios.length # show how many radio buttons are on the page.
|
488
|
+
#
|
489
|
+
# Output:
|
490
|
+
# Radios object.
|
491
|
+
#
|
492
|
+
def radios
|
493
|
+
locate if defined?(locate)
|
494
|
+
return Radios.new(self)
|
495
|
+
end
|
496
|
+
|
497
|
+
#
|
498
|
+
# Description:
|
499
|
+
# Used to access link element. Usually an <a> HTML tag.
|
500
|
+
#
|
501
|
+
# Input:
|
502
|
+
# - how - Attribute used to identify the link element.
|
503
|
+
# - what - Value of that attribute.
|
504
|
+
#
|
505
|
+
# Typical Usage:
|
506
|
+
#
|
507
|
+
# ff.link(:id, 'user_name') # access the link element with an ID of user_name
|
508
|
+
# ff.link(:name, 'address') # access the link element with a name of address
|
509
|
+
#
|
510
|
+
# Output:
|
511
|
+
# Link object.
|
512
|
+
#
|
513
|
+
def link(how, what)
|
514
|
+
locate if defined?(locate)
|
515
|
+
return Link.new(self, how, what)
|
516
|
+
end
|
517
|
+
|
518
|
+
#
|
519
|
+
# Description:
|
520
|
+
# Used for accessing all the Link elements on the page. Returns a Links object
|
521
|
+
#
|
522
|
+
# Typical usage:
|
523
|
+
#
|
524
|
+
# ff.links.each { |l| puts l.to_s } # iterate through all the links on the page
|
525
|
+
# ff.links[1].to_s # goto the first link on the page
|
526
|
+
# ff.links.length # show how many links are on the page.
|
527
|
+
#
|
528
|
+
# Output:
|
529
|
+
# Links Object
|
530
|
+
#
|
531
|
+
def links
|
532
|
+
locate if defined?(locate)
|
533
|
+
return Links.new(self)
|
534
|
+
end
|
535
|
+
|
536
|
+
#
|
537
|
+
# Description:
|
538
|
+
# Used to access image element. Usually an <img> HTML tag.
|
539
|
+
#
|
540
|
+
# Input:
|
541
|
+
# - how - Attribute used to identify the image element.
|
542
|
+
# - what - Value of that attribute.
|
543
|
+
#
|
544
|
+
# Typical Usage:
|
545
|
+
#
|
546
|
+
# ff.image(:id, 'user_name') # access the image element with an ID of user_name
|
547
|
+
# ff.image(:name, 'address') # access the image element with a name of address
|
548
|
+
#
|
549
|
+
# Output:
|
550
|
+
# Image object.
|
551
|
+
#
|
552
|
+
def image(how, what = nil)
|
553
|
+
locate if defined?(locate)
|
554
|
+
Image.new(self, how, what)
|
555
|
+
end
|
556
|
+
|
557
|
+
#
|
558
|
+
# Description:
|
559
|
+
# Used for accessing all the Image elements on the page. Returns a Images object
|
560
|
+
#
|
561
|
+
# Typical usage:
|
562
|
+
#
|
563
|
+
# ff.images.each { |i| puts i.to_s } # iterate through all the images on the page
|
564
|
+
# ff.images[1].to_s # goto the first image on the page
|
565
|
+
# ff.images.length # show how many images are on the page.
|
566
|
+
#
|
567
|
+
# Output:
|
568
|
+
# Images object.
|
569
|
+
#
|
570
|
+
def images
|
571
|
+
locate if defined?(locate)
|
572
|
+
return Images.new(self)
|
573
|
+
end
|
574
|
+
|
575
|
+
# This is the main method for accessing JavaScript popups.
|
576
|
+
# returns a PopUp object
|
577
|
+
#def popup # BUG this should not be on the container object!
|
578
|
+
# return PopUp.new(self)
|
579
|
+
#end
|
580
|
+
|
581
|
+
#
|
582
|
+
# Description:
|
583
|
+
# Used to access div element. Usually an <div> HTML tag.
|
584
|
+
#
|
585
|
+
# Input:
|
586
|
+
# - how - Attribute used to identify the dive element.
|
587
|
+
# - what - Value of that attribute.
|
588
|
+
#
|
589
|
+
# Typical Usage:
|
590
|
+
#
|
591
|
+
# ff.div(:id, 'user_name') # access the div element with an ID of user_name
|
592
|
+
# ff.div(:name, 'address') # access the div element with a name of address
|
593
|
+
#
|
594
|
+
# Output:
|
595
|
+
# Div object.
|
596
|
+
#
|
597
|
+
def div(how, what)
|
598
|
+
locate if defined?(locate)
|
599
|
+
return Div.new(self, how, what)
|
600
|
+
end
|
601
|
+
|
602
|
+
#
|
603
|
+
# Description:
|
604
|
+
# Used for accessing all the Div elements on the page. Returns a Divs object
|
605
|
+
#
|
606
|
+
# Typical usage:
|
607
|
+
#
|
608
|
+
# ff.divs.each { |d| puts d.to_s } # iterate through all the divs on the page
|
609
|
+
# ff.divs[1].to_s # goto the first div on the page
|
610
|
+
# ff.divs.length # show how many divs are on the page.
|
611
|
+
#
|
612
|
+
# Output:
|
613
|
+
# Divs object.
|
614
|
+
#
|
615
|
+
def divs
|
616
|
+
locate if defined?(locate)
|
617
|
+
return Divs.new(self)
|
618
|
+
end
|
619
|
+
|
620
|
+
|
621
|
+
#
|
622
|
+
# Description:
|
623
|
+
# Used to access a span. Usually an <span> HTML tag.
|
624
|
+
#
|
625
|
+
# Input:
|
626
|
+
# - how - The attribute used to identify the span.
|
627
|
+
# - what - The value of that attribute.
|
628
|
+
#
|
629
|
+
# Typical usage:
|
630
|
+
# ff.span(:id, /list/) # access the first span that matches list.
|
631
|
+
# ff.span(:index,2) # access the second span on the page
|
632
|
+
# ff.span(:title , "A Picture") # access a span using the tooltip text.
|
633
|
+
#
|
634
|
+
# Output:
|
635
|
+
# Span Object
|
636
|
+
#
|
637
|
+
def span(how, what)
|
638
|
+
locate if defined?(locate)
|
639
|
+
return Span.new(self, how, what)
|
640
|
+
end
|
641
|
+
|
642
|
+
#
|
643
|
+
# Description:
|
644
|
+
# Used for accessing all the Span elements on the page. Returns a Spans object
|
645
|
+
#
|
646
|
+
# Typical usage:
|
647
|
+
#
|
648
|
+
# ff.spans.each { |s| puts s.to_s } # iterate through all the spans on the page
|
649
|
+
# ff.spans[1].to_s # goto the first span on the page
|
650
|
+
# ff.spans.length # show how many spans are on the page.
|
651
|
+
#
|
652
|
+
# Output:
|
653
|
+
# Spans object.
|
654
|
+
#
|
655
|
+
def spans
|
656
|
+
locate if defined?(locate)
|
657
|
+
return Spans.new(self)
|
658
|
+
end
|
659
|
+
|
660
|
+
|
661
|
+
#
|
662
|
+
# Description:
|
663
|
+
# Used to access a paragraph. Usually an <p> HTML tag. For more details on this visit
|
664
|
+
# See http://www.xulplanet.com/references/objref/HTMLParagraphElement.html.
|
665
|
+
#
|
666
|
+
# Input:
|
667
|
+
# - how - The attribute used to identify the paragraph.
|
668
|
+
# - what - The value of that attribute.
|
669
|
+
#
|
670
|
+
# Typical Usage
|
671
|
+
#
|
672
|
+
# ff.p(:id, /list/) # access the first p tag that matches list.
|
673
|
+
# ff.p(:index,2) # access the second p tag on the page
|
674
|
+
# ff.p(:title , "A Picture") # access a p tag using the tooltip text.
|
675
|
+
#
|
676
|
+
# Output:
|
677
|
+
# Paragraph object.
|
678
|
+
#
|
679
|
+
def p(how, what)
|
680
|
+
locate if defined?(locate)
|
681
|
+
return P.new(self, how, what)
|
682
|
+
end
|
683
|
+
|
684
|
+
#
|
685
|
+
# Description:
|
686
|
+
# Used for accessing all the Paragraph <p> elements on the page. Returns a Ps object
|
687
|
+
#
|
688
|
+
# Typical usage:
|
689
|
+
#
|
690
|
+
# ff.ps.each { |p| puts p.to_s } # iterate through all the p tags on the page
|
691
|
+
# ff.ps[1].to_s # goto the first p tag on the page
|
692
|
+
# ff.ps.length # show how many p tags are on the page.
|
693
|
+
#
|
694
|
+
# Output:
|
695
|
+
# Ps object
|
696
|
+
#
|
697
|
+
def ps
|
698
|
+
locate if defined?(locate)
|
699
|
+
return Ps.new(self)
|
700
|
+
end
|
701
|
+
|
702
|
+
#
|
703
|
+
# Description:
|
704
|
+
# Used to access a pre element. Usually a <pre> HTML tag. For more details on this element
|
705
|
+
# visit http://www.xulplanet.com/references/objref/HTMLPreElement.html.
|
706
|
+
#
|
707
|
+
# Input:
|
708
|
+
# - how - The attribute used to identify the pre tag.
|
709
|
+
# - what - The value of that attribute.
|
710
|
+
#
|
711
|
+
# Typical Usage
|
712
|
+
#
|
713
|
+
# ff.pre(:id, /list/) # access the first pre tag that matches list.
|
714
|
+
# ff.pre(:index,2) # access the second pre tag on the page
|
715
|
+
#
|
716
|
+
# Output:
|
717
|
+
# Pre object.
|
718
|
+
#
|
719
|
+
def pre(how, what)
|
720
|
+
locate if defined?(locate)
|
721
|
+
return Pre.new(self, how, what)
|
722
|
+
end
|
723
|
+
|
724
|
+
#
|
725
|
+
# Description:
|
726
|
+
# Used for accessing all the Pre elements on the page. Returns a Pres object
|
727
|
+
#
|
728
|
+
# Typical usage:
|
729
|
+
#
|
730
|
+
# ff.pres.each { |pre| puts pre.to_s } # iterate through all the pre tags on the page
|
731
|
+
# ff.pres[1].to_s # goto the first pre tag on the page
|
732
|
+
# ff.pres.length # show how many pre tags are on the page.
|
733
|
+
#
|
734
|
+
# Output:
|
735
|
+
# Pres object
|
736
|
+
#
|
737
|
+
def pres
|
738
|
+
locate if defined?(locate)
|
739
|
+
return Pres.new(self)
|
740
|
+
end
|
741
|
+
|
742
|
+
#
|
743
|
+
# Description:
|
744
|
+
# Used to access label. Usually a <label> HTML tag. For more information on this
|
745
|
+
# tag visit http://www.xulplanet.com/references/objref/HTMLLabelElement.html.
|
746
|
+
#
|
747
|
+
# Inputs:
|
748
|
+
# - how - The attribute used to identify the label.
|
749
|
+
# - what - The value of that attribute.
|
750
|
+
#
|
751
|
+
# Typical Usage:
|
752
|
+
# ff.label(:id, /list/) # access the first label that matches list.
|
753
|
+
# ff.label(:index,2) # access the second label on the page
|
754
|
+
# ff.label(:for, "txt_1") # access a the label that is associated with the object that has an id of txt_1
|
755
|
+
#
|
756
|
+
# Output:
|
757
|
+
# Label object
|
758
|
+
#
|
759
|
+
def label(how, what)
|
760
|
+
locate if defined?(locate)
|
761
|
+
return Label.new(self, how, what)
|
762
|
+
end
|
763
|
+
|
764
|
+
#
|
765
|
+
# Description:
|
766
|
+
# Used for accessing all the Label elements on the page. Returns a Labels object
|
767
|
+
#
|
768
|
+
# Typical usage:
|
769
|
+
#
|
770
|
+
# ff.labels.each { |l| puts l.to_s } # iterate through all the labels on the page
|
771
|
+
# ff.labels[1].to_s # goto the first label on the page
|
772
|
+
# ff.labels.length # show how many labels are on the page.
|
773
|
+
#
|
774
|
+
# Output:
|
775
|
+
# Labels object
|
776
|
+
#
|
777
|
+
def labels
|
778
|
+
locate if defined?(locate)
|
779
|
+
return Labels.new(self)
|
780
|
+
end
|
781
|
+
|
782
|
+
# Description:
|
783
|
+
# Searching for Page Elements. Not for external consumption.
|
784
|
+
#
|
785
|
+
# def ole_inner_elements
|
786
|
+
# return document.body.all
|
787
|
+
# end
|
788
|
+
# private :ole_inner_elements
|
789
|
+
|
790
|
+
|
791
|
+
#
|
792
|
+
# Description:
|
793
|
+
# This method shows the available objects on the current page.
|
794
|
+
# This is usually only used for debugging or writing new test scripts.
|
795
|
+
# This is a nice feature to help find out what HTML objects are on a page
|
796
|
+
# when developing a test case using FireWatir.
|
797
|
+
#
|
798
|
+
# Typical Usage:
|
799
|
+
# ff.show_all_objects
|
800
|
+
#
|
801
|
+
# Output:
|
802
|
+
# Prints all the available elements on the page.
|
803
|
+
#
|
804
|
+
def show_all_objects
|
805
|
+
puts "-----------Objects in the current context-------------"
|
806
|
+
locate if defined?(locate)
|
807
|
+
elements = Document.new(self).all
|
808
|
+
puts elements.length
|
809
|
+
elements.each do |n|
|
810
|
+
puts n.tagName
|
811
|
+
puts n.to_s
|
812
|
+
puts "------------------------------------------"
|
813
|
+
end
|
814
|
+
puts "Total number of objects in the current context : #{elements.length}"
|
815
|
+
return elements
|
816
|
+
# Test the index access.
|
817
|
+
# puts doc[35].to_s
|
818
|
+
end
|
819
|
+
|
820
|
+
#
|
821
|
+
# Description:
|
822
|
+
# Reads the javascript execution result from the jssh socket.
|
823
|
+
#
|
824
|
+
# Input:
|
825
|
+
# - socket - It is the jssh socket, the only point of communication between the browser and firewatir scripts.
|
826
|
+
#
|
827
|
+
# Output:
|
828
|
+
# The javascript execution result as string.
|
829
|
+
#
|
830
|
+
def read_socket(socket = $jssh_socket)
|
831
|
+
return_value = ""
|
832
|
+
data = ""
|
833
|
+
#puts Thread.list
|
834
|
+
s = nil
|
835
|
+
while(s == nil) do
|
836
|
+
s = Kernel.select([socket] , nil , nil, 1)
|
837
|
+
end
|
838
|
+
#if(s != nil)
|
839
|
+
for stream in s[0]
|
840
|
+
data = stream.recv(1024)
|
841
|
+
#puts "data is : #{data}"
|
842
|
+
while(data[data.length - 3..data.length - 1] != "\n> ")
|
843
|
+
return_value += data
|
844
|
+
data = stream.recv(1024)
|
845
|
+
#puts "data length is : #{data.length}"
|
846
|
+
end
|
847
|
+
end
|
848
|
+
|
849
|
+
# If received data is less than 1024 characters or for last data
|
850
|
+
# we read in the above loop
|
851
|
+
return_value += data
|
852
|
+
|
853
|
+
# Get the command prompt inserted by JSSH
|
854
|
+
#s = Kernel.select([socket] , nil , nil, 0.3)
|
855
|
+
|
856
|
+
#if(s != nil)
|
857
|
+
# for stream in s[0]
|
858
|
+
# return_value += socket.recv(1024)
|
859
|
+
# end
|
860
|
+
#end
|
861
|
+
|
862
|
+
length = return_value.length
|
863
|
+
#puts "Return value before removing command prompt is : #{return_value}"
|
864
|
+
|
865
|
+
#Remove the command prompt. Every result returned by JSSH has "\n> " at the end.
|
866
|
+
if length <= 3
|
867
|
+
return_value = ""
|
868
|
+
elsif(return_value[0..2] == "\n> ")
|
869
|
+
return_value = return_value[3..length-1]
|
870
|
+
else
|
871
|
+
#return_value = return_value[0..length-3]
|
872
|
+
return_value = return_value[0..length-4]
|
873
|
+
end
|
874
|
+
#puts "Return value after removing command prompt is : #{return_value}"
|
875
|
+
#socket.flush
|
876
|
+
|
877
|
+
# make sure that command prompt doesn't get there.
|
878
|
+
if(return_value[return_value.length - 3..return_value.length - 1] == "\n> ")
|
879
|
+
return_value = return_value[0..return_value.length - 4]
|
880
|
+
end
|
881
|
+
if(return_value[0..2] == "\n> ")
|
882
|
+
return_value = return_value[3..return_value.length - 1]
|
883
|
+
end
|
884
|
+
#puts "return value is : #{return_value}"
|
885
|
+
return return_value
|
886
|
+
end
|
887
|
+
|
888
|
+
end # module
|
889
|
+
|