firewatir 1.6.5 → 1.6.6.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +461 -0
- data/LICENSE +31 -31
- data/README.rdoc +112 -0
- data/VERSION +1 -0
- data/lib/firewatir.rb +41 -40
- data/lib/firewatir/container.rb +491 -491
- data/lib/firewatir/document.rb +239 -239
- data/lib/firewatir/element.rb +1364 -1364
- data/lib/firewatir/element_collections.rb +314 -314
- data/lib/firewatir/elements/button.rb +15 -15
- data/lib/firewatir/elements/file_field.rb +29 -29
- data/lib/firewatir/elements/form.rb +40 -40
- data/lib/firewatir/elements/frame.rb +55 -55
- data/lib/firewatir/elements/hidden.rb +56 -56
- data/lib/firewatir/elements/image.rb +139 -139
- data/lib/firewatir/elements/input_element.rb +44 -44
- data/lib/firewatir/elements/link.rb +76 -76
- data/lib/firewatir/elements/non_control_element.rb +53 -53
- data/lib/firewatir/elements/non_control_elements.rb +108 -108
- data/lib/firewatir/elements/not_used.rb +278 -278
- data/lib/firewatir/elements/option.rb +130 -130
- data/lib/firewatir/elements/radio_check_common.rb +163 -163
- data/lib/firewatir/elements/select_list.rb +188 -188
- data/lib/firewatir/elements/table.rb +218 -218
- data/lib/firewatir/elements/table_cell.rb +54 -54
- data/lib/firewatir/elements/table_row.rb +100 -100
- data/lib/firewatir/elements/text_field.rb +218 -218
- data/lib/firewatir/exceptions.rb +10 -10
- data/lib/firewatir/firefox.rb +984 -1040
- data/lib/firewatir/jssh_socket.rb +100 -100
- data/lib/firewatir/winClicker.rb +122 -122
- data/lib/firewatir/x11.rb +192 -192
- data/rakefile.rb +15 -0
- data/unittests/attach_to_new_window_test.rb +49 -49
- data/unittests/bug_fixes_test.rb +195 -195
- data/unittests/buttons_xpath_test.rb +88 -88
- data/unittests/checkbox_test.rb +158 -158
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/div_test.rb +275 -275
- data/unittests/ff_test.rb +47 -0
- data/unittests/filefield_test.rb +49 -49
- data/unittests/filefield_xpath_test.rb +35 -35
- data/unittests/form_test.rb +296 -296
- data/unittests/frame_test.rb +159 -159
- data/unittests/hidden_test.rb +85 -85
- data/unittests/hidden_xpath_test.rb +72 -72
- data/unittests/html/JavascriptClick.html +42 -42
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +61 -61
- data/unittests/html/checkboxes1.html +70 -70
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/div.html +72 -72
- data/unittests/html/div_xml.html +20 -20
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +45 -45
- data/unittests/html/forms3.html +132 -132
- data/unittests/html/forms4.html +27 -27
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/frame_links.html +3 -3
- data/unittests/html/frame_multi.html +4 -4
- data/unittests/html/iframeTest.html +14 -14
- data/unittests/html/iframeTest1.html +13 -13
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/images1.html +66 -66
- data/unittests/html/javascriptevents.html +35 -35
- data/unittests/html/link_pass.html +10 -10
- data/unittests/html/links1.html +42 -42
- data/unittests/html/links2.html +10 -10
- data/unittests/html/modal_dialog.html +8 -8
- data/unittests/html/modal_dialog_launcher.html +11 -11
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +17 -17
- data/unittests/html/new_browser_popup.html +7 -7
- data/unittests/html/pass.html +9 -9
- data/unittests/html/popups1.html +60 -60
- data/unittests/html/pre.html +27 -27
- data/unittests/html/radioButtons1.html +70 -70
- 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/select_tealeaf.html +54 -54
- data/unittests/html/selectboxes1.html +55 -55
- data/unittests/html/simple_table.html +26 -26
- data/unittests/html/simple_table_buttons.html +104 -104
- data/unittests/html/simple_table_columns.html +74 -74
- data/unittests/html/table1.html +165 -165
- data/unittests/html/tableCell_using_xpath.html +19 -19
- data/unittests/html/textarea.html +30 -30
- data/unittests/html/textfields1.html +62 -62
- data/unittests/html/textsearch.html +44 -44
- data/unittests/images_test.rb +198 -198
- data/unittests/images_xpath_test.rb +118 -118
- data/unittests/javascript_test.rb +75 -75
- data/unittests/links_test.rb +231 -231
- data/unittests/links_xpath_test.rb +79 -79
- data/unittests/mozilla_all_tests.rb +7 -7
- data/unittests/pre_test.rb +75 -75
- data/unittests/radios_test.rb +166 -166
- 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 -29
- data/unittests/table_test.rb +385 -385
- data/unittests/table_xpath_test.rb +185 -185
- data/unittests/textfields_test.rb +234 -234
- data/unittests/textfields_xpath_test.rb +113 -113
- metadata +51 -19
- data/lib/firewatir/version.rb +0 -5
@@ -1,15 +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
|
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
|
@@ -1,29 +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
|
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
|
@@ -1,40 +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
|
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
|
@@ -1,55 +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
|
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
|
@@ -1,56 +1,56 @@
|
|
1
|
-
module FireWatir
|
2
|
-
#
|
3
|
-
# Description:
|
4
|
-
# Class for Hidden Field element.
|
5
|
-
#
|
6
|
-
class Hidden < TextField
|
7
|
-
INPUT_TYPES = ["hidden"]
|
8
|
-
|
9
|
-
#
|
10
|
-
# Description:
|
11
|
-
# Sets the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
|
12
|
-
#
|
13
|
-
# Input:
|
14
|
-
# n - Value to be set.
|
15
|
-
#
|
16
|
-
def set(n)
|
17
|
-
self.value=n
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# Description:
|
22
|
-
# Appends the value to the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
|
23
|
-
#
|
24
|
-
# Input:
|
25
|
-
# n - Value to be appended.
|
26
|
-
#
|
27
|
-
def append(n)
|
28
|
-
self.value = self.value.to_s + n.to_s
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Description:
|
33
|
-
# Clears the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
|
34
|
-
#
|
35
|
-
def clear
|
36
|
-
self.value = ""
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# Description:
|
41
|
-
# Does nothing, as you cant set focus to a hidden field. Overridden here so that exception doesn't occurs.
|
42
|
-
#
|
43
|
-
def focus
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Description:
|
48
|
-
# Hidden element is never visible - returns false.
|
49
|
-
#
|
50
|
-
def visible?
|
51
|
-
assert_exists
|
52
|
-
false
|
53
|
-
end
|
54
|
-
|
55
|
-
end # Hidden
|
56
|
-
end # FireWatir
|
1
|
+
module FireWatir
|
2
|
+
#
|
3
|
+
# Description:
|
4
|
+
# Class for Hidden Field element.
|
5
|
+
#
|
6
|
+
class Hidden < TextField
|
7
|
+
INPUT_TYPES = ["hidden"]
|
8
|
+
|
9
|
+
#
|
10
|
+
# Description:
|
11
|
+
# Sets the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
|
12
|
+
#
|
13
|
+
# Input:
|
14
|
+
# n - Value to be set.
|
15
|
+
#
|
16
|
+
def set(n)
|
17
|
+
self.value=n
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Description:
|
22
|
+
# Appends the value to the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
|
23
|
+
#
|
24
|
+
# Input:
|
25
|
+
# n - Value to be appended.
|
26
|
+
#
|
27
|
+
def append(n)
|
28
|
+
self.value = self.value.to_s + n.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Description:
|
33
|
+
# Clears the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
|
34
|
+
#
|
35
|
+
def clear
|
36
|
+
self.value = ""
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Description:
|
41
|
+
# Does nothing, as you cant set focus to a hidden field. Overridden here so that exception doesn't occurs.
|
42
|
+
#
|
43
|
+
def focus
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Description:
|
48
|
+
# Hidden element is never visible - returns false.
|
49
|
+
#
|
50
|
+
def visible?
|
51
|
+
assert_exists
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
end # Hidden
|
56
|
+
end # FireWatir
|
@@ -1,139 +1,139 @@
|
|
1
|
-
module FireWatir
|
2
|
-
#
|
3
|
-
# Description:
|
4
|
-
# Class for Image element.
|
5
|
-
#
|
6
|
-
class Image < Element
|
7
|
-
attr_accessor :element_name
|
8
|
-
TAG = 'IMG'
|
9
|
-
#
|
10
|
-
# Description:
|
11
|
-
# Initializes the instance of image object.
|
12
|
-
#
|
13
|
-
# Input:
|
14
|
-
# - how - Attribute to identify the image element.
|
15
|
-
# - what - Value of that attribute.
|
16
|
-
#
|
17
|
-
def initialize(container, how, what)
|
18
|
-
@how = how
|
19
|
-
@what = what
|
20
|
-
@container = container
|
21
|
-
end
|
22
|
-
|
23
|
-
# Description:
|
24
|
-
# Locate the image element on the page.
|
25
|
-
#
|
26
|
-
def locate
|
27
|
-
case @how
|
28
|
-
when:jssh_name
|
29
|
-
@element_name = @what
|
30
|
-
when :xpath
|
31
|
-
@element_name = element_by_xpath(@container, @what)
|
32
|
-
else
|
33
|
-
@element_name = locate_tagged_element('IMG', @how, @what)
|
34
|
-
end
|
35
|
-
@o = self
|
36
|
-
end
|
37
|
-
|
38
|
-
#
|
39
|
-
# Description:
|
40
|
-
# Used to populate the properties in to_s method. Not used anymore
|
41
|
-
#
|
42
|
-
def image_string_creator
|
43
|
-
n = []
|
44
|
-
n << "src:".ljust(TO_S_SIZE) + self.src.to_s
|
45
|
-
n << "file date:".ljust(TO_S_SIZE) + self.fileCreatedDate.to_s
|
46
|
-
n << "file size:".ljust(TO_S_SIZE) + self.fileSize.to_s
|
47
|
-
n << "width:".ljust(TO_S_SIZE) + self.width.to_s
|
48
|
-
n << "height:".ljust(TO_S_SIZE) + self.height.to_s
|
49
|
-
n << "alt:".ljust(TO_S_SIZE) + self.alt.to_s
|
50
|
-
return n
|
51
|
-
end
|
52
|
-
private :image_string_creator
|
53
|
-
|
54
|
-
# returns a string representation of the object
|
55
|
-
def to_s
|
56
|
-
assert_exists
|
57
|
-
super({"src" => "src","width" => "width","height" => "height","alt" => "alt"})
|
58
|
-
end
|
59
|
-
|
60
|
-
# this method returns the file created date of the image
|
61
|
-
#def file_created_date
|
62
|
-
# assert_exists
|
63
|
-
# return @o.invoke("fileCreatedDate")
|
64
|
-
#end
|
65
|
-
# alias fileCreatedDate file_created_date
|
66
|
-
|
67
|
-
# this method returns the filesize of the image
|
68
|
-
#def file_size
|
69
|
-
# assert_exists
|
70
|
-
# return @o.invoke("fileSize").to_s
|
71
|
-
#end
|
72
|
-
# alias fileSize file_size
|
73
|
-
|
74
|
-
#
|
75
|
-
# Description:
|
76
|
-
# Gets the width of the image in pixels, as a string.
|
77
|
-
#
|
78
|
-
# Output:
|
79
|
-
# Width of image (in pixels).
|
80
|
-
#
|
81
|
-
def width
|
82
|
-
assert_exists
|
83
|
-
return @o.invoke("width").to_s
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Description:
|
88
|
-
# Gets the height of the image in pixels, as a string.
|
89
|
-
#
|
90
|
-
# Output:
|
91
|
-
# Height of image (in pixels).
|
92
|
-
#
|
93
|
-
def height
|
94
|
-
assert_exists
|
95
|
-
return @o.invoke("height").to_s
|
96
|
-
end
|
97
|
-
|
98
|
-
# This method attempts to find out if the image was actually loaded by the web browser.
|
99
|
-
# If the image was not loaded, the browser is unable to determine some of the properties.
|
100
|
-
# We look for these missing properties to see if the image is really there or not.
|
101
|
-
# If the Disk cache is full ( tools menu -> Internet options -> Temporary Internet Files) , it may produce incorrect responses.
|
102
|
-
#def has_loaded
|
103
|
-
# locate
|
104
|
-
# raise UnknownObjectException, "Unable to locate image using #{@how} and #{@what}" if @o == nil
|
105
|
-
# return false if @o.fileCreatedDate == "" and @o.fileSize.to_i == -1
|
106
|
-
# return true
|
107
|
-
#end
|
108
|
-
# alias hasLoaded? loaded?
|
109
|
-
|
110
|
-
#
|
111
|
-
# Description:
|
112
|
-
# Highlights the image ( in fact it adds or removes a border around the image)
|
113
|
-
#
|
114
|
-
# Input:
|
115
|
-
# - set_or_clear - :set to set the border, :clear to remove it
|
116
|
-
#
|
117
|
-
def highlight( set_or_clear )
|
118
|
-
if set_or_clear == :set
|
119
|
-
begin
|
120
|
-
@original_border = @o.border
|
121
|
-
@o.border = 1
|
122
|
-
rescue
|
123
|
-
@original_border = nil
|
124
|
-
end
|
125
|
-
else
|
126
|
-
begin
|
127
|
-
@o.border = @original_border
|
128
|
-
@original_border = nil
|
129
|
-
rescue
|
130
|
-
# we could be here for a number of reasons...
|
131
|
-
ensure
|
132
|
-
@original_border = nil
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
private :highlight
|
137
|
-
|
138
|
-
end # Image
|
139
|
-
end # FireWatir
|
1
|
+
module FireWatir
|
2
|
+
#
|
3
|
+
# Description:
|
4
|
+
# Class for Image element.
|
5
|
+
#
|
6
|
+
class Image < Element
|
7
|
+
attr_accessor :element_name
|
8
|
+
TAG = 'IMG'
|
9
|
+
#
|
10
|
+
# Description:
|
11
|
+
# Initializes the instance of image object.
|
12
|
+
#
|
13
|
+
# Input:
|
14
|
+
# - how - Attribute to identify the image element.
|
15
|
+
# - what - Value of that attribute.
|
16
|
+
#
|
17
|
+
def initialize(container, how, what)
|
18
|
+
@how = how
|
19
|
+
@what = what
|
20
|
+
@container = container
|
21
|
+
end
|
22
|
+
|
23
|
+
# Description:
|
24
|
+
# Locate the image element on the page.
|
25
|
+
#
|
26
|
+
def locate
|
27
|
+
case @how
|
28
|
+
when:jssh_name
|
29
|
+
@element_name = @what
|
30
|
+
when :xpath
|
31
|
+
@element_name = element_by_xpath(@container, @what)
|
32
|
+
else
|
33
|
+
@element_name = locate_tagged_element('IMG', @how, @what)
|
34
|
+
end
|
35
|
+
@o = self
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Description:
|
40
|
+
# Used to populate the properties in to_s method. Not used anymore
|
41
|
+
#
|
42
|
+
def image_string_creator
|
43
|
+
n = []
|
44
|
+
n << "src:".ljust(TO_S_SIZE) + self.src.to_s
|
45
|
+
n << "file date:".ljust(TO_S_SIZE) + self.fileCreatedDate.to_s
|
46
|
+
n << "file size:".ljust(TO_S_SIZE) + self.fileSize.to_s
|
47
|
+
n << "width:".ljust(TO_S_SIZE) + self.width.to_s
|
48
|
+
n << "height:".ljust(TO_S_SIZE) + self.height.to_s
|
49
|
+
n << "alt:".ljust(TO_S_SIZE) + self.alt.to_s
|
50
|
+
return n
|
51
|
+
end
|
52
|
+
private :image_string_creator
|
53
|
+
|
54
|
+
# returns a string representation of the object
|
55
|
+
def to_s
|
56
|
+
assert_exists
|
57
|
+
super({"src" => "src","width" => "width","height" => "height","alt" => "alt"})
|
58
|
+
end
|
59
|
+
|
60
|
+
# this method returns the file created date of the image
|
61
|
+
#def file_created_date
|
62
|
+
# assert_exists
|
63
|
+
# return @o.invoke("fileCreatedDate")
|
64
|
+
#end
|
65
|
+
# alias fileCreatedDate file_created_date
|
66
|
+
|
67
|
+
# this method returns the filesize of the image
|
68
|
+
#def file_size
|
69
|
+
# assert_exists
|
70
|
+
# return @o.invoke("fileSize").to_s
|
71
|
+
#end
|
72
|
+
# alias fileSize file_size
|
73
|
+
|
74
|
+
#
|
75
|
+
# Description:
|
76
|
+
# Gets the width of the image in pixels, as a string.
|
77
|
+
#
|
78
|
+
# Output:
|
79
|
+
# Width of image (in pixels).
|
80
|
+
#
|
81
|
+
def width
|
82
|
+
assert_exists
|
83
|
+
return @o.invoke("width").to_s
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Description:
|
88
|
+
# Gets the height of the image in pixels, as a string.
|
89
|
+
#
|
90
|
+
# Output:
|
91
|
+
# Height of image (in pixels).
|
92
|
+
#
|
93
|
+
def height
|
94
|
+
assert_exists
|
95
|
+
return @o.invoke("height").to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
# This method attempts to find out if the image was actually loaded by the web browser.
|
99
|
+
# If the image was not loaded, the browser is unable to determine some of the properties.
|
100
|
+
# We look for these missing properties to see if the image is really there or not.
|
101
|
+
# If the Disk cache is full ( tools menu -> Internet options -> Temporary Internet Files) , it may produce incorrect responses.
|
102
|
+
#def has_loaded
|
103
|
+
# locate
|
104
|
+
# raise UnknownObjectException, "Unable to locate image using #{@how} and #{@what}" if @o == nil
|
105
|
+
# return false if @o.fileCreatedDate == "" and @o.fileSize.to_i == -1
|
106
|
+
# return true
|
107
|
+
#end
|
108
|
+
# alias hasLoaded? loaded?
|
109
|
+
|
110
|
+
#
|
111
|
+
# Description:
|
112
|
+
# Highlights the image ( in fact it adds or removes a border around the image)
|
113
|
+
#
|
114
|
+
# Input:
|
115
|
+
# - set_or_clear - :set to set the border, :clear to remove it
|
116
|
+
#
|
117
|
+
def highlight( set_or_clear )
|
118
|
+
if set_or_clear == :set
|
119
|
+
begin
|
120
|
+
@original_border = @o.border
|
121
|
+
@o.border = 1
|
122
|
+
rescue
|
123
|
+
@original_border = nil
|
124
|
+
end
|
125
|
+
else
|
126
|
+
begin
|
127
|
+
@o.border = @original_border
|
128
|
+
@original_border = nil
|
129
|
+
rescue
|
130
|
+
# we could be here for a number of reasons...
|
131
|
+
ensure
|
132
|
+
@original_border = nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
private :highlight
|
137
|
+
|
138
|
+
end # Image
|
139
|
+
end # FireWatir
|