watir 1.6.5 → 1.6.6.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGES +461 -326
  2. data/VERSION +1 -0
  3. data/bin/watir-console +6 -6
  4. data/lib/changes.rb +3 -3
  5. data/lib/license.rb +38 -38
  6. data/lib/readme.rb +140 -140
  7. data/lib/watir/WindowHelper.rb +49 -49
  8. data/lib/watir/camel_case.rb +66 -66
  9. data/lib/watir/clickJSDialog.rb +19 -19
  10. data/lib/watir/close_all.rb +37 -37
  11. data/lib/watir/collections.rb +392 -344
  12. data/lib/watir/container.rb +857 -815
  13. data/lib/watir/contrib/enabled_popup.rb +20 -20
  14. data/lib/watir/contrib/ie-new-process.rb +27 -27
  15. data/lib/watir/contrib/page_checker.rb +29 -29
  16. data/lib/watir/cookiemanager.rb +55 -55
  17. data/lib/watir/core.rb +28 -0
  18. data/lib/watir/core_ext.rb +17 -17
  19. data/lib/watir/datahandler.rb +107 -107
  20. data/lib/watir/dialog.rb +46 -46
  21. data/lib/watir/element.rb +351 -343
  22. data/lib/watir/element_collections.rb +97 -97
  23. data/lib/watir/form.rb +170 -170
  24. data/lib/watir/frame.rb +59 -59
  25. data/lib/watir/html_element.rb +22 -0
  26. data/lib/watir/ie-class.rb +1006 -1009
  27. data/lib/watir/ie-process.rb +39 -39
  28. data/lib/watir/ie.rb +70 -133
  29. data/lib/watir/image.rb +130 -130
  30. data/lib/watir/input_elements.rb +614 -572
  31. data/lib/watir/irb-history.rb +30 -30
  32. data/lib/watir/link.rb +64 -64
  33. data/lib/watir/locator.rb +200 -176
  34. data/lib/watir/logger.rb +19 -19
  35. data/lib/watir/modal_dialog.rb +122 -122
  36. data/lib/watir/module.rb +37 -0
  37. data/lib/watir/non_control_elements.rb +145 -145
  38. data/lib/watir/page-container.rb +116 -107
  39. data/lib/watir/popup.rb +29 -29
  40. data/lib/watir/process.rb +19 -19
  41. data/lib/watir/screen_capture.rb +115 -115
  42. data/lib/watir/setFileDialog.rb +16 -16
  43. data/lib/watir/table.rb +395 -362
  44. data/lib/watir/watir_simple.rb +475 -475
  45. data/lib/watir/win32.rb +35 -35
  46. data/lib/watir/win32ole.rb +14 -14
  47. data/lib/watir/winClicker.rb +496 -496
  48. data/rakefile.rb +70 -0
  49. data/unittests/all_tests.rb +10 -10
  50. data/unittests/buttons_xpath_test.rb +69 -69
  51. data/unittests/checkbox_test.rb +179 -179
  52. data/unittests/checkbox_xpath_test.rb +107 -107
  53. data/unittests/click_no_wait_test.rb +21 -0
  54. data/unittests/core_tests.rb +17 -17
  55. data/unittests/css_test.rb +42 -35
  56. data/unittests/defer_test.rb +46 -46
  57. data/unittests/dialog_test.rb +77 -77
  58. data/unittests/div2_xpath_test.rb +21 -21
  59. data/unittests/div_test.rb +188 -188
  60. data/unittests/div_xpath_test.rb +96 -96
  61. data/unittests/element_test.rb +49 -0
  62. data/unittests/errorchecker_test.rb +32 -22
  63. data/unittests/filefield_test.rb +39 -39
  64. data/unittests/filefield_xpath_test.rb +33 -33
  65. data/unittests/form_test.rb +280 -280
  66. data/unittests/form_xpath_test.rb +252 -252
  67. data/unittests/frame_test.rb +155 -155
  68. data/unittests/google_form_test.rb +15 -15
  69. data/unittests/html/JavascriptClick.html +39 -39
  70. data/unittests/html/blankpage.html +11 -11
  71. data/unittests/html/buttons1.html +40 -40
  72. data/unittests/html/checkboxes1.html +89 -89
  73. data/unittests/html/click_no_wait.html +14 -0
  74. data/unittests/html/complex_table.html +36 -36
  75. data/unittests/html/cssTest.html +42 -42
  76. data/unittests/html/depot_store.html +59 -59
  77. data/unittests/html/div.html +93 -93
  78. data/unittests/html/div_xml.html +20 -20
  79. data/unittests/html/fileupload.html +45 -45
  80. data/unittests/html/formTest1.html +38 -38
  81. data/unittests/html/forms2.html +44 -44
  82. data/unittests/html/forms3.html +131 -131
  83. data/unittests/html/forms4.html +27 -27
  84. data/unittests/html/frame_buttons.html +3 -3
  85. data/unittests/html/frame_links.html +3 -3
  86. data/unittests/html/frame_multi.html +4 -4
  87. data/unittests/html/google_india.html +119 -119
  88. data/unittests/html/iframeTest.html +12 -12
  89. data/unittests/html/iframeTest1.html +6 -6
  90. data/unittests/html/iframeTest2.html +5 -5
  91. data/unittests/html/images1.html +66 -66
  92. data/unittests/html/javascriptevents.html +35 -35
  93. data/unittests/html/link_pass.html +10 -10
  94. data/unittests/html/links1.html +38 -38
  95. data/unittests/html/links2.html +10 -10
  96. data/unittests/html/links_multi.html +14 -14
  97. data/unittests/html/list_matters.html +720 -720
  98. data/unittests/html/lists.html +17 -17
  99. data/unittests/html/map_test.html +31 -31
  100. data/unittests/html/modal_dialog.html +10 -10
  101. data/unittests/html/modal_dialog_launcher.html +11 -11
  102. data/unittests/html/nestedFrames.html +6 -6
  103. data/unittests/html/new_browser.html +16 -16
  104. data/unittests/html/pass.html +12 -12
  105. data/unittests/html/popups1.html +59 -59
  106. data/unittests/html/pre.html +27 -27
  107. data/unittests/html/radioButtons1.html +71 -71
  108. data/unittests/html/select_tealeaf.html +54 -54
  109. data/unittests/html/selectboxes1.html +52 -52
  110. data/unittests/html/simple_table.html +26 -26
  111. data/unittests/html/simple_table_buttons.html +104 -104
  112. data/unittests/html/simple_table_columns.html +76 -76
  113. data/unittests/html/table1.html +181 -181
  114. data/unittests/html/tableCell_using_xpath.html +19 -19
  115. data/unittests/html/table_and_tablerow_to_a.html +174 -0
  116. data/unittests/html/textarea.html +30 -30
  117. data/unittests/html/textfields1.html +88 -88
  118. data/unittests/html/textsearch.html +44 -44
  119. data/unittests/html/wallofcheckboxes.html +1003 -1003
  120. data/unittests/html/xpath_nbsp.html +12 -12
  121. data/unittests/ie_exists_test.rb +33 -33
  122. data/unittests/ie_mock.rb +94 -94
  123. data/unittests/ie_test.rb +51 -51
  124. data/unittests/images_test.rb +157 -157
  125. data/unittests/images_xpath_test.rb +91 -91
  126. data/unittests/links_multi_test.rb +48 -48
  127. data/unittests/links_test.rb +175 -175
  128. data/unittests/links_xpath_test.rb +39 -39
  129. data/unittests/lists_test.rb +32 -32
  130. data/unittests/map_test.rb +98 -98
  131. data/unittests/minmax_test.rb +31 -31
  132. data/unittests/navigate_test.rb +39 -39
  133. data/unittests/nbsp_xpath_test.rb +16 -16
  134. data/unittests/non_core_tests.rb +12 -12
  135. data/unittests/other/WindowLogonExample.rb +27 -27
  136. data/unittests/other/WindowLogonExtra.rb +6 -6
  137. data/unittests/other/all_tests_concurrent.rb +57 -57
  138. data/unittests/other/jscriptExtraAlert.rb +6 -6
  139. data/unittests/other/jscriptExtraConfirmCancel.rb +6 -6
  140. data/unittests/other/jscriptExtraConfirmOk.rb +6 -6
  141. data/unittests/other/jscriptPushButton.rb +6 -6
  142. data/unittests/other/jscript_test.rb +63 -63
  143. data/unittests/other/navigate_exception_test.rb +24 -24
  144. data/unittests/other/rexml_unit_test.rb +27 -27
  145. data/unittests/other/screen_capture_test.rb +54 -54
  146. data/unittests/other/testcase_method_order_test.rb +35 -35
  147. data/unittests/other/testcase_verify_test.rb +24 -24
  148. data/unittests/other/wait_until_test.rb +99 -99
  149. data/unittests/pagecontainstext_test.rb +69 -69
  150. data/unittests/parent_child_test.rb +43 -43
  151. data/unittests/perf_test.rb +20 -20
  152. data/unittests/popups_test.rb +43 -43
  153. data/unittests/pre_test.rb +53 -53
  154. data/unittests/radios_test.rb +212 -212
  155. data/unittests/radios_xpath_test.rb +101 -101
  156. data/unittests/security_setting_test.rb +23 -23
  157. data/unittests/selectbox_test.rb +148 -148
  158. data/unittests/selectbox_xpath_test.rb +113 -113
  159. data/unittests/setup.rb +87 -77
  160. data/unittests/speed_settings_test.rb +67 -67
  161. data/unittests/table_and_tablerow_to_a_test.rb +117 -0
  162. data/unittests/table_cell_using_xpath_test.rb +35 -35
  163. data/unittests/table_test.rb +376 -376
  164. data/unittests/table_xpath_test.rb +110 -110
  165. data/unittests/test_tests.rb +9 -9
  166. data/unittests/textarea_test.rb +92 -92
  167. data/unittests/textarea_xpath_test.rb +78 -78
  168. data/unittests/textfield_for_ch_char_test.rb +31 -31
  169. data/unittests/textfields_test.rb +218 -218
  170. data/unittests/textfields_xpath_test.rb +111 -111
  171. data/unittests/window_tests.rb +10 -10
  172. data/unittests/windows/attach_to_existing_window_test.rb +53 -53
  173. data/unittests/windows/attach_to_new_window_test.rb +83 -83
  174. data/unittests/windows/close_window_test.rb +20 -20
  175. data/unittests/windows/frame_links_test.rb +25 -25
  176. data/unittests/windows/ie-each_test.rb +47 -47
  177. data/unittests/windows/iedialog_test.rb +54 -54
  178. data/unittests/windows/js_events_test.rb +42 -55
  179. data/unittests/windows/modal_dialog_test.rb +128 -128
  180. data/unittests/windows/new_test.rb +57 -57
  181. data/unittests/windows/open_close_test.rb +18 -18
  182. data/unittests/windows/send_keys_test.rb +33 -33
  183. data/unittests/xpath_tests.rb +10 -10
  184. metadata +85 -31
  185. data/lib/watir/utils.rb +0 -20
  186. data/lib/watir/version.rb +0 -5
