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,188 @@
1
+ module FireWatir
2
+ #
3
+ # Description:
4
+ # Class for SelectList element.
5
+ #
6
+ class SelectList < InputElement
7
+ INPUT_TYPES = ["select-one", "select-multiple"]
8
+
9
+ attr_accessor :o
10
+
11
+ #
12
+ # Description:
13
+ # Clears the selected items in the select box.
14
+ #
15
+ def clear
16
+ assert_exists
17
+ #highlight( :set)
18
+ wait = false
19
+ each do |selectBoxItem|
20
+ if selectBoxItem.selected
21
+ selectBoxItem.selected = false
22
+ wait = true
23
+ end
24
+ end
25
+ self.wait if wait
26
+ #highlight( :clear)
27
+ end
28
+ alias clearSelection clear
29
+
30
+ def each
31
+ assert_exists
32
+ arr_options = js_options
33
+ #puts arr_options[0]#.length
34
+ for i in 0..arr_options.length - 1 do
35
+ yield Option.new(self, :jssh_name, arr_options[i])
36
+ end
37
+ end
38
+
39
+ #
40
+ # Description:
41
+ # Get option element at specified index in select list.
42
+ #
43
+ # Input:
44
+ # key - option index
45
+ #
46
+ # Output:
47
+ # Option element at specified index
48
+ #
49
+ def [] (key)
50
+ assert_exists
51
+ arr_options = js_options
52
+ return Option.new(self, :jssh_name, arr_options[key - 1])
53
+ end
54
+
55
+ #
56
+ # Description:
57
+ # Selects an item by text. If you need to select multiple items you need to call this function for each item.
58
+ #
59
+ # Input:
60
+ # - item - Text of item to be selected.
61
+ #
62
+ def select( item )
63
+ select_items_in_select_list(:text, item)
64
+ end
65
+ alias :set :select
66
+
67
+ #
68
+ # Description:
69
+ # Selects an item by value. If you need to select multiple items you need to call this function for each item.
70
+ #
71
+ # Input:
72
+ # - item - Value of the item to be selected.
73
+ #
74
+ def select_value( item )
75
+ select_items_in_select_list(:value, item)
76
+ end
77
+
78
+ #
79
+ # Description:
80
+ # Gets all the items in the select list as an array.
81
+ # An empty array is returned if the select box has no contents.
82
+ #
83
+ # Output:
84
+ # Array containing the items of the select list.
85
+ #
86
+ def options
87
+ assert_exists
88
+ #element.log "There are #{@o.length} items"
89
+ returnArray = []
90
+ each { |thisItem| returnArray << thisItem.text }
91
+ return returnArray
92
+ end
93
+
94
+ alias getAllContents options
95
+
96
+ #
97
+ # Description:
98
+ # Gets all the selected items in the select list as an array.
99
+ # An empty array is returned if the select box has no selected item.
100
+ #
101
+ # Output:
102
+ # Array containing the selected items of the select list.
103
+ #
104
+ def selected_options
105
+ assert_exists
106
+ returnArray = []
107
+ #element.log "There are #{@o.length} items"
108
+ each do |thisItem|
109
+ #puts "#{thisItem.selected}"
110
+ if thisItem.selected
111
+ #element.log "Item ( #{thisItem.text} ) is selected"
112
+ returnArray << thisItem.text
113
+ end
114
+ end
115
+ return returnArray
116
+ end
117
+
118
+ alias getSelectedItems selected_options
119
+
120
+ #
121
+ # Description:
122
+ # Get the option using attribute and its value.
123
+ #
124
+ # Input:
125
+ # - attribute - Attribute used to find the option.
126
+ # - value - value of that attribute.
127
+ #
128
+ def option (attribute, value)
129
+ assert_exists
130
+ Option.new(self, attribute, value)
131
+ end
132
+
133
+ private
134
+
135
+ # Description:
136
+ # Selects items from the select box.
137
+ #
138
+ # Input:
139
+ # - name - :value or :text - how we find an item in the select box
140
+ # - item - value of either item text or item value.
141
+ #
142
+ def select_items_in_select_list(attribute, value)
143
+ assert_exists
144
+
145
+ attribute = attribute.to_s
146
+ found = false
147
+
148
+ value = value.to_s unless [Regexp, String].any? { |e| value.kind_of? e }
149
+
150
+ highlight( :set )
151
+ each do |option|
152
+ next unless value.matches(option.invoke(attribute))
153
+ found = true
154
+ next if option.selected
155
+
156
+ option.selected = true
157
+ fireEvent("onChange")
158
+ wait
159
+ end
160
+ highlight( :clear )
161
+
162
+ unless found
163
+ raise NoValueFoundException, "No option with #{attribute} of #{value.inspect} in this select element"
164
+ end
165
+
166
+ value
167
+ end
168
+
169
+ #
170
+ # Description:
171
+ # Gets all the options of the select list element.
172
+ #
173
+ # Output:
174
+ # Array of option elements.
175
+ #
176
+ def js_options
177
+ jssh_socket.send("#{element_object}.options.length;\n", 0)
178
+ length = read_socket().to_i
179
+ # puts "options length is : #{length}"
180
+ arr_options = Array.new(length)
181
+ for i in 0..length - 1
182
+ arr_options[i] = "#{element_object}.options[#{i}]"
183
+ end
184
+ return arr_options
185
+ end
186
+
187
+ end # Selects
188
+ end # FireWatir
@@ -0,0 +1,218 @@
1
+ module FireWatir
2
+ class Table < Element
3
+ attr_accessor :element_name
4
+ TAG = 'TABLE'
5
+
6
+ # - how - Attribute to identify the table element.
7
+ # - what - Value of that attribute.
8
+ def initialize(container, how, what)
9
+ @how = how
10
+ @what = what
11
+ @container = container
12
+ @o = nil
13
+ #super nil
14
+ end
15
+
16
+ #
17
+ # Description:
18
+ # Locate the table element.
19
+ #
20
+ def locate
21
+ case @how
22
+ when :jssh_name
23
+ @element_name = @what
24
+ when :xpath
25
+ @element_name = element_by_xpath(@container, @what)
26
+ else
27
+ @element_name = locate_tagged_element('TABLE', @how, @what)
28
+ end
29
+ @o = self
30
+ end
31
+
32
+ #
33
+ # Description:
34
+ # Override the highlight method, as if the tables rows are set to have a background color,
35
+ # this will override the table background color, and the normal flash method wont work
36
+ #
37
+ def highlight(set_or_clear )
38
+
39
+ if set_or_clear == :set
40
+ begin
41
+ @original_border = @o.border.to_i
42
+ if @o.border.to_i==1
43
+ @o.border = 2
44
+ else
45
+ @o.border=1
46
+ end
47
+ rescue
48
+ @original_border = nil
49
+ end
50
+ else
51
+ begin
52
+ @o.border= @original_border unless @original_border == nil
53
+ @original_border = nil
54
+ rescue
55
+ # we could be here for a number of reasons...
56
+ ensure
57
+ @original_border = nil
58
+ end
59
+ end
60
+ super
61
+ end
62
+
63
+ #
64
+ # Description:
65
+ # Used to populate the properties in the to_s method.
66
+ #
67
+ #def table_string_creator
68
+ # n = []
69
+ # n << "rows:".ljust(TO_S_SIZE) + self.row_count.to_s
70
+ # n << "cols:".ljust(TO_S_SIZE) + self.column_count.to_s
71
+ # return n
72
+ #end
73
+ #private :table_string_creator
74
+
75
+ # returns the properties of the object in a string
76
+ # raises an ObjectNotFound exception if the object cannot be found
77
+ # TODO: Implement to_s method for this class.
78
+
79
+ def to_s
80
+ assert_exists
81
+ r = super({"rows" => "rows.length","columns" => "columnLength", "cellspacing" => "cellspacing", "cellpadding" => "cellpadding", "border" => "border"})
82
+ # r += self.column_count.to_s
83
+ end
84
+
85
+ #
86
+ # Description:
87
+ # Gets the number of rows in the table.
88
+ #
89
+ # Output:
90
+ # Number of rows.
91
+ #
92
+ def row_count
93
+ assert_exists
94
+ return rows.length
95
+ end
96
+
97
+ #
98
+ # Description:
99
+ # Gets the table as a 2 dimensional array. Dont expect too much if there are nested tables, colspan etc.
100
+ #
101
+ # Output:
102
+ # 2D array with rows and column text of the table.
103
+ #
104
+ def to_a
105
+ assert_exists
106
+ y = []
107
+ table_rows = rows
108
+ for row in table_rows
109
+ x = []
110
+ row.each do |td|
111
+ x << td.to_s.strip
112
+ end
113
+ y << x
114
+ end
115
+ return y
116
+ end
117
+
118
+ #
119
+ # Description:
120
+ # Gets the array of rows in the table.
121
+ #
122
+ # Output:
123
+ # Array of rows.
124
+ #
125
+ def rows
126
+ assert_exists
127
+ arr_rows = get_rows
128
+ table_rows = Array.new(arr_rows.length)
129
+ for i in 0..arr_rows.length - 1 do
130
+ table_rows[i] = TableRow.new(@container, :jssh_name, arr_rows[i])
131
+ end
132
+ return table_rows
133
+ end
134
+
135
+ #
136
+ # Description:
137
+ # Get row at particular index in table.
138
+ #
139
+ # Input:
140
+ # key - row index
141
+ #
142
+ # Output:
143
+ # Table Row element
144
+ #
145
+ def [](key)
146
+ assert_exists
147
+ arr_rows = rows
148
+ return arr_rows[key - 1]
149
+ end
150
+
151
+ #
152
+ # Desription:
153
+ # Iterate over each table row element.
154
+ #
155
+ def each
156
+ assert_exists
157
+ arr_rows = rows
158
+ for i in 0..arr_rows.length - 1 do
159
+ yield arr_rows[i]
160
+ end
161
+ end
162
+
163
+ #
164
+ # Description:
165
+ # Get column count of first row in the table.
166
+ #
167
+ # Output:
168
+ # Number of columns in first row.
169
+ #
170
+ def column_count
171
+ assert_exists
172
+ arr_rows = rows
173
+ return arr_rows[0].column_count
174
+ end
175
+
176
+ #
177
+ # Description:
178
+ # Get values of specified column in each row.
179
+ #
180
+ # Input:
181
+ # Column number
182
+ #
183
+ # Output:
184
+ # Values of column (specified as input) in each row
185
+ #
186
+ def column_values(column)
187
+ assert_exists
188
+ arr_rows = rows
189
+ values = Array.new(arr_rows.length)
190
+ for i in 0..arr_rows.length - 1 do
191
+ values[i] = arr_rows[i][column].to_s
192
+ end
193
+ return values
194
+ end
195
+
196
+ #
197
+ # Description:
198
+ # Get values of all the column in specified row.
199
+ #
200
+ # Input:
201
+ # Row number.
202
+ #
203
+ # Output:
204
+ # Value of all columns present in the row.
205
+ #
206
+ def row_values(row)
207
+ assert_exists
208
+ arr_rows = rows
209
+ cells = arr_rows[row - 1].cells
210
+ values = Array.new(cells.length)
211
+ for i in 0..cells.length - 1 do
212
+ values[i] = cells[i].to_s
213
+ end
214
+ return values
215
+ end
216
+
217
+ end # Table
218
+ end # FireWatir
@@ -0,0 +1,54 @@
1
+ module FireWatir
2
+ #
3
+ # Description:
4
+ # Class for Table Cell.
5
+ #
6
+ class TableCell < Element
7
+ attr_accessor :element_name
8
+
9
+ # Description:
10
+ # Locate the table cell element on the page.
11
+ #
12
+ def locate
13
+ case @how
14
+ when :jssh_name
15
+ @element_name = @what
16
+ when :xpath
17
+ @element_name = element_by_xpath(@container, @what)
18
+ else
19
+ @element_name = locate_tagged_element("TD", @how, @what)
20
+ end
21
+ @o = self
22
+ end
23
+
24
+ #
25
+ # Description:
26
+ # Initializes the instance of table cell object.
27
+ #
28
+ # Input:
29
+ # - how - Attribute to identify the table cell element.
30
+ # - what - Value of that attribute.
31
+ #
32
+ def initialize(container, how, what)
33
+ @how = how
34
+ @what = what
35
+ @container = container
36
+ #super nil
37
+ end
38
+
39
+ alias to_s text
40
+
41
+ #
42
+ # Description:
43
+ # Gets the col span of table cell.
44
+ #
45
+ # Output:
46
+ # Colspan of table cell.
47
+ #
48
+ def colspan
49
+ assert_exists
50
+ @o.colSpan
51
+ end
52
+
53
+ end # TableCell
54
+ end # FireWatir