watir 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 (178) hide show
  1. data/CHANGES +326 -188
  2. data/bin/watir-console +7 -8
  3. data/lib/changes.rb +3 -3
  4. data/lib/license.rb +38 -38
  5. data/lib/readme.rb +140 -140
  6. data/lib/watir/WindowHelper.rb +49 -49
  7. data/lib/watir/camel_case.rb +66 -45
  8. data/lib/watir/clickJSDialog.rb +19 -19
  9. data/lib/watir/close_all.rb +37 -37
  10. data/lib/watir/collections.rb +344 -312
  11. data/lib/watir/container.rb +815 -753
  12. data/lib/watir/contrib/enabled_popup.rb +20 -20
  13. data/lib/watir/contrib/ie-new-process.rb +27 -27
  14. data/lib/watir/contrib/page_checker.rb +29 -29
  15. data/lib/watir/cookiemanager.rb +55 -55
  16. data/lib/watir/core_ext.rb +18 -0
  17. data/lib/watir/datahandler.rb +107 -107
  18. data/lib/watir/dialog.rb +46 -46
  19. data/lib/watir/element.rb +343 -312
  20. data/lib/watir/element_collections.rb +97 -81
  21. data/lib/watir/form.rb +170 -170
  22. data/lib/watir/frame.rb +59 -59
  23. data/lib/watir/ie-class.rb +1009 -1003
  24. data/lib/watir/ie-process.rb +39 -39
  25. data/lib/watir/ie.rb +133 -132
  26. data/lib/watir/image.rb +130 -130
  27. data/lib/watir/input_elements.rb +572 -539
  28. data/lib/watir/irb-history.rb +30 -30
  29. data/lib/watir/link.rb +64 -64
  30. data/lib/watir/locator.rb +176 -161
  31. data/lib/watir/logger.rb +19 -19
  32. data/lib/watir/modal_dialog.rb +122 -122
  33. data/lib/watir/non_control_elements.rb +145 -127
  34. data/lib/watir/page-container.rb +107 -105
  35. data/lib/watir/popup.rb +29 -29
  36. data/lib/watir/process.rb +19 -19
  37. data/lib/watir/screen_capture.rb +115 -115
  38. data/lib/watir/setFileDialog.rb +16 -16
  39. data/lib/watir/table.rb +362 -362
  40. data/lib/watir/utils.rb +19 -19
  41. data/lib/watir/version.rb +5 -5
  42. data/lib/watir/watir_simple.rb +475 -475
  43. data/lib/watir/win32.rb +35 -28
  44. data/lib/watir/win32ole.rb +14 -6
  45. data/lib/watir/winClicker.rb +496 -479
  46. data/unittests/all_tests.rb +10 -10
  47. data/unittests/buttons_xpath_test.rb +69 -69
  48. data/unittests/checkbox_test.rb +179 -176
  49. data/unittests/checkbox_xpath_test.rb +107 -107
  50. data/unittests/core_tests.rb +17 -16
  51. data/unittests/css_test.rb +35 -35
  52. data/unittests/defer_test.rb +46 -46
  53. data/unittests/dialog_test.rb +77 -77
  54. data/unittests/div2_xpath_test.rb +21 -21
  55. data/unittests/div_test.rb +188 -183
  56. data/unittests/div_xpath_test.rb +96 -96
  57. data/unittests/errorchecker_test.rb +22 -22
  58. data/unittests/filefield_test.rb +39 -40
  59. data/unittests/filefield_xpath_test.rb +33 -33
  60. data/unittests/form_test.rb +280 -293
  61. data/unittests/form_xpath_test.rb +252 -253
  62. data/unittests/frame_test.rb +155 -157
  63. data/unittests/google_form_test.rb +15 -15
  64. data/unittests/html/JavascriptClick.html +39 -39
  65. data/unittests/html/blankpage.html +11 -11
  66. data/unittests/html/buttons1.html +40 -40
  67. data/unittests/html/checkboxes1.html +89 -89
  68. data/unittests/html/complex_table.html +36 -36
  69. data/unittests/html/cssTest.html +42 -42
  70. data/unittests/html/depot_store.html +51 -51
  71. data/unittests/html/div.html +93 -93
  72. data/unittests/html/div_xml.html +20 -20
  73. data/unittests/html/fileupload.html +45 -45
  74. data/unittests/html/formTest1.html +38 -38
  75. data/unittests/html/forms2.html +44 -44
  76. data/unittests/html/forms3.html +131 -131
  77. data/unittests/html/forms4.html +27 -27
  78. data/unittests/html/frame_buttons.html +3 -3
  79. data/unittests/html/frame_links.html +3 -3
  80. data/unittests/html/frame_multi.html +4 -4
  81. data/unittests/html/google_india.html +107 -107
  82. data/unittests/html/iframeTest.html +12 -12
  83. data/unittests/html/iframeTest1.html +6 -6
  84. data/unittests/html/iframeTest2.html +5 -5
  85. data/unittests/html/images1.html +66 -66
  86. data/unittests/html/javascriptevents.html +35 -35
  87. data/unittests/html/link_pass.html +10 -10
  88. data/unittests/html/links1.html +38 -38
  89. data/unittests/html/links2.html +10 -10
  90. data/unittests/html/links_multi.html +14 -14
  91. data/unittests/html/list_matters.html +720 -720
  92. data/unittests/html/lists.html +17 -17
  93. data/unittests/html/map_test.html +31 -31
  94. data/unittests/html/modal_dialog.html +10 -10
  95. data/unittests/html/modal_dialog_launcher.html +11 -11
  96. data/unittests/html/nestedFrames.html +6 -6
  97. data/unittests/html/new_browser.html +16 -16
  98. data/unittests/html/pass.html +12 -12
  99. data/unittests/html/popups1.html +59 -59
  100. data/unittests/html/pre.html +27 -27
  101. data/unittests/html/radioButtons1.html +71 -71
  102. data/unittests/html/select_tealeaf.html +54 -54
  103. data/unittests/html/selectboxes1.html +52 -55
  104. data/unittests/html/simple_table.html +26 -26
  105. data/unittests/html/simple_table_buttons.html +104 -104
  106. data/unittests/html/simple_table_columns.html +76 -76
  107. data/unittests/html/table1.html +181 -181
  108. data/unittests/html/tableCell_using_xpath.html +19 -19
  109. data/unittests/html/textarea.html +30 -30
  110. data/unittests/html/textfields1.html +88 -88
  111. data/unittests/html/textsearch.html +44 -44
  112. data/unittests/html/wallofcheckboxes.html +1003 -1003
  113. data/unittests/html/xpath_nbsp.html +12 -12
  114. data/unittests/ie_exists_test.rb +33 -33
  115. data/unittests/ie_mock.rb +94 -94
  116. data/unittests/ie_test.rb +51 -50
  117. data/unittests/images_test.rb +157 -157
  118. data/unittests/images_xpath_test.rb +91 -91
  119. data/unittests/links_multi_test.rb +48 -48
  120. data/unittests/links_test.rb +175 -177
  121. data/unittests/links_xpath_test.rb +39 -39
  122. data/unittests/map_test.rb +98 -98
  123. data/unittests/minmax_test.rb +31 -31
  124. data/unittests/navigate_test.rb +39 -39
  125. data/unittests/nbsp_xpath_test.rb +16 -16
  126. data/unittests/non_core_tests.rb +12 -12
  127. data/unittests/other/WindowLogonExample.rb +27 -27
  128. data/unittests/other/WindowLogonExtra.rb +6 -6
  129. data/unittests/other/all_tests_concurrent.rb +57 -57
  130. data/unittests/{windows → other}/jscriptExtraAlert.rb +6 -6
  131. data/unittests/{windows → other}/jscriptExtraConfirmCancel.rb +6 -6
  132. data/unittests/{windows → other}/jscriptExtraConfirmOk.rb +6 -6
  133. data/unittests/{windows → other}/jscriptPushButton.rb +6 -6
  134. data/unittests/{windows → other}/jscript_test.rb +63 -63
  135. data/unittests/other/navigate_exception_test.rb +24 -24
  136. data/unittests/other/rexml_unit_test.rb +27 -24
  137. data/unittests/other/screen_capture_test.rb +54 -54
  138. data/unittests/other/testcase_method_order_test.rb +35 -35
  139. data/unittests/other/testcase_verify_test.rb +24 -24
  140. data/unittests/other/wait_until_test.rb +99 -99
  141. data/unittests/pagecontainstext_test.rb +69 -69
  142. data/unittests/parent_child_test.rb +43 -43
  143. data/unittests/perf_test.rb +20 -20
  144. data/unittests/popups_test.rb +43 -43
  145. data/unittests/pre_test.rb +53 -53
  146. data/unittests/radios_test.rb +212 -212
  147. data/unittests/radios_xpath_test.rb +101 -101
  148. data/unittests/security_setting_test.rb +23 -23
  149. data/unittests/selectbox_test.rb +148 -139
  150. data/unittests/selectbox_xpath_test.rb +113 -113
  151. data/unittests/setup.rb +77 -75
  152. data/unittests/speed_settings_test.rb +67 -65
  153. data/unittests/table_cell_using_xpath_test.rb +35 -35
  154. data/unittests/table_test.rb +376 -362
  155. data/unittests/table_xpath_test.rb +110 -110
  156. data/unittests/test_tests.rb +9 -9
  157. data/unittests/textarea_test.rb +92 -92
  158. data/unittests/textarea_xpath_test.rb +78 -78
  159. data/unittests/textfield_for_ch_char_test.rb +31 -29
  160. data/unittests/textfields_test.rb +218 -218
  161. data/unittests/textfields_xpath_test.rb +111 -111
  162. data/unittests/window_tests.rb +10 -7
  163. data/unittests/windows/attach_to_existing_window_test.rb +53 -52
  164. data/unittests/windows/attach_to_new_window_test.rb +83 -82
  165. data/unittests/windows/close_window_test.rb +20 -20
  166. data/unittests/windows/frame_links_test.rb +25 -25
  167. data/unittests/windows/ie-each_test.rb +47 -47
  168. data/unittests/windows/iedialog_test.rb +54 -54
  169. data/unittests/windows/js_events_test.rb +55 -55
  170. data/unittests/windows/modal_dialog_test.rb +128 -126
  171. data/unittests/windows/new_test.rb +57 -55
  172. data/unittests/windows/open_close_test.rb +18 -18
  173. data/unittests/windows/send_keys_test.rb +33 -32
  174. data/unittests/xpath_tests.rb +10 -10
  175. metadata +20 -20
  176. data/lib/watir/contrib/visible.rb +0 -47
  177. data/unittests/iostring.rb +0 -30
  178. data/unittests/iostring_test.rb +0 -48