@@ -1,40 +1,40 @@
1
- require 'win32/process'
2
-
3
- module Watir
4
- class IE
5
- class Process
6
- def self.start
7
- program_files = ENV['ProgramFiles'] || "c:\\Program Files"
8
- startup_command = "#{program_files}\\Internet Explorer\\iexplore.exe"
9
- process_info = ::Process.create('app_name' => "#{startup_command} about:blank")
10
- process_id = process_info.process_id
11
- new process_id
12
- end
13
-
14
- def initialize process_id
15
- @process_id = process_id
16
- end
17
- attr_reader :process_id
18
-
19
- def window
20
- Waiter.wait_until do
21
- IE.each do | ie |
22
- window = ie.ie
23
- hwnd = ie.hwnd
24
- process_id = Process.process_id_from_hwnd hwnd
25
- return window if process_id == @process_id
26
- end
27
- end
28
- end
29
-
30
- # Returns the process id for the specifed hWnd.
31
- def self.process_id_from_hwnd hwnd
32
- pid_info = ' ' * 32
33
- Win32API.new('user32', 'GetWindowThreadProcessId', 'ip', 'i').
34
- call(hwnd, pid_info)
35
- process_id = pid_info.unpack("L")[0]
36
- end
37
-
38
- end
39
- end
1
+ require 'win32/process'
2
+
3
+ module Watir
4
+ class IE
5
+ class Process
6
+ def self.start
7
+ program_files = ENV['ProgramFiles'] || "c:\\Program Files"
8
+ startup_command = "#{program_files}\\Internet Explorer\\iexplore.exe"
9
+ process_info = ::Process.create('app_name' => "#{startup_command} about:blank")
10
+ process_id = process_info.process_id
11
+ new process_id
12
+ end
13
+
14
+ def initialize process_id
15
+ @process_id = process_id
16
+ end
17
+ attr_reader :process_id
18
+
19
+ def window
20
+ Waiter.wait_until do
21
+ IE.each do | ie |
22
+ window = ie.ie
23
+ hwnd = ie.hwnd
24
+ process_id = Process.process_id_from_hwnd hwnd
25
+ return window if process_id == @process_id
26
+ end
27
+ end
28
+ end
29
+
30
+ # Returns the process id for the specifed hWnd.
31
+ def self.process_id_from_hwnd hwnd
32
+ pid_info = ' ' * 32
33
+ Win32API.new('user32', 'GetWindowThreadProcessId', 'ip', 'i').
34
+ call(hwnd, pid_info)
35
+ process_id = pid_info.unpack("L")[0]
36
+ end
37
+
38
+ end
39
+ end
40
40
  end
