firewatir 1.6.2 → 1.6.5

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