@@ -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,132 +1,133 @@
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/logger'
70
- require 'watir/win32'
71
- require 'watir/container'
72
- require 'watir/locator'
73
- require 'watir/page-container'
74
- require 'watir/ie-class'
75
- require 'watir/version'
76
- require 'watir/popup'
77
- require 'watir/element'
78
- require 'watir/frame'
79
- require 'watir/modal_dialog'
80
- require 'watir/element_collections'
81
- require 'watir/form'
82
- require 'watir/non_control_elements'
83
- require 'watir/input_elements'
84
- require 'watir/table'
85
- require 'watir/image'
86
- require 'watir/link'
87
- require 'watir/collections'
88
-
89
- require 'watir'
90
-
91
- module Watir
92
- include Watir::Exception
93
-
94
- # Directory containing the watir.rb file
95
- @@dir = File.expand_path(File.dirname(__FILE__))
96
-
97
- ATTACHER = Waiter.new
98
- # Like regular Ruby "until", except that a TimeOutException is raised
99
- # if the timeout is exceeded. Timeout is IE.attach_timeout.
100
- def self.until_with_timeout # block
101
- ATTACHER.timeout = IE.attach_timeout
102
- ATTACHER.wait_until { yield }
103
- end
104
-
105
- @@autoit = nil
106
-
107
- def self.autoit
108
- unless @@autoit
109
- begin
110
- @@autoit = WIN32OLE.new('AutoItX3.Control')
111
- rescue WIN32OLERuntimeError
112
- _register('AutoItX3.dll')
113
- @@autoit = WIN32OLE.new('AutoItX3.Control')
114
- end
115
- end
116
- @@autoit
117
- end
118
-
119
- def self._register(dll)
120
- system("regsvr32.exe /s " + "#{@@dir}/watir/#{dll}".gsub('/', '\\'))
121
- end
122
- def self._unregister(dll)
123
- system("regsvr32.exe /s /u " + "#{@@dir}/watir/#{dll}".gsub('/', '\\'))
124
- end
125
- end
126
-
127
- # why won't this work when placed in the module (where it properly belongs)
128
- def _code_that_copies_readonly_array(array, name)
129
- "temp = Array.new(#{array.inspect}); #{name}.clear; temp.each {|element| #{name} << element}"
130
- end
131
-
132
- 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/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,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 fileCreatedDate
47
- assert_exists
48
- return @o.invoke("fileCreatedDate")
49
- end
50
-
51
- # this method returns the filesize of the image
52
- def fileSize
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 hasLoaded?
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