firewatir 1.6.2 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,278 @@
1
+ # # this class is a collection of the table body objects that exist in the table
2
+ # # it wouldnt normally be created by a user, but gets returned by the bodies method of the Table object
3
+ # # many of the methods available to this object are inherited from the Element class
4
+ # # TODO: Implement TableBodies class.
5
+ # class TableBodies < Element
6
+ #
7
+ # # Description:
8
+ # # Initializes the form element.
9
+ # #
10
+ # # Input:
11
+ # # - how - Attribute to identify the form element.
12
+ # # - what - Value of that attribute.
13
+ # #
14
+ # def initialize( parent_table)
15
+ # element = container
16
+ # @o = parent_table # in this case, @o is the parent table
17
+ # end
18
+ #
19
+ # # returns the number of TableBodies that exist in the table
20
+ # def length
21
+ # assert_exists
22
+ # return @o.tBodies.length
23
+ # end
24
+ #
25
+ # # returns the n'th Body as a FireWatir TableBody object
26
+ # def []n
27
+ # assert_exists
28
+ # return TableBody.new(element, :direct, ole_table_body_at_index(n))
29
+ # end
30
+ #
31
+ # # returns an ole table body
32
+ # def ole_table_body_at_index(n)
33
+ # return @o.tBodies[(n-1).to_s]
34
+ # end
35
+ #
36
+ # # iterates through each of the TableBodies in the Table. Yields a TableBody object
37
+ # def each
38
+ # 1.upto( @o.tBodies.length ) { |i| yield TableBody.new(element, :direct, ole_table_body_at_index(i)) }
39
+ # end
40
+ #
41
+ # end # TableBodies
42
+ #
43
+ # # this class is a table body
44
+ # # TODO: Implement TableBody class
45
+ # class TableBody < Element
46
+ # def locate
47
+ # @o = nil
48
+ # if @how == :direct
49
+ # @o = @what # in this case, @o is the table body
50
+ # elsif @how == :index
51
+ # @o = @parent_table.bodies.ole_table_body_at_index(@what)
52
+ # end
53
+ # @rows = []
54
+ # if @o
55
+ # @o.rows.each do |oo|
56
+ # @rows << TableRow.new(element, :direct, oo)
57
+ # end
58
+ # end
59
+ # end
60
+ #
61
+ #
62
+ # # Description:
63
+ # # Initializes the form element.
64
+ # #
65
+ # # Input:
66
+ # # - how - Attribute to identify the form element.
67
+ # # - what - Value of that attribute.
68
+ # #
69
+ # def initialize( how, what, parent_table = nil)
70
+ # element = container
71
+ # @how = how
72
+ # @what = what
73
+ # @parent_table = parent_table
74
+ # super nil
75
+ # end
76
+ #
77
+ # # returns the specified row as a TableRow object
78
+ # def [](n)
79
+ # assert_exists
80
+ # return @rows[n - 1]
81
+ # end
82
+ #
83
+ # # iterates through all the rows in the table body
84
+ # def each
85
+ # locate
86
+ # 0.upto(@rows.length - 1) { |i| yield @rows[i] }
87
+ # end
88
+ #
89
+ # # returns the number of rows in this table body.
90
+ # def length
91
+ # return @rows.length
92
+ # end
93
+ # end # TableBody
94
+
95
+ # # this class is the super class for the iterator classes ( buttons, links, spans etc
96
+ # # it would normally only be accessed by the iterator methods ( spans , links etc) of IE
97
+ # class ElementCollections
98
+ # include Enumerable
99
+ # include Container
100
+ #
101
+ # # Super class for all the iteractor classes
102
+ # # * container - an instance of an IE object
103
+ # def initialize( container)
104
+ # element = container
105
+ # @length = length() # defined by subclasses
106
+ #
107
+ # # set up the items we want to display when the show method s used
108
+ # set_show_items
109
+ # end
110
+ #
111
+ # private
112
+ # def set_show_items
113
+ # @show_attributes = AttributeLengthPairs.new( "id" , 20)
114
+ # @show_attributes.add( "name" , 20)
115
+ # end
116
+ #
117
+ # public
118
+ # def get_length_of_input_objects(object_type)
119
+ # object_types =
120
+ # if object_type.kind_of? Array
121
+ # object_type
122
+ # else
123
+ # [ object_type ]
124
+ # end
125
+ #
126
+ # length = 0
127
+ # objects = element.document.getElementsByTagName("INPUT")
128
+ # if objects.length > 0
129
+ # objects.each do |o|
130
+ # length += 1 if object_types.include?(o.invoke("type").downcase )
131
+ # end
132
+ # end
133
+ # return length
134
+ # end
135
+ #
136
+ # # iterate through each of the elements in the collection in turn
137
+ # def each
138
+ # 0.upto( @length-1 ) { |i | yield iterator_object(i) }
139
+ # end
140
+ #
141
+ # # allows access to a specific item in the collection
142
+ # def [](n)
143
+ # return iterator_object(n-1)
144
+ # end
145
+ #
146
+ # # this method is the way to show the objects, normally used from irb
147
+ # def show
148
+ # s="index".ljust(6)
149
+ # @show_attributes.each do |attribute_length_pair|
150
+ # s=s + attribute_length_pair.attribute.ljust(attribute_length_pair.length)
151
+ # end
152
+ #
153
+ # index = 1
154
+ # self.each do |o|
155
+ # s= s+"\n"
156
+ # s=s + index.to_s.ljust(6)
157
+ # @show_attributes.each do |attribute_length_pair|
158
+ # begin
159
+ # s=s + eval( 'o.getOLEObject.invoke("#{attribute_length_pair.attribute}")').to_s.ljust( attribute_length_pair.length )
160
+ # rescue=>e
161
+ # s=s+ " ".ljust( attribute_length_pair.length )
162
+ # end
163
+ # end
164
+ # index+=1
165
+ # end
166
+ # puts s
167
+ # end
168
+ #
169
+ # # this method creates an object of the correct type that the iterators use
170
+ # private
171
+ # def iterator_object(i)
172
+ # element_class.new(element, :index, i+1)
173
+ # end
174
+ # end
175
+ #
176
+ # # --
177
+ # # These classes are not for public consumption, so we switch off rdoc
178
+ # #
179
+ # # presumes element_class or element_tag is defined
180
+ # # for subclasses of ElementCollections
181
+ # module CommonCollection
182
+ # def element_tag
183
+ # element_class.tag
184
+ # end
185
+ # def length
186
+ # element.document.getElementsByTagName(element_tag).length
187
+ # end
188
+ # end
189
+ #
190
+ # # This class is used as part of the .show method of the iterators class
191
+ # # it would not normally be used by a user
192
+ # class AttributeLengthPairs
193
+ #
194
+ # # This class is used as part of the .show method of the iterators class
195
+ # # it would not normally be used by a user
196
+ # class AttributeLengthHolder
197
+ # attr_accessor :attribute
198
+ # attr_accessor :length
199
+ #
200
+ # def initialize( attrib, length)
201
+ # @attribute = attrib
202
+ # @length = length
203
+ # end
204
+ # end
205
+ #
206
+ # def initialize( attrib=nil , length=nil)
207
+ # @attr=[]
208
+ # add( attrib , length ) if attrib
209
+ # @index_counter=0
210
+ # end
211
+ #
212
+ # # BUG: Untested. (Null implementation passes all tests.)
213
+ # def add( attrib , length)
214
+ # @attr << AttributeLengthHolder.new( attrib , length )
215
+ # end
216
+ #
217
+ # def delete(attrib)
218
+ # item_to_delete=nil
219
+ # @attr.each_with_index do |e,i|
220
+ # item_to_delete = i if e.attribute==attrib
221
+ # end
222
+ # @attr.delete_at(item_to_delete ) unless item_to_delete == nil
223
+ # end
224
+ #
225
+ # def next
226
+ # temp = @attr[@index_counter]
227
+ # @index_counter +=1
228
+ # return temp
229
+ # end
230
+ #
231
+ # def each
232
+ # 0.upto( @attr.length-1 ) { |i | yield @attr[i] }
233
+ # end
234
+ # end
235
+ #
236
+
237
+ #
238
+ #
239
+ # # Module for handling the Javascript pop-ups. Not in use currently, will be available in future.
240
+ # # Use ff.startClicker() method for clicking javascript pop ups. Refer to unit tests on how to handle
241
+ # # javascript pop up (unittests/javascript_test.rb)
242
+ # module Dialog
243
+ # # Class for handling javascript popup. Not in use currently, will be available in future. See unit tests on how to handle
244
+ # # javascript pop up (unittests/javascript_test.rb).
245
+ # class JSPopUp
246
+ # include Container
247
+ #
248
+ # def has_appeared(text)
249
+ # require 'socket'
250
+ # sleep 4
251
+ # shell = TCPSocket.new("localhost", 9997)
252
+ # read_socket(shell)
253
+ # #jssh_command = "var url = document.URL;"
254
+ # jssh_command = "var length = getWindows().length; var win;length;\n"
255
+ # #jssh_command << "for(var i = 0; i < length; i++)"
256
+ # #jssh_command << "{"
257
+ # #jssh_command << " win = getWindows()[i];"
258
+ # #jssh_command << " if(win.opener != null && "
259
+ # #jssh_command << " win.title == \"[JavaScript Application]\" &&"
260
+ # #jssh_command << " win.opener.document.URL == url)"
261
+ # #jssh_command << " {"
262
+ # #jssh_command << " break;"
263
+ # #jssh_command << " }"
264
+ # #jssh_command << "}"
265
+ #
266
+ # #jssh_command << " win.title;\n";
267
+ # #jssh_command << "var dialog = win.document.childNodes[0];"
268
+ # #jssh_command << "vbox = dialog.childNodes[1].childNodes[1];"
269
+ # #jssh_command << "vbox.childNodes[1].childNodes[0].childNodes[0].textContent;\n"
270
+ # puts jssh_command
271
+ # shell.send("#{jssh_command}", 0)
272
+ # jstext = read_socket(shell)
273
+ # puts jstext
274
+ # return jstext == text
275
+ # end
276
+ # end # JSPopUp
277
+ # end # Dialog
278
+ #
@@ -0,0 +1,131 @@
1
+ module FireWatir
2
+ #
3
+ # Description:
4
+ # Class for Option element.
5
+ #
6
+ class Option < InputElement
7
+ #
8
+ # Description:
9
+ # Initializes the instance of option object.
10
+ #
11
+ # Input:
12
+ # - select_list - instance of select list element.
13
+ # - attribute - Attribute to identify the option.
14
+ # - value - Value of that attribute.
15
+ #
16
+ def initialize (select_list, attribute, value)
17
+ @select_list = @container = select_list
18
+ @how = attribute
19
+ @what = value
20
+ @option = nil
21
+ @element_name = ""
22
+
23
+ unless [:text, :value, :jssh_name].include? attribute
24
+ raise MissingWayOfFindingObjectException,
25
+ "Option does not support attribute #{@how}"
26
+ end
27
+ #puts @select_list.o.length
28
+ #puts "what is : #{@what}, how is #{@how}, list name is : #{@select_list.element_name}"
29
+ if(attribute == :jssh_name)
30
+ @element_name = @what
31
+ @option = self
32
+ else
33
+ @select_list.o.each do |option| # items in the list
34
+ #puts "option is : #{option}"
35
+ if(attribute == :value)
36
+ match_value = option.value
37
+ else
38
+ match_value = option.text
39
+ end
40
+ #puts "value is #{match_value}"
41
+ if value.matches( match_value) #option.invoke(attribute))
42
+ @option = option
43
+ @element_name = option.element_name
44
+ break
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ #
51
+ # Description:
52
+ # Checks if option exists or not.
53
+ #
54
+ def assert_exists
55
+ unless @option
56
+ raise UnknownObjectException,
57
+ "Unable to locate an option using #{@how} and #{@what}"
58
+ end
59
+ end
60
+ private :assert_exists
61
+
62
+ #
63
+ # Description:
64
+ # Selects the option.
65
+ #
66
+ def select
67
+ assert_exists
68
+ if(@how == :text)
69
+ @select_list.select(@what)
70
+ elsif(@how == :value)
71
+ @select_list.select_value(@what)
72
+ end
73
+ end
74
+
75
+ #
76
+ # Description:
77
+ # Gets the class name of the option.
78
+ #
79
+ # Output:
80
+ # Class name of the option.
81
+ #
82
+ def class_name
83
+ assert_exists
84
+ jssh_socket.send("#{element_object}.className;\n", 0)
85
+ return read_socket()
86
+ end
87
+
88
+ #
89
+ # Description:
90
+ # Gets the text of the option.
91
+ #
92
+ # Output:
93
+ # Text of the option.
94
+ #
95
+ def text
96
+ assert_exists
97
+ jssh_socket.send("#{element_object}.text;\n", 0)
98
+ return read_socket()
99
+ end
100
+
101
+ #
102
+ # Description:
103
+ # Gets the value of the option.
104
+ #
105
+ # Output:
106
+ # Value of the option.
107
+ #
108
+ def value
109
+ assert_exists
110
+ jssh_socket.send("#{element_object}.value;\n", 0)
111
+ return read_socket()
112
+ end
113
+
114
+ #
115
+ # Description:
116
+ # Gets the status of the option; whether it is selected or not.
117
+ #
118
+ # Output:
119
+ # True if option is selected, false otherwise.
120
+ #
121
+ def selected
122
+ assert_exists
123
+ jssh_socket.send("#{element_object}.selected;\n", 0)
124
+ value = read_socket()
125
+ return true if value == "true"
126
+ return false if value == "false"
127
+ end
128
+
129
+
130
+ end # Option
131
+ end # FireWatir
@@ -0,0 +1,163 @@
1
+ module FireWatir
2
+ #
3
+ # Description:
4
+ # Base class for checkbox and radio button elements.
5
+ #
6
+ class RadioCheckCommon < Element
7
+ attr_accessor :element_name
8
+ #
9
+ # Description:
10
+ # Initializes the instance of element object. Element can be checkbox or radio button.
11
+ #
12
+ # Input:
13
+ # - how - Attribute to identify the element.
14
+ # - what - Value of that attribute.
15
+ # - value - value of the element.
16
+ #
17
+ def initialize(container, how, what, value = nil)
18
+ @how = how
19
+ @what = what
20
+ @value = value
21
+ @container = container
22
+ end
23
+
24
+ #
25
+ # Description:
26
+ # Locate the element on the page. Element can be a checkbox or radio button.
27
+ #
28
+ def locate
29
+ case @how
30
+ when :jssh_name
31
+ @element_name = @what
32
+ when :xpath
33
+ @element_name = element_by_xpath(@container, @what)
34
+ else
35
+ @element_name = locate_tagged_element("input", @how, @what, @type, @value)
36
+ end
37
+ @o = self
38
+ end
39
+
40
+ #
41
+ # Description:
42
+ # Checks if element i.e. radio button or check box is checked or not.
43
+ #
44
+ # Output:
45
+ # True if element is checked, false otherwise.
46
+ #
47
+ def set?
48
+ assert_exists
49
+ return @o.checked
50
+ end
51
+ alias getState set?
52
+ alias checked? set?
53
+ alias isSet? set?
54
+
55
+ #
56
+ # Description:
57
+ # Unchecks the radio button or check box element.
58
+ # Raises ObjectDisabledException exception if element is disabled.
59
+ #
60
+ def clear
61
+ assert_exists
62
+ assert_enabled
63
+ #highlight(:set)
64
+ set_clear_item(false)
65
+ #highlight(:clear)
66
+ end
67
+
68
+ #
69
+ # Description:
70
+ # Checks the radio button or check box element.
71
+ # Raises ObjectDisabledException exception if element is disabled.
72
+ #
73
+ def set
74
+ assert_exists
75
+ assert_enabled
76
+ #highlight(:set)
77
+ set_clear_item(true)
78
+ #highlight(:clear)
79
+ end
80
+
81
+ #
82
+ # Description:
83
+ # Used by clear and set method to uncheck and check radio button and checkbox element respectively.
84
+ #
85
+ def set_clear_item(set)
86
+ @o.fire_event("onclick")
87
+ @container.wait
88
+ end
89
+ private :set_clear_item
90
+
91
+ end # RadioCheckCommon
92
+
93
+ #
94
+ # Description:
95
+ # Class for RadioButton element.
96
+ #
97
+ class Radio < RadioCheckCommon
98
+ def initialize *args
99
+ super
100
+ @type = ["radio"]
101
+ end
102
+
103
+ def clear
104
+ assert_exists
105
+ assert_enabled
106
+ #higlight(:set)
107
+ @o.checked = false
108
+ #highlight(:clear)
109
+ end
110
+
111
+ end # Radio
112
+
113
+ #
114
+ # Description:
115
+ # Class for Checkbox element.
116
+ #
117
+ class CheckBox < RadioCheckCommon
118
+ def initialize *args
119
+ super
120
+ @type = ["checkbox"]
121
+ end
122
+
123
+ #
124
+ # Description:
125
+ # Checks or unchecks the checkbox. If no value is supplied it will check the checkbox.
126
+ # Raises ObjectDisabledException exception if the object is disabled
127
+ #
128
+ # Input:
129
+ # - set_or_clear - Parameter indicated whether to check or uncheck the checkbox.
130
+ # True to check the check box, false for unchecking the checkbox.
131
+ #
132
+ def set( set_or_clear=true )
133
+ assert_exists
134
+ assert_enabled
135
+ highlight(:set)
136
+
137
+ if set_or_clear == true
138
+ if @o.checked == false
139
+ set_clear_item( true )
140
+ end
141
+ else
142
+ self.clear
143
+ end
144
+ highlight(:clear )
145
+ end
146
+
147
+ #
148
+ # Description:
149
+ # Unchecks the checkbox.
150
+ # Raises ObjectDisabledException exception if the object is disabled
151
+ #
152
+ def clear
153
+ assert_exists
154
+ assert_enabled
155
+ highlight( :set)
156
+ if @o.checked == true
157
+ set_clear_item( false )
158
+ end
159
+ highlight( :clear)
160
+ end
161
+
162
+ end # CheckBox
163
+ end # FireWatir