@@ -1,133 +1,70 @@
1
- =begin
2
- license
3
- ---------------------------------------------------------------------------
4
- Copyright (c) 2004 - 2005, Paul Rogers and Bret Pettichord
5
- Copyright (c) 2006 - 2008, Bret Pettichord
6
- All rights reserved.
7
-
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are met:
10
-
11
- 1. Redistributions of source code must retain the above copyright notice,
12
- this list of conditions and the following disclaimer.
13
-
14
- 2. Redistributions in binary form must reproduce the above copyright
15
- notice, this list of conditions and the following disclaimer in the
16
- documentation and/or other materials provided with the distribution.
17
-
18
- 3. Neither the names Paul Rogers, nor Bret Pettichord nor the names of any
19
- other contributors to this software may be used to endorse or promote
20
- products derived from this software without specific prior written
21
- permission.
22
-
23
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
24
- IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
27
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30
- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- --------------------------------------------------------------------------
35
- (based on BSD Open Source License)
36
- =end
37
-
38
- require 'watir/win32ole'
39
-
40
- require 'logger'
41
- require 'watir/winClicker'
42
- require 'watir/exceptions'
43
- require 'watir/utils'
44
- require 'watir/close_all'
45
- require 'watir/ie-process'
46
-
47
- require 'dl/import'
48
- require 'dl/struct'
49
- require 'Win32API'
50
-
51
- require 'watir/matches'
52
-
53
- # these switches need to be deleted from ARGV to enable the Test::Unit
54
- # functionality that grabs
55
- # the remaining ARGV as a filter on what tests to run.
56
- # Note: this means that watir must be require'd BEFORE test/unit.
57
- # (Alternatively, you could require test/unit first and then put the Watir::IE
58
- # arguments after the '--'.)
59
-
60
- # Make Internet Explorer invisible. -b stands for background
61
- $HIDE_IE ||= ARGV.delete('-b')
62
-
63
- # Run fast
64
- $FAST_SPEED = ARGV.delete('-f')
65
-
66
- # Eat the -s command line switch (deprecated)
67
- ARGV.delete('-s')
68
-
69
- require 'watir/core_ext'
70
- require 'watir/logger'
71
- require 'watir/win32'
72
- require 'watir/container'
73
- require 'watir/locator'
74
- require 'watir/page-container'
75
- require 'watir/ie-class'
76
- require 'watir/version'
77
- require 'watir/popup'
78
- require 'watir/element'
79
- require 'watir/frame'
80
- require 'watir/modal_dialog'
81
- require 'watir/element_collections'
82
- require 'watir/form'
83
- require 'watir/non_control_elements'
84
- require 'watir/input_elements'
85
- require 'watir/table'
86
- require 'watir/image'
87
- require 'watir/link'
88
- require 'watir/collections'
89
-
90
- require 'watir'
91
-
92
- module Watir
93
- include Watir::Exception
94
-
95
- # Directory containing the watir.rb file
96
- @@dir = File.expand_path(File.dirname(__FILE__))
97
-
98
- ATTACHER = Waiter.new
99
- # Like regular Ruby "until", except that a TimeOutException is raised
100
- # if the timeout is exceeded. Timeout is IE.attach_timeout.
101
- def self.until_with_timeout # block
102
- ATTACHER.timeout = IE.attach_timeout
103
- ATTACHER.wait_until { yield }
104
- end
105
-
106
- @@autoit = nil
107
-
108
- def self.autoit
109
- unless @@autoit
110
- begin
111
- @@autoit = WIN32OLE.new('AutoItX3.Control')
112
- rescue WIN32OLERuntimeError
113
- _register('AutoItX3.dll')
114
- @@autoit = WIN32OLE.new('AutoItX3.Control')
115
- end
116
- end
117
- @@autoit
118
- end
119
-
120
- def self._register(dll)
121
- system("regsvr32.exe /s " + "#{@@dir}/#{dll}".gsub('/', '\\'))
122
- end
123
- def self._unregister(dll)
124
- system("regsvr32.exe /s /u " + "#{@@dir}/#{dll}".gsub('/', '\\'))
125
- end
126
- end
127
-
128
- # why won't this work when placed in the module (where it properly belongs)
129
- def _code_that_copies_readonly_array(array, name)
130
- "temp = Array.new(#{array.inspect}); #{name}.clear; temp.each {|element| #{name} << element}"
131
- end
132
-
133
- require 'watir/camel_case'
1
+ =begin
2
+ license
3
+ ---------------------------------------------------------------------------
4
+ Copyright (c) 2004 - 2005, Paul Rogers and Bret Pettichord
5
+ Copyright (c) 2006 - 2008, Bret Pettichord
6
+ All rights reserved.
7
+
8
+ Redistribution and use in source and binary forms, with or without
9
+ modification, are permitted provided that the following conditions are met:
10
+
11
+ 1. Redistributions of source code must retain the above copyright notice,
12
+ this list of conditions and the following disclaimer.
13
+
14
+ 2. Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+
18
+ 3. Neither the names Paul Rogers, nor Bret Pettichord nor the names of any
19
+ other contributors to this software may be used to endorse or promote
20
+ products derived from this software without specific prior written
21
+ permission.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
24
+ IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
27
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ --------------------------------------------------------------------------
35
+ (based on BSD Open Source License)
36
+ =end
37
+
38
+ require 'watir/core'
39
+ require 'watir/winClicker'
40
+ require 'watir/close_all'
41
+ require 'watir/ie-process'
42
+
43
+ require 'dl/import'
44
+ require 'dl/struct'
45
+ require 'Win32API'
46
+
47
+ # these switches need to be deleted from ARGV to enable the Test::Unit
48
+ # functionality that grabs
49
+ # the remaining ARGV as a filter on what tests to run.
50
+ # Note: this means that watir must be require'd BEFORE test/unit.
51
+ # (Alternatively, you could require test/unit first and then put the Watir::IE
52
+ # arguments after the '--'.)
53
+
54
+ # Make Internet Explorer invisible. -b stands for background
55
+ $HIDE_IE ||= ARGV.delete('-b')
56
+
57
+ # Run fast
58
+ $FAST_SPEED = ARGV.delete('-f')
59
+
60
+ # Eat the -s command line switch (deprecated)
61
+ ARGV.delete('-s')
62
+
63
+ require 'watir/win32'
64
+ require 'watir/popup'
65
+ require 'watir/frame'
66
+ require 'watir/modal_dialog'
67
+ require 'watir/collections'
68
+ require 'watir'
69
+
70
+ require 'watir/camel_case'
@@ -1,131 +1,131 @@
1
- module Watir
2
-
3
- # This class is the means of accessing an image on a page.
4
- # Normally a user would not need to create this object as it is returned by the Watir::Container#image method
5
- #
6
- # many of the methods available to this object are inherited from the Element class
7
- #
8
- class Image < Element
9
- def initialize(container, how, what)
10
- set_container container
11
- @how = how
12
- @what = what
13
- super nil
14
- end
15
-
16
- def locate
17
- if @how == :xpath
18
- @o = @container.element_by_xpath(@what)
19
- else
20
- @o = @container.locate_tagged_element('IMG', @how, @what)
21
- end
22
- end
23
-
24
- # this method produces the properties for an image as an array
25
- def image_string_creator
26
- n = []
27
- n << "src:".ljust(TO_S_SIZE) + self.src.to_s
28
- n << "file date:".ljust(TO_S_SIZE) + self.fileCreatedDate.to_s
29
- n << "file size:".ljust(TO_S_SIZE) + self.fileSize.to_s
30
- n << "width:".ljust(TO_S_SIZE) + self.width.to_s
31
- n << "height:".ljust(TO_S_SIZE) + self.height.to_s
32
- n << "alt:".ljust(TO_S_SIZE) + self.alt.to_s
33
- return n
34
- end
35
- private :image_string_creator
36
-
37
- # returns a string representation of the object
38
- def to_s
39
- assert_exists
40
- r = string_creator
41
- r += image_string_creator
42
- return r.join("\n")
43
- end
44
-
45
- # this method returns the file created date of the image
46
- def file_created_date
47
- assert_exists
48
- return @o.invoke("fileCreatedDate")
49
- end
50
-
51
- # this method returns the filesize of the image
52
- def file_size
53
- assert_exists
54
- return @o.invoke("fileSize").to_s
55
- end
56
-
57
- # returns the width in pixels of the image, as a string
58
- def width
59
- assert_exists
60
- return @o.invoke("width").to_s
61
- end
62
-
63
- # returns the height in pixels of the image, as a string
64
- def height
65
- assert_exists
66
- return @o.invoke("height").to_s
67
- end
68
-
69
- # This method attempts to find out if the image was actually loaded by the web browser.
70
- # If the image was not loaded, the browser is unable to determine some of the properties.
71
- # We look for these missing properties to see if the image is really there or not.
72
- # If the Disk cache is full (tools menu -> Internet options -> Temporary Internet Files), it may produce incorrect responses.
73
- def loaded?
74
- locate
75
- raise UnknownObjectException, "Unable to locate image using #{@how} and #{@what}" if @o == nil
76
- return false if @o.fileCreatedDate == "" and @o.fileSize.to_i == -1
77
- return true
78
- end
79
-
80
- # this method highlights the image (in fact it adds or removes a border around the image)
81
- # * set_or_clear - symbol - :set to set the border, :clear to remove it
82
- def highlight(set_or_clear)
83
- if set_or_clear == :set
84
- begin
85
- @original_border = @o.border
86
- @o.border = 1
87
- rescue
88
- @original_border = nil
89
- end
90
- else
91
- begin
92
- @o.border = @original_border
93
- @original_border = nil
94
- rescue
95
- # we could be here for a number of reasons...
96
- ensure
97
- @original_border = nil
98
- end
99
- end
100
- end
101
- private :highlight
102
-
103
- # This method saves the image to the file path that is given. The
104
- # path must be in windows format (c:\\dirname\\somename.gif). This method
105
- # will not overwrite a previously existing image. If an image already
106
- # exists at the given path then a dialog will be displayed prompting
107
- # for overwrite.
108
- # Raises a WatirException if AutoIt is not correctly installed
109
- # path - directory path and file name of where image should be saved
110
- def save(path)
111
- require 'watir/windowhelper'
112
- WindowHelper.check_autoit_installed
113
- @container.goto(src)
114
- begin
115
- thrd = fill_save_image_dialog(path)
116
- @container.document.execCommand("SaveAs")
117
- thrd.join(5)
118
- ensure
119
- @container.back
120
- end
121
- end
122
-
123
- def fill_save_image_dialog(path)
124
- Thread.new do
125
- system("ruby -e \"require 'win32ole'; @autoit=WIN32OLE.new('AutoItX3.Control'); waitresult=@autoit.WinWait 'Save Picture', '', 15; if waitresult == 1\" -e \"@autoit.ControlSetText 'Save Picture', '', '1148', '#{path}'; @autoit.ControlSend 'Save Picture', '', '1', '{ENTER}';\" -e \"end\"")
126
- end
127
- end
128
- private :fill_save_image_dialog
129
- end
130
-
1
+ module Watir
2
+
3
+ # This class is the means of accessing an image on a page.
4
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#image method
5
+ #
6
+ # many of the methods available to this object are inherited from the Element class
7
+ #
8
+ class Image < Element
9
+ def initialize(container, how, what)
10
+ set_container container
11
+ @how = how
12
+ @what = what
13
+ super nil
14
+ end
15
+
16
+ def locate
17
+ if @how == :xpath
18
+ @o = @container.element_by_xpath(@what)
19
+ else
20
+ @o = @container.locate_tagged_element('IMG', @how, @what)
21
+ end
22
+ end
23
+
24
+ # this method produces the properties for an image as an array
25
+ def image_string_creator
26
+ n = []
27
+ n << "src:".ljust(TO_S_SIZE) + self.src.to_s
28
+ n << "file date:".ljust(TO_S_SIZE) + self.fileCreatedDate.to_s
29
+ n << "file size:".ljust(TO_S_SIZE) + self.fileSize.to_s
30
+ n << "width:".ljust(TO_S_SIZE) + self.width.to_s
31
+ n << "height:".ljust(TO_S_SIZE) + self.height.to_s
32
+ n << "alt:".ljust(TO_S_SIZE) + self.alt.to_s
33
+ return n
34
+ end
35
+ private :image_string_creator
36
+
37
+ # returns a string representation of the object
38
+ def to_s
39
+ assert_exists
40
+ r = string_creator
41
+ r += image_string_creator
42
+ return r.join("\n")
43
+ end
44
+
45
+ # this method returns the file created date of the image
46
+ def file_created_date
47
+ assert_exists
48
+ return @o.invoke("fileCreatedDate")
49
+ end
50
+
51
+ # this method returns the filesize of the image
52
+ def file_size
53
+ assert_exists
54
+ return @o.invoke("fileSize").to_s
55
+ end
56
+
57
+ # returns the width in pixels of the image, as a string
58
+ def width
59
+ assert_exists
60
+ return @o.invoke("width").to_s
61
+ end
62
+
63
+ # returns the height in pixels of the image, as a string
64
+ def height
65
+ assert_exists
66
+ return @o.invoke("height").to_s
67
+ end
68
+
69
+ # This method attempts to find out if the image was actually loaded by the web browser.
70
+ # If the image was not loaded, the browser is unable to determine some of the properties.
71
+ # We look for these missing properties to see if the image is really there or not.
72
+ # If the Disk cache is full (tools menu -> Internet options -> Temporary Internet Files), it may produce incorrect responses.
73
+ def loaded?
74
+ locate
75
+ raise UnknownObjectException, "Unable to locate image using #{@how} and #{@what}" if @o == nil
76
+ return false if @o.fileCreatedDate == "" and @o.fileSize.to_i == -1
77
+ return true
78
+ end
79
+
80
+ # this method highlights the image (in fact it adds or removes a border around the image)
81
+ # * set_or_clear - symbol - :set to set the border, :clear to remove it
82
+ def highlight(set_or_clear)
83
+ if set_or_clear == :set
84
+ begin
85
+ @original_border = @o.border
86
+ @o.border = 1
87
+ rescue
88
+ @original_border = nil
89
+ end
90
+ else
91
+ begin
92
+ @o.border = @original_border
93
+ @original_border = nil
94
+ rescue
95
+ # we could be here for a number of reasons...
96
+ ensure
97
+ @original_border = nil
98
+ end
99
+ end
100
+ end
101
+ private :highlight
102
+
103
+ # This method saves the image to the file path that is given. The
104
+ # path must be in windows format (c:\\dirname\\somename.gif). This method
105
+ # will not overwrite a previously existing image. If an image already
106
+ # exists at the given path then a dialog will be displayed prompting
107
+ # for overwrite.
108
+ # Raises a WatirException if AutoIt is not correctly installed
109
+ # path - directory path and file name of where image should be saved
110
+ def save(path)
111
+ require 'watir/windowhelper'
112
+ WindowHelper.check_autoit_installed
113
+ @container.goto(src)
114
+ begin
115
+ thrd = fill_save_image_dialog(path)
116
+ @container.document.execCommand("SaveAs")
117
+ thrd.join(5)
118
+ ensure
119
+ @container.back
120
+ end
121
+ end
122
+
123
+ def fill_save_image_dialog(path)
124
+ Thread.new do
125
+ system("ruby -e \"require 'win32ole'; @autoit=WIN32OLE.new('AutoItX3.Control'); waitresult=@autoit.WinWait 'Save Picture', '', 15; if waitresult == 1\" -e \"@autoit.ControlSetText 'Save Picture', '', '1148', '#{path}'; @autoit.ControlSend 'Save Picture', '', '1', '{ENTER}';\" -e \"end\"")
126
+ end
127
+ end
128
+ private :fill_save_image_dialog
129
+ end
130
+
131
131
  end