wet-winobj 0.1-mswin32

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.
@@ -0,0 +1,144 @@
1
+ =begin license
2
+ Copyright (c) 2005, Qantom Software
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11
+
12
+ (based on BSD Open Source License)
13
+ =end
14
+
15
+
16
+ require 'wet/winobjects/Window.rb'
17
+ require 'wet/winobjects/WinDialog.rb'
18
+
19
+ module Wet
20
+ module Winobjects
21
+
22
+ =begin rdoc
23
+ The AppWindow is a top level application window like a browser
24
+ window.
25
+ =end
26
+ class AppWindow < Window
27
+
28
+ =begin rdoc
29
+ Constructor to create a new instance of the app window
30
+ You usually dont have to do it directly. However using it
31
+ directly can come in handy. For example in WET / Watir you
32
+ could create a new AppWindow object by passing the browser's
33
+ hwnd.
34
+ =end
35
+ def initialize(wnd_hwnd)
36
+ super
37
+ if @hwnd != -1
38
+ @title = window_caption(@hwnd)
39
+ @parent = parent_window(@hwnd)
40
+ @class_name = class_name(@hwnd)
41
+ end
42
+ end
43
+
44
+ =begin rdoc
45
+ Helper utilitiy to find an AppWindow using the passed properties.
46
+
47
+ Most of the times you dont have to call this method directly. From
48
+ the main wet-winobjects module, if you say app_window(name => value) , then the required AppWindow instance is generated.
49
+ =end
50
+ def AppWindow.find(props)
51
+ CompileUtils.assert_argument_types(Hash, props.class)
52
+ arg_length = props.length
53
+ found_wnd = -1
54
+ new_wnd = nil
55
+ if props.length == 1 && props['title'] != nil
56
+ title = props['title']
57
+ found_wnd = find_window(title)
58
+ else
59
+ raise UnsupportedOperationException.new("Can only search windows using title")
60
+ end
61
+ new_wnd = AppWindow.new(found_wnd)
62
+ return new_wnd
63
+ end
64
+
65
+ =begin rdoc
66
+ Acivate this window and bring it to top
67
+ =end
68
+ def activate()
69
+ assert_object_exists
70
+ old_active = set_active_window(@hwnd)
71
+ end
72
+
73
+ =begin rdoc
74
+ Set the current windows state to 'maximized'
75
+ =end
76
+ def maximize()
77
+ assert_object_exists
78
+ mx = do_maximize(@hwnd)
79
+ end
80
+
81
+ =begin rdoc
82
+ Set the current windows state to 'minimized'
83
+ =end
84
+ def minimize()
85
+ assert_object_exists
86
+ mn = do_minimize(@hwnd)
87
+ end
88
+
89
+ def title()
90
+ assert_object_exists
91
+ return @title
92
+ end
93
+
94
+ =begin rdoc
95
+ Close the current application window
96
+ =end
97
+ def close()
98
+ assert_object_exists
99
+ return do_destroy_window(@hwnd)
100
+ end
101
+
102
+
103
+
104
+ =begin rdoc
105
+ Return a text that is an aggregate of all 'displayed' text elements.
106
+ =end
107
+ def content_text()
108
+ ret_text=""
109
+ child_objects.each do |c|
110
+ ret_text=ret_text+c.display_text()
111
+ end
112
+ return ret_text
113
+ end
114
+
115
+ =begin rdoc
116
+ Get a 'Dialog' that is owned by this AppWindow.
117
+
118
+ The props parameter is a hashtable of expected properties' name / value.
119
+
120
+ In the current version the following properties can be used:
121
+ 1) 'text' - The title of the WinDialog that is associated with this
122
+ control.
123
+ eg:-
124
+ If you say myWindow.win_dialog("text" => "Expected"), then the method
125
+ will return the Dialog whose title is 'Expected'. Returns an
126
+ empty WinEdit otherwise
127
+ =end
128
+ def dialog(props = nil)
129
+ assert_object_exists
130
+ return WinDialog::find(@hwnd, props)
131
+ end
132
+
133
+
134
+
135
+ def to_s()
136
+ str = "AppWindow(title:="
137
+ str = str + text()
138
+ str = str + ")"
139
+ return str
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,101 @@
1
+ =begin license
2
+ Copyright (c) 2005, Qantom Software
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11
+
12
+ (based on BSD Open Source License)
13
+ =end
14
+
15
+ module Wet
16
+ module Winobjects
17
+ =begin
18
+ Class to represent a win32 button
19
+ =end
20
+ class WinButton < Window
21
+
22
+ @@known_class_names = ["Button"]
23
+
24
+ =begin rdoc
25
+ Constructor. Typically not invoked directly
26
+ =end
27
+ def initialize(hwnd)
28
+ super
29
+ if @hwnd != -1
30
+ find_button_styles()
31
+ end
32
+ end
33
+
34
+ =begin rdoc
35
+ Is the Window object a possible candidate for this class?
36
+ Return true if yes. False otherwise.
37
+ =end
38
+ #Note : - in the interest of reusable design, I had first put it this as a method
39
+ #in Window. But then I realized that each class may have to make complex
40
+ #calculations - eg. A label could be a static or an edit field set to read-only
41
+ def WinButton.candidate_match?(win_element)
42
+ is_match = false
43
+ @@known_class_names.each do |e|
44
+ if TextUtils.compare_text(win_element.win_class,e)
45
+ is_match = true
46
+ break
47
+ end
48
+ end
49
+ return is_match
50
+ end
51
+
52
+ =begin rdoc
53
+ Is this button a radio button ?
54
+ Return true if it is, false otherwise
55
+ =end
56
+ def is_radio()
57
+ assert_object_exists
58
+ return @is_radio
59
+ end
60
+
61
+ =begin rdoc
62
+ Is this button a checkbox?
63
+ Return true if it is, false otherwise.
64
+ =end
65
+ def is_checkbox()
66
+ assert_object_exists
67
+ return @is_checkbox
68
+ end
69
+
70
+ =begin rdoc
71
+ Perform a click operation on this button
72
+ =end
73
+ def click()
74
+ assert_object_exists
75
+ do_button_click(@hwnd)
76
+ end
77
+
78
+ def to_s()
79
+ str = "WinButton(text:="
80
+ str = str + text()
81
+ str = str + ")"
82
+ return str
83
+ end
84
+
85
+ protected
86
+ def button_state()
87
+ assert_object_exists
88
+ do_get_button_state(@hwnd)
89
+ end
90
+
91
+ protected
92
+ def find_button_styles()
93
+ @control_style = get_win_style()
94
+ @is_radio = @control_style & BS_AUTORADIOBUTTON == BS_AUTORADIOBUTTON
95
+ @is_checkbox = @control_style & BS_AUTOCHECKBOX ==BS_AUTOCHECKBOX
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ end
@@ -0,0 +1,84 @@
1
+ =begin license
2
+ Copyright (c) 2005, Qantom Software
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11
+
12
+ (based on BSD Open Source License)
13
+ =end
14
+
15
+ module Wet
16
+ module Winobjects
17
+ =begin
18
+ Class to represent a win32 button
19
+ =end
20
+ class WinCheckbox < WinButton
21
+
22
+ @@known_class_names = ["Button"]
23
+
24
+
25
+
26
+ =begin rdoc
27
+ Is the Window object a possible candidate for this class?
28
+ Return true if yes. False otherwise.
29
+ =end
30
+ #Note : - in the interest of reusable design, I had first put it this as a method
31
+ #in Window. But then I realized that each class may have to make complex
32
+ #calculations - eg. A label could be a static or an edit field set to read-only
33
+ def WinCheckbox.candidate_match?(win_element)
34
+ is_match = false
35
+ @@known_class_names.each do |e|
36
+ if TextUtils.compare_text(win_element.win_class,e)
37
+ tmp_button = WinButton.new(win_element.hwnd)
38
+ if tmp_button.is_checkbox()
39
+ is_match = true
40
+ break
41
+ end
42
+ end
43
+ end
44
+ return is_match
45
+ end
46
+
47
+ =begin rdoc
48
+ Is the radio button 'checked'?
49
+ Return true if yes. False otherwise
50
+ =end
51
+ def is_checked()
52
+ assert_object_exists
53
+ return button_state()== BST_CHECKED
54
+ end
55
+
56
+
57
+ =begin rdoc
58
+ Set this checkbox to 'Checked' state
59
+ =end
60
+ def set_on()
61
+ assert_object_exists
62
+ do_set_check_on(@hwnd)
63
+ end
64
+
65
+ =begin rdoc
66
+ Clear this checkbox if already checked
67
+ =end
68
+ def set_off()
69
+ assert_object_exists
70
+ do_set_check_off(@hwnd)
71
+ end
72
+
73
+ def to_s()
74
+ str = "WinCheckbox(text:="
75
+ str = str + text()
76
+ str = str + ")"
77
+ return str
78
+ end
79
+
80
+
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,70 @@
1
+ =begin license
2
+ Copyright (c) 2005, Qantom Software
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11
+
12
+ (based on BSD Open Source License)
13
+ =end
14
+
15
+ module Wet
16
+ module Winobjects
17
+ =begin rdoc
18
+ Class to represent a Win32 Combobox.
19
+ =end
20
+ class WinComboBox < Window
21
+
22
+ @@known_class_names = [/ComboBox/]
23
+
24
+ =begin rdoc
25
+ Is the Window object a possible candidate for this class?
26
+ Return true if yes. False otherwise.
27
+ =end
28
+ #Note : - in the interest of reusable design, I had first put it this as a method
29
+ #in Window. But then I realized that each class may have to make complex
30
+ #calculations - eg. A label could be a static or an edit field set to read-only
31
+ def WinComboBox.candidate_match?(win_element)
32
+ is_match = false
33
+ @@known_class_names.each do |e|
34
+ if TextUtils.compare_text(win_element.win_class,e)
35
+ is_match = true
36
+ break
37
+ end
38
+ end
39
+ return is_match
40
+ end
41
+
42
+ =begin
43
+ Set the text in a combo box
44
+ =end
45
+ def set(text)
46
+ assert_object_exists
47
+ return do_set_text(@hwnd, text)
48
+ end
49
+
50
+ =begin
51
+ We dont want to return the child objects of a combobox
52
+ The edit control / second combo are a part of the combobox
53
+ =end
54
+ def child_objects()
55
+ assert_object_exists
56
+ return []
57
+ end
58
+
59
+ def to_s()
60
+ str = "WinComboBox(label:="
61
+ if label != nil
62
+ str = str + label()
63
+ end
64
+ str = str + ")"
65
+ return str
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,112 @@
1
+ =begin license
2
+ Copyright (c) 2005, Qantom Software
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of Qantom Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11
+
12
+ (based on BSD Open Source License)
13
+ =end
14
+
15
+
16
+ require 'wet/winobjects/Window.rb'
17
+
18
+ module Wet
19
+ module Winobjects
20
+
21
+ =begin rdoc
22
+ Class representing any Win32 window. This class
23
+ has elements to access all of the known (actually currently
24
+ used in the context of Web Testing) types of objects like
25
+ Button, Edit and ComboBox
26
+ =end
27
+ class WinDialog < Window
28
+
29
+ def initialize(parent, hwnd)
30
+ super(hwnd)
31
+ @owner = AppWindow.new(parent)
32
+ end
33
+
34
+ =begin rdoc
35
+ Find a Dialog whose parent is parent_hwnd and
36
+ properties matches 'props'. If props is nill, then
37
+ the active popup dialog is returned.
38
+
39
+ The allowed properties are:
40
+ 1) text - The title of this dialog box.
41
+
42
+ You typically dont have to call this directly. The wrapper
43
+ method in the AppWindow will do it for you.
44
+ myAppWindow.Dialog("text" => "Microsoft internet")
45
+ =end
46
+ # if props is nil, then the dialog that is owned by the
47
+ # parent is returned.
48
+ def WinDialog.find(parent_hwnd, props=nil)
49
+ if props == nil
50
+ props = {"title" => /.*/}
51
+ end
52
+ CompileUtils.assert_argument_types(Hash, props.class)
53
+ tmp_hwnd = -1
54
+ timeout(Object_timeout) do
55
+ while tmp_hwnd == -1
56
+ tmp_hwnd = enabled_popup(parent_hwnd)
57
+ if tmp_hwnd == -1
58
+ sleep 1
59
+ end
60
+ end
61
+ end
62
+
63
+ # This is not the right way to do it. If a popup is found, but title
64
+ # doesn't match, actual approach would be to go back to the start
65
+ # of the timeout loop and try again waiting for another active popup.
66
+ #But right now just return nil if the title doesn't match
67
+ if props.length == 1 && props['title'] != nil
68
+ title = props['title']
69
+ act=window_caption(tmp_hwnd)
70
+ if !TextUtils.compare_text(act, title)
71
+ tmp_hwnd = -1
72
+ end
73
+ else
74
+ raise UnsupportedOperationException.new("Can only search windows using title")
75
+ end
76
+
77
+ dlg = WinDialog.new(parent_hwnd, tmp_hwnd)
78
+
79
+ return dlg
80
+ end
81
+
82
+ =begin rdoc
83
+ Return the owner of this dialog box. Popup dialog boxes
84
+ are usually owned by some other windows.
85
+ =end
86
+ def owner()
87
+ assert_object_exists
88
+ return @owner
89
+ end
90
+
91
+
92
+ =begin rdoc
93
+ Return a text that is an aggregate of all 'displayed' text elements.
94
+ =end
95
+ def content_text()
96
+ ret_text=""
97
+ child_objects.each do |c|
98
+ ret_text=ret_text+c.display_text()
99
+ end
100
+ return ret_text
101
+ end
102
+
103
+ def to_s()
104
+ str = "Dialog(title:="
105
+ str = str + text()
106
+ str = str + ")"
107
+ return str
108
+ end
109
+
110
+ end
111
+ end
112
+ end