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
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,44 @@
1
+ module FireWatir
2
+ #
3
+ # Description:
4
+ # Base class containing items that are common between select list, text field, button, hidden, file field classes.
5
+ #
6
+ class InputElement < Element
7
+ attr_accessor :element_name
8
+ #
9
+ # Description:
10
+ # Locate the element on the page. Element can be a select list, text field, button, hidden, file field.
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
+ if(self.class::INPUT_TYPES.include?("select-one"))
20
+ @element_name = locate_tagged_element("select", @how, @what, self.class::INPUT_TYPES)
21
+ else
22
+ @element_name = locate_tagged_element("input", @how, @what, self.class::INPUT_TYPES)
23
+ end
24
+ end
25
+ @o = self
26
+ end
27
+ #
28
+ # Description:
29
+ # Initializes the instance of element.
30
+ #
31
+ # Input:
32
+ # - how - Attribute to identify the element.
33
+ # - what - Value of that attribute.
34
+ #
35
+ def initialize(container, how, what)
36
+ @how = how
37
+ @what = what
38
+ @container = container
39
+ @element_name = ""
40
+ #super(nil)
41
+ end
42
+
43
+ end # FireWatir
44
+ end # InputElement
@@ -0,0 +1,76 @@
1
+ module FireWatir
2
+ #
3
+ # Description:
4
+ # Class for Link element.
5
+ #
6
+ class Link < Element
7
+ attr_accessor :element_name
8
+ TAG = 'A'
9
+ #
10
+ # Description:
11
+ # Initializes the instance of link element.
12
+ #
13
+ # Input:
14
+ # - how - Attribute to identify the link 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
+ #
24
+ # Description:
25
+ # Locate the link element on the page.
26
+ #
27
+ def locate
28
+ case @how
29
+ when :jssh_name
30
+ @element_name = @what
31
+ when :xpath
32
+ @element_name = element_by_xpath(@container, @what)
33
+ else
34
+ @element_name = locate_tagged_element('A', @how, @what)
35
+ end
36
+ @o = self
37
+ end
38
+
39
+ #TODO: if an image is used as part of the link, this will return true
40
+ #def link_has_image
41
+ # assert_exists
42
+ # return true if @o.getElementsByTagName("IMG").length > 0
43
+ # return false
44
+ #end
45
+
46
+ #TODO: this method returns the src of an image, if an image is used as part of the link
47
+ #def src # BUG?
48
+ # assert_exists
49
+ # if @o.getElementsByTagName("IMG").length > 0
50
+ # return @o.getElementsByTagName("IMG")[0.to_s].src
51
+ # else
52
+ # return ""
53
+ # end
54
+ #end
55
+
56
+ #
57
+ # Description:
58
+ # Used to populate the properties in to_s method.
59
+ #
60
+ #def link_string_creator
61
+ # n = []
62
+ # n << "href:".ljust(TO_S_SIZE) + self.href
63
+ # n << "inner text:".ljust(TO_S_SIZE) + self.text
64
+ # n << "img src:".ljust(TO_S_SIZE) + self.src if self.link_has_image
65
+ # return n
66
+ # end
67
+
68
+ # returns a textual description of the link
69
+
70
+ def to_s
71
+ assert_exists
72
+ super({"href" => "href","inner text" => "text"})
73
+ end
74
+
75
+ end # Link
76
+ end # FireWatir
@@ -0,0 +1,53 @@
1
+ module FireWatir
2
+
3
+ # Base class containing items that are common between the span, div, label, p and pre classes.
4
+ class NonControlElement < Element
5
+ def self.inherited subclass
6
+ class_name = subclass.to_s.demodulize
7
+ method_name = class_name.underscore
8
+ FireWatir::Container.module_eval "def #{method_name}(how, what=nil)
9
+ locate if respond_to?(:locate)
10
+ return #{class_name}.new(self, how, what); end"
11
+ end
12
+
13
+ attr_accessor :element_name
14
+
15
+ #
16
+ # Description:
17
+ # Locate the element on the page. Element can be a span, div, label, p or pre HTML tag.
18
+ #
19
+ def locate
20
+ case @how
21
+ when :jssh_name
22
+ @element_name = @what
23
+ when :xpath
24
+ @element_name = element_by_xpath(@container, @what)
25
+ else
26
+ @element_name = locate_tagged_element(self.class::TAG, @how, @what)
27
+ end
28
+ @o = self
29
+ end
30
+
31
+ # - how - Attribute to identify the element.
32
+ # - what - Value of that attribute.
33
+ def initialize(container, how, what)
34
+ #@element = Element.new(nil)
35
+ @how = how
36
+ @what = what
37
+ @container = container
38
+ @o = nil
39
+ end
40
+
41
+ # Returns a string of properties of the object.
42
+ def to_s(attributes = nil)
43
+ assert_exists
44
+ hash_properties = {"text"=>"innerHTML"}
45
+ hash_properties.update(attributes) if attributes != nil
46
+ r = super(hash_properties)
47
+ #r = string_creator
48
+ #r += span_div_string_creator
49
+ return r.join("\n")
50
+ end
51
+
52
+ end # NonControlElement
53
+ end # FireWatir
@@ -0,0 +1,108 @@
1
+ module FireWatir
2
+ class Pre < NonControlElement
3
+ TAG = 'PRE'
4
+ end
5
+
6
+ class P < NonControlElement
7
+ TAG = 'P'
8
+ end
9
+
10
+ class Div < NonControlElement
11
+ TAG = 'DIV'
12
+ end
13
+
14
+ class Span < NonControlElement
15
+ TAG = 'SPAN'
16
+ end
17
+
18
+ class Strong < NonControlElement
19
+ TAG = 'STRONG'
20
+ end
21
+
22
+ class Label < NonControlElement
23
+ TAG = 'LABEL'
24
+
25
+ #
26
+ # Description:
27
+ # Used to populate the properties in the to_s method.
28
+ #
29
+ #def label_string_creator
30
+ # n = []
31
+ # n << "for:".ljust(TO_S_SIZE) + self.for
32
+ # n << "inner text:".ljust(TO_S_SIZE) + self.text
33
+ # return n
34
+ #end
35
+ #private :label_string_creator
36
+
37
+ #
38
+ # Description:
39
+ # Creates string of properties of the object.
40
+ #
41
+ def to_s
42
+ assert_exists
43
+ super({"for" => "htmlFor","text" => "innerHTML"})
44
+ # r=r + label_string_creator
45
+ end
46
+ end
47
+
48
+ class Ul < NonControlElement
49
+ TAG = 'UL'
50
+ end
51
+
52
+ class Li < NonControlElement
53
+ TAG = 'LI'
54
+ end
55
+
56
+ class Dl < NonControlElement
57
+ TAG = 'DL'
58
+ end
59
+
60
+ class Dt < NonControlElement
61
+ TAG = 'DT'
62
+ end
63
+
64
+ class Dd < NonControlElement
65
+ TAG = 'DD'
66
+ end
67
+
68
+ class H1 < NonControlElement
69
+ TAG = 'H1'
70
+ end
71
+
72
+ class H2 < NonControlElement
73
+ TAG = 'H2'
74
+ end
75
+
76
+ class H3 < NonControlElement
77
+ TAG = 'H3'
78
+ end
79
+
80
+ class H4 < NonControlElement
81
+ TAG = 'H4'
82
+ end
83
+
84
+ class H5 < NonControlElement
85
+ TAG = 'H5'
86
+ end
87
+
88
+ class H6 < NonControlElement
89
+ TAG = 'H6'
90
+ end
91
+
92
+ class Map < NonControlElement
93
+ TAG = 'MAP'
94
+ end
95
+
96
+ class Area < NonControlElement
97
+ TAG = 'AREA'
98
+ end
99
+
100
+ class Body < NonControlElement
101
+ TAG = 'TBODY'
102
+ end
103
+
104
+ class Em < NonControlElement
105
+ TAG = 'EM'
106
+ end
107
+
108
+ end # FireWatir