firewatir 1.6.2 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +32 -0
- data/lib/firewatir.rb +40 -50
- data/lib/firewatir/container.rb +491 -534
- data/lib/firewatir/document.rb +239 -0
- data/lib/firewatir/element.rb +1365 -0
- data/lib/firewatir/element_collections.rb +314 -0
- data/lib/firewatir/elements/button.rb +15 -0
- data/lib/firewatir/elements/file_field.rb +29 -0
- data/lib/firewatir/elements/form.rb +40 -0
- data/lib/firewatir/elements/frame.rb +55 -0
- data/lib/firewatir/elements/hidden.rb +56 -0
- data/lib/firewatir/elements/image.rb +139 -0
- data/lib/firewatir/elements/input_element.rb +44 -0
- data/lib/firewatir/elements/link.rb +76 -0
- data/lib/firewatir/elements/non_control_element.rb +53 -0
- data/lib/firewatir/elements/non_control_elements.rb +108 -0
- data/lib/firewatir/elements/not_used.rb +278 -0
- data/lib/firewatir/elements/option.rb +131 -0
- data/lib/firewatir/elements/radio_check_common.rb +163 -0
- data/lib/firewatir/elements/select_list.rb +188 -0
- data/lib/firewatir/elements/table.rb +218 -0
- data/lib/firewatir/elements/table_cell.rb +54 -0
- data/lib/firewatir/elements/table_row.rb +100 -0
- data/lib/firewatir/elements/text_field.rb +218 -0
- data/lib/firewatir/exceptions.rb +10 -10
- data/lib/firewatir/firefox.rb +1040 -1127
- data/lib/firewatir/jssh_socket.rb +101 -0
- data/lib/firewatir/version.rb +5 -5
- data/unittests/attach_to_new_window_test.rb +49 -42
- data/unittests/bug_fixes_test.rb +195 -198
- data/unittests/buttons_xpath_test.rb +88 -88
- data/unittests/checkbox_test.rb +158 -155
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/div_test.rb +275 -276
- data/unittests/filefield_test.rb +49 -45
- data/unittests/filefield_xpath_test.rb +35 -35
- data/unittests/form_test.rb +296 -308
- data/unittests/frame_test.rb +159 -152
- data/unittests/hidden_test.rb +85 -85
- data/unittests/hidden_xpath_test.rb +72 -72
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +61 -61
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/div.html +72 -72
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +45 -45
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/iframeTest.html +14 -14
- data/unittests/html/iframeTest1.html +13 -13
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/links1.html +42 -42
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +1 -0
- data/unittests/html/new_browser_popup.html +8 -0
- data/unittests/html/pass.html +9 -9
- data/unittests/html/pre.html +27 -27
- data/unittests/html/redirect.html +10 -10
- data/unittests/html/redirect1.html +8 -8
- data/unittests/html/redirect2.html +8 -8
- data/unittests/html/redirect3.html +8 -8
- data/unittests/html/simple_table_columns.html +74 -74
- data/unittests/html/table1.html +165 -165
- data/unittests/html/textfields1.html +62 -62
- data/unittests/images_test.rb +198 -205
- data/unittests/images_xpath_test.rb +118 -119
- data/unittests/javascript_test.rb +75 -75
- data/unittests/links_test.rb +231 -232
- data/unittests/links_xpath_test.rb +79 -79
- data/unittests/mozilla_all_tests.rb +7 -7
- data/unittests/pre_test.rb +75 -76
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/redirect_test.rb +41 -41
- data/unittests/selectbox_test.rb +142 -142
- data/unittests/selectbox_xpath_test.rb +129 -129
- data/unittests/setup.rb +29 -30
- data/unittests/table_test.rb +385 -373
- data/unittests/table_xpath_test.rb +185 -185
- data/unittests/textfields_test.rb +234 -233
- data/unittests/textfields_xpath_test.rb +113 -113
- metadata +33 -11
- data/lib/firewatir/MozillaBaseElement.rb +0 -1863
- data/lib/firewatir/htmlelements.rb +0 -1911
- data/unittests/iostring.rb +0 -30
- data/unittests/iostring_test.rb +0 -48
@@ -0,0 +1,314 @@
|
|
1
|
+
module FireWatir
|
2
|
+
|
3
|
+
#
|
4
|
+
# Description:
|
5
|
+
# Class for iterating over elements of common type like links, images, divs etc.
|
6
|
+
#
|
7
|
+
class ElementCollections
|
8
|
+
include Enumerable
|
9
|
+
include JsshSocket
|
10
|
+
|
11
|
+
def self.inherited subclass
|
12
|
+
class_name = subclass.to_s.demodulize
|
13
|
+
method_name = class_name.underscore
|
14
|
+
element_class_name = class_name.singularize
|
15
|
+
|
16
|
+
FireWatir::Container.module_eval "def #{method_name}
|
17
|
+
locate if respond_to?(:locate)
|
18
|
+
return #{class_name}.new(self); end"
|
19
|
+
|
20
|
+
subclass.class_eval "def element_class; #{element_class_name}; end"
|
21
|
+
end
|
22
|
+
|
23
|
+
@@current_level = 0
|
24
|
+
|
25
|
+
def initialize(container)
|
26
|
+
@container = container
|
27
|
+
elements = locate_elements
|
28
|
+
length = elements.length
|
29
|
+
#puts "length is : #{length}"
|
30
|
+
@element_objects = Array.new(length)
|
31
|
+
for i in 0..length - 1 do
|
32
|
+
@element_objects[i] = element_class.new(container, :jssh_name, elements[i])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# default implementation. overridden by some subclasses.
|
37
|
+
def locate_elements
|
38
|
+
locate_tagged_elements(element_class::TAG)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Return all the elements of give tag and type inside the container.
|
43
|
+
#
|
44
|
+
# Input:
|
45
|
+
# tag - tag name of the elements
|
46
|
+
# types - array of element type names. used in case where same
|
47
|
+
# element tag has different types like input has type image, button etc.
|
48
|
+
#
|
49
|
+
def locate_tagged_elements(tag, types = [])
|
50
|
+
|
51
|
+
# generate array to hold results
|
52
|
+
result_name = "arr_coll_#{tag}_#{@@current_level}"
|
53
|
+
jssh_command = "var #{result_name}=new Array();"
|
54
|
+
|
55
|
+
# generate array of elements matching the tag
|
56
|
+
case @container
|
57
|
+
when FireWatir::Firefox, FireWatir::Frame
|
58
|
+
elements_tag = "elements_#{tag}"
|
59
|
+
container_name = "#{@container.document_var}"
|
60
|
+
else
|
61
|
+
elements_tag = "elements_#{@@current_level}_#{tag}"
|
62
|
+
container_name = @container.element_name
|
63
|
+
end
|
64
|
+
if types.include?("textarea") || types.include?("button")
|
65
|
+
search_tag = '*'
|
66
|
+
else
|
67
|
+
search_tag = tag
|
68
|
+
end
|
69
|
+
jssh_command << "var #{elements_tag} = null; "
|
70
|
+
jssh_command << "#{elements_tag} = #{container_name}.getElementsByTagName(\"#{search_tag}\");"
|
71
|
+
|
72
|
+
|
73
|
+
# generate array containing results
|
74
|
+
if types.empty?
|
75
|
+
jssh_command << "#{result_name} = #{elements_tag};"
|
76
|
+
else
|
77
|
+
# generate types array
|
78
|
+
jssh_command << "var types = new Array("
|
79
|
+
types.each_with_index do |type, count|
|
80
|
+
jssh_command << "," unless count == 0
|
81
|
+
jssh_command << "\"#{type}\""
|
82
|
+
end
|
83
|
+
jssh_command << ");"
|
84
|
+
|
85
|
+
# check the type of each element
|
86
|
+
jssh_command << "
|
87
|
+
for(var i=0; i<#{elements_tag}.length; i++)
|
88
|
+
{
|
89
|
+
var element = #{elements_tag} [i];
|
90
|
+
var same_type = false;
|
91
|
+
|
92
|
+
for (var j = 0; j < types.length; j++)
|
93
|
+
{
|
94
|
+
if (types[j] == element.type || types[j] == element.tagName)
|
95
|
+
{
|
96
|
+
same_type = true;
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
if (same_type)
|
102
|
+
{
|
103
|
+
#{result_name}.push(element);
|
104
|
+
}
|
105
|
+
};"
|
106
|
+
end
|
107
|
+
jssh_command << "#{result_name}.length;"
|
108
|
+
|
109
|
+
# Remove \n that are there in the string as a result of pressing enter while formatting.
|
110
|
+
jssh_command.gsub!(/\n/, "")
|
111
|
+
#puts jssh_command
|
112
|
+
jssh_socket.send("#{jssh_command};\n", 0)
|
113
|
+
length = read_socket().to_i;
|
114
|
+
#puts "elements length is in locate_tagged_elements is : #{length}"
|
115
|
+
|
116
|
+
elements = (0...length).collect {|i| "#{result_name}[#{i}]"}
|
117
|
+
|
118
|
+
@@current_level = @@current_level + 1
|
119
|
+
return elements
|
120
|
+
end
|
121
|
+
private :locate_tagged_elements
|
122
|
+
|
123
|
+
#
|
124
|
+
# Description:
|
125
|
+
# Gets the length of elements of same tag and type found on the page.
|
126
|
+
#
|
127
|
+
# Ouput:
|
128
|
+
# Count of elements found on the page.
|
129
|
+
#
|
130
|
+
def length
|
131
|
+
return @element_objects.length
|
132
|
+
end
|
133
|
+
alias_method :size, :length
|
134
|
+
|
135
|
+
#
|
136
|
+
# Description:
|
137
|
+
# Iterate over the elements of same tag and type found on the page.
|
138
|
+
#
|
139
|
+
def each
|
140
|
+
for i in 0..@element_objects.length - 1
|
141
|
+
yield @element_objects[i]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# Description:
|
147
|
+
# Accesses nth element of same tag and type found on the page.
|
148
|
+
#
|
149
|
+
# Input:
|
150
|
+
# n - index of element (1 based)
|
151
|
+
#
|
152
|
+
def [](n)
|
153
|
+
return @element_objects[n-1]
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# Returns the first element in the collection.
|
158
|
+
#
|
159
|
+
|
160
|
+
def first
|
161
|
+
@element_objects.first
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# Returns the last element in the collection.
|
166
|
+
#
|
167
|
+
|
168
|
+
def last
|
169
|
+
@element_objects.last
|
170
|
+
end
|
171
|
+
|
172
|
+
def to_s
|
173
|
+
map { |e| e.to_s }.join("\n")
|
174
|
+
end
|
175
|
+
|
176
|
+
def inspect
|
177
|
+
'#<%s:0x%x length=%s container=%s> elements=%s>' %
|
178
|
+
[self.class, hash*2, length.inspect, @container.inspect, @element_objects.inspect]
|
179
|
+
end
|
180
|
+
|
181
|
+
end # ElementCollections
|
182
|
+
|
183
|
+
# Class for accessing all the button elements in the document.
|
184
|
+
# It would normally only be accessed by the FireWatir::Container#buttons method
|
185
|
+
class Buttons < ElementCollections
|
186
|
+
def locate_elements
|
187
|
+
locate_tagged_elements("input", ["button", "image", "submit", "reset"])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Class for accessing all the File Field elements in the document.
|
192
|
+
# It would normally only be accessed by the FireWatir::Container#file_fields method
|
193
|
+
class FileFields < ElementCollections
|
194
|
+
def locate_elements
|
195
|
+
locate_tagged_elements("input", ["file"])
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# Class for accessing all the CheckBox elements in the document.
|
200
|
+
# It would normally only be accessed by the FireWatir::Container#checkboxes method
|
201
|
+
class CheckBoxes < ElementCollections
|
202
|
+
def locate_elements
|
203
|
+
locate_tagged_elements("input", ["checkbox"])
|
204
|
+
end
|
205
|
+
end
|
206
|
+
module Container
|
207
|
+
alias checkboxes check_boxes
|
208
|
+
end
|
209
|
+
|
210
|
+
# Class for accessing all the Radio button elements in the document.
|
211
|
+
# It would normally only be accessed by the FireWatir::Container#radios method
|
212
|
+
class Radios < ElementCollections
|
213
|
+
def locate_elements
|
214
|
+
locate_tagged_elements("input", ["radio"])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Class for accessing all the select list elements in the document.
|
219
|
+
# It would normally only be accessed by the FireWatir::Container#select_lists method
|
220
|
+
class SelectLists < ElementCollections
|
221
|
+
def locate_elements
|
222
|
+
locate_tagged_elements("select", ["select-one", "select-multiple"])
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# Class for accessing all the link elements in the document.
|
227
|
+
# It would normally only be accessed by the FireWatir::Container#links method
|
228
|
+
class Links < ElementCollections; end
|
229
|
+
|
230
|
+
# Class for accessing all the image elements in the document.
|
231
|
+
# It would normally only be accessed by the FireWatir::Container#images method
|
232
|
+
class Images < ElementCollections; end
|
233
|
+
|
234
|
+
# Class for accessing all the text field elements in the document.
|
235
|
+
# It would normally only be accessed by the FireWatir::Container#text_fields method
|
236
|
+
class TextFields < ElementCollections
|
237
|
+
def locate_elements
|
238
|
+
locate_tagged_elements("input", ["text", "textarea", "password"])
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
# Class for accessing all the hidden elements in the document.
|
243
|
+
# It would normally only be accessed by the FireWatir::Container#hiddens method
|
244
|
+
class Hiddens < ElementCollections
|
245
|
+
def locate_elements
|
246
|
+
locate_tagged_elements("input", ["hidden"])
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# Class for accessing all the table elements in the document.
|
251
|
+
# It would normally only be accessed by the FireWatir::Container#tables method
|
252
|
+
class Tables < ElementCollections; end
|
253
|
+
|
254
|
+
# Class for accessing all the label elements in the document.
|
255
|
+
# It would normally only be accessed by the FireWatir::Container#labels method
|
256
|
+
class Labels < ElementCollections; end
|
257
|
+
|
258
|
+
# Class for accessing all the pre element in the document.
|
259
|
+
# It would normally only be accessed by the FireWatir::Container#pres method
|
260
|
+
class Pres < ElementCollections; end
|
261
|
+
|
262
|
+
# Class for accessing all the paragraph elements in the document.
|
263
|
+
# It would normally only be accessed by the FireWatir::Container#ps method
|
264
|
+
class Ps < ElementCollections; end
|
265
|
+
|
266
|
+
# Class for accessing all the span elements in the document.
|
267
|
+
# It would normally only be accessed by the FireWatir::Container#spans method
|
268
|
+
class Spans < ElementCollections; end
|
269
|
+
|
270
|
+
# Class for accessing all the strong elements in the document.
|
271
|
+
# It would normally only be accessed by the FireWatir::Container#strongs method
|
272
|
+
class Strongs < ElementCollections; end
|
273
|
+
|
274
|
+
# Class for accessing all the div elements in the document.
|
275
|
+
# It would normally only be accessed by the FireWatir::Container#divs method
|
276
|
+
class Divs < ElementCollections; end
|
277
|
+
|
278
|
+
# Class for accessing all the ul elements in the document.
|
279
|
+
# It would normally only be accessed by the FireWatir::Container#uls method
|
280
|
+
class Uls < ElementCollections; end
|
281
|
+
|
282
|
+
# Class for accessing all the li elements in the document.
|
283
|
+
# It would normally only be accessed by the FireWatir::Container#lis method
|
284
|
+
class Lis < ElementCollections; end
|
285
|
+
|
286
|
+
# Class for accessing all the dl elements in the document.
|
287
|
+
# It would normally only be accessed by the FireWatir::Container#dls method
|
288
|
+
class Dls < ElementCollections; end
|
289
|
+
|
290
|
+
# Class for accessing all the dt elements in the document.
|
291
|
+
# It would normally only be accessed by the FireWatir::Container#dts method
|
292
|
+
class Dts < ElementCollections; end
|
293
|
+
|
294
|
+
# Class for accessing all the dd elements in the document.
|
295
|
+
# It would normally only be accessed by the FireWatir::Container#dds method
|
296
|
+
class Dds < ElementCollections; end
|
297
|
+
|
298
|
+
# Class for accessing all the dd elements in the document.
|
299
|
+
# It would normally only be accessed by the FireWatir::Container#dds method
|
300
|
+
class Ems < ElementCollections; end
|
301
|
+
|
302
|
+
# Class for accessing all the area elements in the document.
|
303
|
+
# It would normally only be accessed by the FireWatir::Container#areas method
|
304
|
+
class Areas < ElementCollections; end
|
305
|
+
|
306
|
+
# Class for accessing all the body elements in the document.
|
307
|
+
# It would normally only be accessed by the FireWatir::Container#bodies method
|
308
|
+
class Bodies < ElementCollections; end
|
309
|
+
|
310
|
+
# Class for accessing all the dd elements in the document.
|
311
|
+
# It would normally only be accessed by the FireWatir::Container#maps method
|
312
|
+
class Maps < ElementCollections; end
|
313
|
+
|
314
|
+
end # FireWatir
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FireWatir
|
2
|
+
#
|
3
|
+
# Description:
|
4
|
+
# Class for Button element.
|
5
|
+
#
|
6
|
+
class Button < InputElement
|
7
|
+
INPUT_TYPES = ["button", "submit", "image", "reset"]
|
8
|
+
|
9
|
+
def locate
|
10
|
+
super
|
11
|
+
@o = @element.locate_tagged_element("button", @how, @what, self.class::INPUT_TYPES) unless @o
|
12
|
+
end
|
13
|
+
|
14
|
+
end # Button
|
15
|
+
end # FireWatir
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FireWatir
|
2
|
+
#
|
3
|
+
# Description:
|
4
|
+
# Class for FileField element.
|
5
|
+
#
|
6
|
+
class FileField < InputElement
|
7
|
+
INPUT_TYPES = ["file"]
|
8
|
+
|
9
|
+
#
|
10
|
+
# Description:
|
11
|
+
# Sets the path of the file in the textbox.
|
12
|
+
#
|
13
|
+
# Input:
|
14
|
+
# path - Path of the file.
|
15
|
+
#
|
16
|
+
def set(path)
|
17
|
+
assert_exists
|
18
|
+
|
19
|
+
path.gsub!("\\", "\\\\\\")
|
20
|
+
|
21
|
+
jssh_socket.send("#{element_object}.value = \"#{path}\";\n", 0)
|
22
|
+
read_socket()
|
23
|
+
@o.fireEvent("onChange")
|
24
|
+
|
25
|
+
@@current_level = 0
|
26
|
+
end
|
27
|
+
|
28
|
+
end # FileField
|
29
|
+
end # FireWatir
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module FireWatir
|
2
|
+
class Form < Element
|
3
|
+
|
4
|
+
attr_accessor :element_name
|
5
|
+
#
|
6
|
+
# Description:
|
7
|
+
# Initializes the instance of form object.
|
8
|
+
#
|
9
|
+
# Input:
|
10
|
+
# - how - Attribute to identify the form element.
|
11
|
+
# - what - Value of that attribute.
|
12
|
+
#
|
13
|
+
def initialize(container, how, what)
|
14
|
+
@how = how
|
15
|
+
@what = what
|
16
|
+
@container = container
|
17
|
+
end
|
18
|
+
|
19
|
+
def locate
|
20
|
+
# Get form using xpath.
|
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("form", @how, @what)
|
28
|
+
end
|
29
|
+
@o = self
|
30
|
+
end
|
31
|
+
|
32
|
+
# Submit the form. Equivalent to pressing Enter or Return to submit a form.
|
33
|
+
def submit
|
34
|
+
assert_exists
|
35
|
+
submit_form
|
36
|
+
@o.wait
|
37
|
+
end
|
38
|
+
|
39
|
+
end # Form
|
40
|
+
end # FireWatir
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module FireWatir
|
2
|
+
class Frame < Element
|
3
|
+
|
4
|
+
attr_accessor :element_name
|
5
|
+
#
|
6
|
+
# Description:
|
7
|
+
# Initializes the instance of frame or iframe object.
|
8
|
+
#
|
9
|
+
# Input:
|
10
|
+
# - how - Attribute to identify the frame element.
|
11
|
+
# - what - Value of that attribute.
|
12
|
+
#
|
13
|
+
def initialize(container, how, what)
|
14
|
+
@how = how
|
15
|
+
@what = what
|
16
|
+
@container = container
|
17
|
+
end
|
18
|
+
|
19
|
+
def locate
|
20
|
+
if(@how == :jssh_name)
|
21
|
+
@element_name = @what
|
22
|
+
else
|
23
|
+
@element_name = locate_frame(@how, @what)
|
24
|
+
end
|
25
|
+
#puts @element_name
|
26
|
+
@o = self
|
27
|
+
|
28
|
+
unless @element_name
|
29
|
+
raise UnknownFrameException, "Unable to locate a frame using #{@how} and #{@what}. "
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def html
|
34
|
+
assert_exists
|
35
|
+
get_frame_html
|
36
|
+
end
|
37
|
+
|
38
|
+
def document_var # unfinished
|
39
|
+
"document"
|
40
|
+
end
|
41
|
+
|
42
|
+
def body_var # unfinished
|
43
|
+
"body"
|
44
|
+
end
|
45
|
+
|
46
|
+
def window_var
|
47
|
+
"window"
|
48
|
+
end
|
49
|
+
|
50
|
+
def browser_var
|
51
|
+
"browser"
|
52
|
+
end
|
53
|
+
|
54
|
+
end # Frame
|
55
|
+
end # FireWatir
|