watir 1.6.2 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +326 -188
- data/bin/watir-console +7 -8
- data/lib/changes.rb +3 -3
- data/lib/license.rb +38 -38
- data/lib/readme.rb +140 -140
- data/lib/watir/WindowHelper.rb +49 -49
- data/lib/watir/camel_case.rb +66 -45
- data/lib/watir/clickJSDialog.rb +19 -19
- data/lib/watir/close_all.rb +37 -37
- data/lib/watir/collections.rb +344 -312
- data/lib/watir/container.rb +815 -753
- data/lib/watir/contrib/enabled_popup.rb +20 -20
- data/lib/watir/contrib/ie-new-process.rb +27 -27
- data/lib/watir/contrib/page_checker.rb +29 -29
- data/lib/watir/cookiemanager.rb +55 -55
- data/lib/watir/core_ext.rb +18 -0
- data/lib/watir/datahandler.rb +107 -107
- data/lib/watir/dialog.rb +46 -46
- data/lib/watir/element.rb +343 -312
- data/lib/watir/element_collections.rb +97 -81
- data/lib/watir/form.rb +170 -170
- data/lib/watir/frame.rb +59 -59
- data/lib/watir/ie-class.rb +1009 -1003
- data/lib/watir/ie-process.rb +39 -39
- data/lib/watir/ie.rb +133 -132
- data/lib/watir/image.rb +130 -130
- data/lib/watir/input_elements.rb +572 -539
- data/lib/watir/irb-history.rb +30 -30
- data/lib/watir/link.rb +64 -64
- data/lib/watir/locator.rb +176 -161
- data/lib/watir/logger.rb +19 -19
- data/lib/watir/modal_dialog.rb +122 -122
- data/lib/watir/non_control_elements.rb +145 -127
- data/lib/watir/page-container.rb +107 -105
- data/lib/watir/popup.rb +29 -29
- data/lib/watir/process.rb +19 -19
- data/lib/watir/screen_capture.rb +115 -115
- data/lib/watir/setFileDialog.rb +16 -16
- data/lib/watir/table.rb +362 -362
- data/lib/watir/utils.rb +19 -19
- data/lib/watir/version.rb +5 -5
- data/lib/watir/watir_simple.rb +475 -475
- data/lib/watir/win32.rb +35 -28
- data/lib/watir/win32ole.rb +14 -6
- data/lib/watir/winClicker.rb +496 -479
- data/unittests/all_tests.rb +10 -10
- data/unittests/buttons_xpath_test.rb +69 -69
- data/unittests/checkbox_test.rb +179 -176
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/core_tests.rb +17 -16
- data/unittests/css_test.rb +35 -35
- data/unittests/defer_test.rb +46 -46
- data/unittests/dialog_test.rb +77 -77
- data/unittests/div2_xpath_test.rb +21 -21
- data/unittests/div_test.rb +188 -183
- data/unittests/div_xpath_test.rb +96 -96
- data/unittests/errorchecker_test.rb +22 -22
- data/unittests/filefield_test.rb +39 -40
- data/unittests/filefield_xpath_test.rb +33 -33
- data/unittests/form_test.rb +280 -293
- data/unittests/form_xpath_test.rb +252 -253
- data/unittests/frame_test.rb +155 -157
- data/unittests/google_form_test.rb +15 -15
- data/unittests/html/JavascriptClick.html +39 -39
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +40 -40
- data/unittests/html/checkboxes1.html +89 -89
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/depot_store.html +51 -51
- data/unittests/html/div.html +93 -93
- 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 +44 -44
- data/unittests/html/forms3.html +131 -131
- 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/google_india.html +107 -107
- data/unittests/html/iframeTest.html +12 -12
- data/unittests/html/iframeTest1.html +6 -6
- 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 +38 -38
- data/unittests/html/links2.html +10 -10
- data/unittests/html/links_multi.html +14 -14
- data/unittests/html/list_matters.html +720 -720
- data/unittests/html/lists.html +17 -17
- data/unittests/html/map_test.html +31 -31
- data/unittests/html/modal_dialog.html +10 -10
- data/unittests/html/modal_dialog_launcher.html +11 -11
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +16 -16
- data/unittests/html/pass.html +12 -12
- data/unittests/html/popups1.html +59 -59
- data/unittests/html/pre.html +27 -27
- data/unittests/html/radioButtons1.html +71 -71
- data/unittests/html/select_tealeaf.html +54 -54
- data/unittests/html/selectboxes1.html +52 -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 +76 -76
- data/unittests/html/table1.html +181 -181
- data/unittests/html/tableCell_using_xpath.html +19 -19
- data/unittests/html/textarea.html +30 -30
- data/unittests/html/textfields1.html +88 -88
- data/unittests/html/textsearch.html +44 -44
- data/unittests/html/wallofcheckboxes.html +1003 -1003
- data/unittests/html/xpath_nbsp.html +12 -12
- data/unittests/ie_exists_test.rb +33 -33
- data/unittests/ie_mock.rb +94 -94
- data/unittests/ie_test.rb +51 -50
- data/unittests/images_test.rb +157 -157
- data/unittests/images_xpath_test.rb +91 -91
- data/unittests/links_multi_test.rb +48 -48
- data/unittests/links_test.rb +175 -177
- data/unittests/links_xpath_test.rb +39 -39
- data/unittests/map_test.rb +98 -98
- data/unittests/minmax_test.rb +31 -31
- data/unittests/navigate_test.rb +39 -39
- data/unittests/nbsp_xpath_test.rb +16 -16
- data/unittests/non_core_tests.rb +12 -12
- data/unittests/other/WindowLogonExample.rb +27 -27
- data/unittests/other/WindowLogonExtra.rb +6 -6
- data/unittests/other/all_tests_concurrent.rb +57 -57
- data/unittests/{windows → other}/jscriptExtraAlert.rb +6 -6
- data/unittests/{windows → other}/jscriptExtraConfirmCancel.rb +6 -6
- data/unittests/{windows → other}/jscriptExtraConfirmOk.rb +6 -6
- data/unittests/{windows → other}/jscriptPushButton.rb +6 -6
- data/unittests/{windows → other}/jscript_test.rb +63 -63
- data/unittests/other/navigate_exception_test.rb +24 -24
- data/unittests/other/rexml_unit_test.rb +27 -24
- data/unittests/other/screen_capture_test.rb +54 -54
- data/unittests/other/testcase_method_order_test.rb +35 -35
- data/unittests/other/testcase_verify_test.rb +24 -24
- data/unittests/other/wait_until_test.rb +99 -99
- data/unittests/pagecontainstext_test.rb +69 -69
- data/unittests/parent_child_test.rb +43 -43
- data/unittests/perf_test.rb +20 -20
- data/unittests/popups_test.rb +43 -43
- data/unittests/pre_test.rb +53 -53
- data/unittests/radios_test.rb +212 -212
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/security_setting_test.rb +23 -23
- data/unittests/selectbox_test.rb +148 -139
- data/unittests/selectbox_xpath_test.rb +113 -113
- data/unittests/setup.rb +77 -75
- data/unittests/speed_settings_test.rb +67 -65
- data/unittests/table_cell_using_xpath_test.rb +35 -35
- data/unittests/table_test.rb +376 -362
- data/unittests/table_xpath_test.rb +110 -110
- data/unittests/test_tests.rb +9 -9
- data/unittests/textarea_test.rb +92 -92
- data/unittests/textarea_xpath_test.rb +78 -78
- data/unittests/textfield_for_ch_char_test.rb +31 -29
- data/unittests/textfields_test.rb +218 -218
- data/unittests/textfields_xpath_test.rb +111 -111
- data/unittests/window_tests.rb +10 -7
- data/unittests/windows/attach_to_existing_window_test.rb +53 -52
- data/unittests/windows/attach_to_new_window_test.rb +83 -82
- data/unittests/windows/close_window_test.rb +20 -20
- data/unittests/windows/frame_links_test.rb +25 -25
- data/unittests/windows/ie-each_test.rb +47 -47
- data/unittests/windows/iedialog_test.rb +54 -54
- data/unittests/windows/js_events_test.rb +55 -55
- data/unittests/windows/modal_dialog_test.rb +128 -126
- data/unittests/windows/new_test.rb +57 -55
- data/unittests/windows/open_close_test.rb +18 -18
- data/unittests/windows/send_keys_test.rb +33 -32
- data/unittests/xpath_tests.rb +10 -10
- metadata +20 -20
- data/lib/watir/contrib/visible.rb +0 -47
- data/unittests/iostring.rb +0 -30
- data/unittests/iostring_test.rb +0 -48
data/lib/watir/ie-process.rb
CHANGED
@@ -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
|
data/lib/watir/ie.rb
CHANGED
@@ -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/
|
70
|
-
require 'watir/
|
71
|
-
require 'watir/
|
72
|
-
require 'watir/
|
73
|
-
require 'watir/
|
74
|
-
require 'watir/
|
75
|
-
require 'watir/
|
76
|
-
require 'watir/
|
77
|
-
require 'watir/
|
78
|
-
require 'watir/
|
79
|
-
require 'watir/
|
80
|
-
require 'watir/
|
81
|
-
require 'watir/
|
82
|
-
require 'watir/
|
83
|
-
require 'watir/
|
84
|
-
require 'watir/
|
85
|
-
require 'watir/
|
86
|
-
require 'watir/
|
87
|
-
require 'watir/
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
#
|
100
|
-
|
101
|
-
|
102
|
-
ATTACHER.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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'
|
data/lib/watir/image.rb
CHANGED
@@ -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
|
47
|
-
assert_exists
|
48
|
-
return @o.invoke("fileCreatedDate")
|
49
|
-
end
|
50
|
-
|
51
|
-
# this method returns the filesize of the image
|
52
|
-
def
|
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
|
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
|