watir-classic 3.3.0 → 3.4.0
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.
- data/CHANGES +17 -0
- data/Gemfile.lock +9 -8
- data/LICENSE +1 -0
- data/README.rdoc +6 -7
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/lib/watir-classic.rb +0 -5
- data/lib/watir-classic/browser.rb +58 -35
- data/lib/watir-classic/browsers.rb +1 -1
- data/lib/watir-classic/container.rb +39 -33
- data/lib/watir-classic/cookies.rb +32 -2
- data/lib/watir-classic/core.rb +0 -1
- data/lib/watir-classic/dialogs/alert.rb +12 -0
- data/lib/watir-classic/dialogs/file_field.rb +11 -0
- data/lib/watir-classic/drag_and_drop_helper.rb +14 -0
- data/lib/watir-classic/element.rb +292 -257
- data/lib/watir-classic/element_collection.rb +26 -8
- data/lib/watir-classic/element_extensions.rb +22 -16
- data/lib/watir-classic/exceptions.rb +4 -4
- data/lib/watir-classic/form.rb +52 -49
- data/lib/watir-classic/frame.rb +23 -14
- data/lib/watir-classic/ie-class.rb +363 -315
- data/lib/watir-classic/ie-process.rb +1 -0
- data/lib/watir-classic/ie.rb +0 -17
- data/lib/watir-classic/image.rb +58 -64
- data/lib/watir-classic/input_elements.rb +224 -219
- data/lib/watir-classic/link.rb +14 -15
- data/lib/watir-classic/locator.rb +12 -7
- data/lib/watir-classic/matches.rb +7 -3
- data/lib/watir-classic/modal_dialog.rb +38 -26
- data/lib/watir-classic/non_control_elements.rb +29 -0
- data/lib/watir-classic/options.rb +10 -15
- data/lib/watir-classic/page-container.rb +30 -48
- data/lib/watir-classic/process.rb +4 -2
- data/lib/watir-classic/screenshot.rb +6 -0
- data/lib/watir-classic/supported_elements.rb +36 -14
- data/lib/watir-classic/table.rb +81 -71
- data/lib/watir-classic/util.rb +9 -11
- data/lib/watir-classic/wait.rb +17 -4
- data/lib/watir-classic/wait_helper.rb +15 -2
- data/lib/watir-classic/win32.rb +2 -1
- data/lib/watir-classic/window.rb +35 -7
- data/lib/watir-classic/xpath_locator.rb +1 -0
- data/lib/watir-classic/yard/global_macros.rb +7 -0
- data/spec/frame_spec.rb +17 -0
- metadata +5 -7
- data/lib/watir-classic/close_all.rb +0 -31
- data/lib/watir-classic/contrib/enabled_popup.rb +0 -21
- data/lib/watir-classic/contrib/ie-new-process.rb +0 -27
- data/lib/watir-classic/contrib/page_checker.rb +0 -29
- data/watir.gif +0 -0
data/lib/watir-classic/ie.rb
CHANGED
@@ -1,22 +1,5 @@
|
|
1
1
|
require 'watir-classic'
|
2
2
|
require 'watir-classic/core'
|
3
|
-
require 'watir-classic/close_all'
|
4
3
|
require 'watir-classic/ie-process'
|
5
4
|
require 'watir-classic/screenshot'
|
6
5
|
require 'multi_json'
|
7
|
-
|
8
|
-
# these switches need to be deleted from ARGV to enable the Test::Unit
|
9
|
-
# functionality that grabs
|
10
|
-
# the remaining ARGV as a filter on what tests to run.
|
11
|
-
# Note: this means that watir-classic must be require'd BEFORE test/unit.
|
12
|
-
# (Alternatively, you could require test/unit first and then put the Watir::IE
|
13
|
-
# arguments after the '--'.)
|
14
|
-
|
15
|
-
# Make Internet Explorer invisible. -b stands for background
|
16
|
-
$HIDE_IE ||= ARGV.delete('-b')
|
17
|
-
|
18
|
-
# Run fast
|
19
|
-
$FAST_SPEED = ARGV.delete('-f')
|
20
|
-
|
21
|
-
# Eat the -s command line switch (deprecated)
|
22
|
-
ARGV.delete('-s')
|
data/lib/watir-classic/image.rb
CHANGED
@@ -1,91 +1,50 @@
|
|
1
1
|
module Watir
|
2
2
|
|
3
|
-
#
|
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
|
-
#
|
3
|
+
# Returned by {Container#image}
|
8
4
|
class Image < Element
|
9
5
|
attr_ole :alt
|
10
6
|
attr_ole :src
|
11
7
|
|
12
|
-
#
|
13
|
-
|
14
|
-
n = []
|
15
|
-
n << "src:".ljust(TO_S_SIZE) + self.src.to_s
|
16
|
-
n << "file date:".ljust(TO_S_SIZE) + self.fileCreatedDate.to_s
|
17
|
-
n << "file size:".ljust(TO_S_SIZE) + self.fileSize.to_s
|
18
|
-
n << "width:".ljust(TO_S_SIZE) + self.width.to_s
|
19
|
-
n << "height:".ljust(TO_S_SIZE) + self.height.to_s
|
20
|
-
n << "alt:".ljust(TO_S_SIZE) + self.alt.to_s
|
21
|
-
return n
|
22
|
-
end
|
23
|
-
private :image_string_creator
|
24
|
-
|
25
|
-
# returns a string representation of the object
|
26
|
-
def to_s
|
27
|
-
assert_exists
|
28
|
-
r = string_creator
|
29
|
-
r += image_string_creator
|
30
|
-
return r.join("\n")
|
31
|
-
end
|
32
|
-
|
33
|
-
# this method returns the filesize of the image, as an int
|
8
|
+
# @return [Fixnum] file size of the image in bytes.
|
9
|
+
# @macro exists
|
34
10
|
def file_size
|
35
11
|
assert_exists
|
36
12
|
@o.invoke("fileSize").to_i
|
37
13
|
end
|
38
14
|
|
39
|
-
#
|
15
|
+
# @return [Fixnum] width of the image in pixels.
|
16
|
+
# @macro exists
|
40
17
|
def width
|
41
18
|
assert_exists
|
42
19
|
@o.invoke("width").to_i
|
43
20
|
end
|
44
21
|
|
45
|
-
#
|
22
|
+
# @return [Fixnum] height of the image in pixels.
|
23
|
+
# @macro exists
|
46
24
|
def height
|
47
25
|
assert_exists
|
48
26
|
@o.invoke("height").to_i
|
49
27
|
end
|
50
28
|
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# We look for these missing properties to see if the image is really there or not.
|
54
|
-
# If the Disk cache is full (tools menu -> Internet options -> Temporary Internet Files), it may produce incorrect responses.
|
29
|
+
# @return [Boolean] true if image is loaded by the browser, false otherwise.
|
30
|
+
# @macro exists
|
55
31
|
def loaded?
|
56
32
|
assert_exists
|
57
33
|
file_size != -1
|
58
34
|
end
|
59
35
|
|
60
|
-
#
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@o.border = @original_border
|
73
|
-
@original_border = nil
|
74
|
-
rescue
|
75
|
-
# we could be here for a number of reasons...
|
76
|
-
ensure
|
77
|
-
@original_border = nil
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
private :highlight
|
82
|
-
|
83
|
-
# This method saves the image to the file path that is given. The
|
84
|
-
# path must be in windows format (c:\\dirname\\somename.gif). This method
|
85
|
-
# will not overwrite a previously existing image. If an image already
|
86
|
-
# exists at the given path then a dialog will be displayed prompting
|
87
|
-
# for overwrite.
|
88
|
-
# path - directory path and file name of where image should be saved
|
36
|
+
# Save the image to the file.
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# browser.image.save("c:/foo/bar.jpg")
|
40
|
+
#
|
41
|
+
# @param [String] path path to the file.
|
42
|
+
#
|
43
|
+
# @note This method will not overwrite a previously existing image.
|
44
|
+
# If an image already exists at the given path then a dialog
|
45
|
+
# will be displayed prompting for overwrite.
|
46
|
+
#
|
47
|
+
# @todo it should raise an Exception if image already exists.
|
89
48
|
def save(path)
|
90
49
|
@container.goto(src)
|
91
50
|
begin
|
@@ -95,7 +54,28 @@ module Watir
|
|
95
54
|
@container.back
|
96
55
|
end
|
97
56
|
end
|
98
|
-
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
assert_exists
|
60
|
+
r = string_creator
|
61
|
+
r += image_string_creator
|
62
|
+
return r.join("\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# this method produces the properties for an image as an array
|
68
|
+
def image_string_creator
|
69
|
+
n = []
|
70
|
+
n << "src:".ljust(TO_S_SIZE) + self.src.to_s
|
71
|
+
n << "file date:".ljust(TO_S_SIZE) + self.fileCreatedDate.to_s
|
72
|
+
n << "file size:".ljust(TO_S_SIZE) + self.fileSize.to_s
|
73
|
+
n << "width:".ljust(TO_S_SIZE) + self.width.to_s
|
74
|
+
n << "height:".ljust(TO_S_SIZE) + self.height.to_s
|
75
|
+
n << "alt:".ljust(TO_S_SIZE) + self.alt.to_s
|
76
|
+
return n
|
77
|
+
end
|
78
|
+
|
99
79
|
def fill_save_image_dialog(path)
|
100
80
|
command = "require 'rubygems';require 'rautomation';" <<
|
101
81
|
"window=::RAutomation::Window.new(:title => 'Save Picture');" <<
|
@@ -103,7 +83,21 @@ module Watir
|
|
103
83
|
"window.button(:value => '&Save').click"
|
104
84
|
IO.popen("ruby -e \"#{command}\"")
|
105
85
|
end
|
106
|
-
|
86
|
+
|
87
|
+
# Highlight the image (in fact it adds a border around the image).
|
88
|
+
def set_highlight
|
89
|
+
perform_highlight do
|
90
|
+
@original_border = @o.border
|
91
|
+
@o.border = 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Clear the highlight of the image (in fact it removes a border around the image).
|
96
|
+
def clear_highlight
|
97
|
+
perform_highlight do
|
98
|
+
@o.border = @original_border if @original_border
|
99
|
+
end
|
100
|
+
end
|
107
101
|
|
108
102
|
end
|
109
103
|
|
@@ -1,37 +1,41 @@
|
|
1
1
|
module Watir
|
2
|
-
|
3
|
-
class InputElement < Element #:nodoc:all
|
4
|
-
def locate
|
5
|
-
@o = @container.locator_for(InputElementLocator, @specifiers, self.class).locate
|
6
|
-
end
|
7
2
|
|
3
|
+
# Super-class for input elements like {SelectList}, {Button} etc.
|
4
|
+
class InputElement < Element
|
8
5
|
attr_ole :disabled?
|
9
6
|
attr_ole :name
|
10
7
|
attr_ole :value
|
11
8
|
attr_ole :alt
|
12
9
|
attr_ole :src
|
13
10
|
attr_ole :type
|
11
|
+
|
12
|
+
# @private
|
13
|
+
def locate
|
14
|
+
@o = @container.locator_for(InputElementLocator, @specifiers, self.class).locate
|
15
|
+
end
|
16
|
+
|
14
17
|
end
|
15
18
|
|
16
|
-
#
|
17
|
-
# Input: Select
|
18
|
-
#
|
19
|
-
|
20
|
-
# This class is the way in which select boxes are manipulated.
|
21
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#select_list method
|
19
|
+
# Returned by {Container#select_list}.
|
22
20
|
class SelectList < InputElement
|
23
21
|
attr_ole :multiple?
|
24
22
|
|
25
|
-
#
|
23
|
+
# Clear the selected options in the select list.
|
24
|
+
#
|
25
|
+
# @macro exists
|
26
|
+
# @macro enabled
|
26
27
|
def clear
|
27
28
|
perform_action do
|
28
29
|
options.each(&:clear)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
33
|
+
# Select an item or items in a select box.
|
34
|
+
#
|
35
|
+
# @param [String,Regexp] item option to select by text, label or value.
|
36
|
+
# @raise [NoValueFoundException] when no options found.
|
37
|
+
# @macro exists
|
38
|
+
# @macro enabled
|
35
39
|
def select(item)
|
36
40
|
matching_options = []
|
37
41
|
perform_action do
|
@@ -43,30 +47,42 @@ module Watir
|
|
43
47
|
end
|
44
48
|
matching_options.first.text
|
45
49
|
end
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
+
|
51
|
+
# Select an item or items in a select box by option's value.
|
52
|
+
#
|
53
|
+
# @param [String,Regexp] item option to select by value.
|
54
|
+
# @raise [NoValueFoundException] when no options found.
|
55
|
+
# @macro exists
|
56
|
+
# @macro enabled
|
50
57
|
def select_value(item)
|
51
58
|
matching_options = matching_items_in_select_list(:value, item)
|
52
59
|
raise NoValueFoundException, "No option with :value of #{item.inspect} in this select element" if matching_options.empty?
|
53
60
|
matching_options.each(&:select)
|
54
61
|
matching_options.first.value
|
55
62
|
end
|
56
|
-
|
57
|
-
#
|
58
|
-
#
|
63
|
+
|
64
|
+
# @example Retrieve selected options as a text:
|
65
|
+
# browser.select_list.selected_options.map(&:text)
|
66
|
+
#
|
67
|
+
# @return [Array<OptionCollection>] array of selected options.
|
68
|
+
# @macro exists
|
59
69
|
def selected_options
|
60
70
|
options.select(&:selected?)
|
61
71
|
end
|
62
72
|
|
63
|
-
#
|
64
|
-
|
73
|
+
# @param [String,Regexp] text_or_regexp option with text to search for.
|
74
|
+
# @return [Boolean] true when option with text includes in select list,
|
75
|
+
# false otherwise.
|
76
|
+
# @macro exists
|
77
|
+
def include?(text_or_regexp)
|
65
78
|
!options.map(&:text).grep(text_or_regexp).empty?
|
66
79
|
end
|
67
80
|
|
68
|
-
#
|
69
|
-
|
81
|
+
# @param [String,Regexp] text_or_regexp option with text to search for.
|
82
|
+
# @return [Boolean] true when option with text is selected in select list,
|
83
|
+
# false otherwise.
|
84
|
+
# @macro exists
|
85
|
+
def selected?(text_or_regexp)
|
70
86
|
raise UnknownObjectException, "Option #{text_or_regexp.inspect} not found." unless include? text_or_regexp
|
71
87
|
!selected_options.map(&:text).grep(text_or_regexp).empty?
|
72
88
|
end
|
@@ -85,19 +101,29 @@ module Watir
|
|
85
101
|
end
|
86
102
|
end
|
87
103
|
end
|
88
|
-
|
104
|
+
|
105
|
+
# Returned by {Container#option}.
|
89
106
|
class Option < Element
|
90
107
|
attr_ole :disabled?
|
91
108
|
attr_ole :name
|
92
109
|
attr_ole :value
|
93
110
|
attr_ole :label
|
94
111
|
|
112
|
+
# Select the option in its select list.
|
113
|
+
#
|
114
|
+
# @macro exists
|
115
|
+
# @macro enabled
|
95
116
|
def select
|
96
117
|
perform_action do
|
97
118
|
change_selected true unless selected?
|
98
119
|
end
|
99
120
|
end
|
100
121
|
|
122
|
+
# Clear option in multi-select list.
|
123
|
+
#
|
124
|
+
# @raise [TypeError] when select list is not multi-select.
|
125
|
+
# @macro exists
|
126
|
+
# @macro enabled
|
101
127
|
def clear
|
102
128
|
raise TypeError, "you can only clear multi-selects" unless select_list.multiple?
|
103
129
|
|
@@ -106,11 +132,14 @@ module Watir
|
|
106
132
|
end
|
107
133
|
end
|
108
134
|
|
135
|
+
# @return [Boolean] true when option is selected, false otherwise.
|
136
|
+
# @macro exists
|
109
137
|
def selected?
|
110
138
|
assert_exists
|
111
139
|
ole_object.selected
|
112
140
|
end
|
113
141
|
|
142
|
+
# Text of the option.
|
114
143
|
def text
|
115
144
|
l = label
|
116
145
|
l.empty? ? super : l rescue ''
|
@@ -135,14 +164,12 @@ module Watir
|
|
135
164
|
end
|
136
165
|
end
|
137
166
|
|
138
|
-
#
|
139
|
-
# Input: Button
|
140
|
-
#
|
141
|
-
|
142
|
-
# Returned by the Watir::Container#button method
|
167
|
+
# Returned by the {Container#button} method.
|
143
168
|
class Button < InputElement
|
144
169
|
alias_method :__value, :value
|
145
170
|
|
171
|
+
# @return [String] button contents of value attribute or inner text if there's no value.
|
172
|
+
# @see Element#text
|
146
173
|
def text
|
147
174
|
val = __value
|
148
175
|
val.empty? ? super : val
|
@@ -151,59 +178,103 @@ module Watir
|
|
151
178
|
alias_method :value, :text
|
152
179
|
end
|
153
180
|
|
154
|
-
#
|
155
|
-
# Input: Text
|
156
|
-
#
|
157
|
-
|
158
|
-
# This class is the main class for Text Fields
|
159
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#text_field method
|
181
|
+
# Returned be {Container#text_field}.
|
160
182
|
class TextField < InputElement
|
161
183
|
attr_ole :size
|
162
184
|
attr_ole :readonly?
|
163
185
|
alias_method :text, :value
|
164
186
|
|
165
|
-
|
166
|
-
|
167
|
-
# return number of maxlength attribute
|
187
|
+
# @return [Fixnum] value of maxlength attribute.
|
188
|
+
# @macro exists
|
168
189
|
def maxlength
|
169
|
-
assert_exists
|
190
|
+
assert_exists
|
170
191
|
begin
|
171
192
|
ole_object.invoke('maxlength').to_i
|
172
193
|
rescue WIN32OLERuntimeError
|
173
194
|
0
|
174
195
|
end
|
175
196
|
end
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
n << "max length:".ljust(TO_S_SIZE) + self.maxlength.to_s
|
181
|
-
n << "read only:".ljust(TO_S_SIZE) + self.readonly?.to_s
|
182
|
-
n
|
197
|
+
|
198
|
+
# @return [String] text field label's text.
|
199
|
+
def label
|
200
|
+
@container.label(:for => name).text
|
183
201
|
end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
202
|
+
|
203
|
+
# Clear the contents of the text field.
|
204
|
+
#
|
205
|
+
# @macro exists
|
206
|
+
# @macro enabled
|
207
|
+
# @raise [ObjectReadOnlyException] if the text field is read only.
|
208
|
+
def clear
|
209
|
+
perform_action do
|
210
|
+
assert_not_readonly
|
211
|
+
@o.scrollIntoView
|
212
|
+
@o.focus(0)
|
213
|
+
@o.select(0)
|
214
|
+
dispatch_event("onSelect")
|
215
|
+
@o.value = ""
|
216
|
+
dispatch_event("onKeyPress")
|
217
|
+
dispatch_event("onChange")
|
218
|
+
@container.wait
|
219
|
+
end
|
191
220
|
end
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
221
|
+
|
222
|
+
# Append the specified text value to the contents of the text field.
|
223
|
+
#
|
224
|
+
# @param [String] value text to append to current text field's value.
|
225
|
+
# @macro exists
|
226
|
+
# @macro enabled
|
227
|
+
# @raise [ObjectReadOnlyException] if the text field is read only.
|
228
|
+
def append(value)
|
229
|
+
perform_action do
|
230
|
+
assert_not_readonly
|
231
|
+
@o.scrollIntoView
|
232
|
+
@o.focus(0)
|
233
|
+
type_by_character(value)
|
197
234
|
end
|
198
235
|
end
|
199
|
-
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
|
204
|
-
#
|
205
|
-
#
|
206
|
-
def
|
236
|
+
|
237
|
+
# Sets the contents of the text field to the specified value.
|
238
|
+
#
|
239
|
+
# @param [String] value text to set as value.
|
240
|
+
# @macro exists
|
241
|
+
# @macro enabled
|
242
|
+
# @raise [ObjectReadOnlyException] if the text field is read only.
|
243
|
+
def set(value)
|
244
|
+
perform_action do
|
245
|
+
assert_not_readonly
|
246
|
+
@o.scrollIntoView
|
247
|
+
if type_keys
|
248
|
+
@o.focus(0)
|
249
|
+
@o.select(0)
|
250
|
+
dispatch_event("onSelect")
|
251
|
+
dispatch_event("onKeyPress")
|
252
|
+
@o.value = ""
|
253
|
+
type_by_character(value)
|
254
|
+
dispatch_event("onChange")
|
255
|
+
dispatch_event("onBlur")
|
256
|
+
else
|
257
|
+
@o.value = limit_to_maxlength(value)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
# Sets the value of the text field directly.
|
263
|
+
#
|
264
|
+
# @note it does not cause any JavaScript events to be fired or exceptions
|
265
|
+
# to be raised. Using {#set} is recommended.
|
266
|
+
#
|
267
|
+
# @param [String] value value to be set.
|
268
|
+
# @macro exists
|
269
|
+
def value=(value)
|
270
|
+
assert_exists
|
271
|
+
@o.value = value.to_s
|
272
|
+
end
|
273
|
+
|
274
|
+
# @deprecated Use "browser.text_field.value.include?(target)" or
|
275
|
+
# "browser.text_field.value.match(target) instead."
|
276
|
+
def verify_contains(target)
|
277
|
+
Kernel.warn "Deprecated(TextField#verify_contains) - use \"browser.text_field.value.include?(target)\" or \"browser.text_field.value.match(target)\" instead."
|
207
278
|
assert_exists
|
208
279
|
if target.kind_of? String
|
209
280
|
return true if self.value == target
|
@@ -212,22 +283,20 @@ module Watir
|
|
212
283
|
end
|
213
284
|
return false
|
214
285
|
end
|
215
|
-
|
216
|
-
#
|
217
|
-
# 19 Jan 2005 - It is added as prototype functionality, and may change
|
218
|
-
# * destination_how - symbol, :id, :name how we identify the drop target
|
219
|
-
# * destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target
|
286
|
+
|
287
|
+
# @deprecated Not part of the WatirSpec API.
|
220
288
|
def drag_contents_to(destination_how, destination_what)
|
289
|
+
Kernel.warn "Deprecated(TextField#drag_contents_to) - is not parf ot the WatirSpec API and might be deleted in the future."
|
221
290
|
assert_exists
|
222
291
|
destination = @container.text_field(destination_how, destination_what)
|
223
292
|
unless destination.exists?
|
224
293
|
raise UnknownObjectException, "Unable to locate destination using #{destination_how } and #{destination_what } "
|
225
294
|
end
|
226
|
-
|
295
|
+
|
227
296
|
@o.focus(0)
|
228
297
|
@o.select(0)
|
229
298
|
value = self.value
|
230
|
-
|
299
|
+
|
231
300
|
dispatch_event("onSelect")
|
232
301
|
dispatch_event("ondragstart")
|
233
302
|
dispatch_event("ondrag")
|
@@ -235,96 +304,37 @@ module Watir
|
|
235
304
|
destination.dispatch_event("onDragEnter")
|
236
305
|
destination.dispatch_event("onDragOver")
|
237
306
|
destination.dispatch_event("ondrop")
|
238
|
-
|
307
|
+
|
239
308
|
dispatch_event("ondragend")
|
240
309
|
destination.value = destination.value + value.to_s
|
241
310
|
self.value = ""
|
242
311
|
end
|
243
|
-
|
244
|
-
# Clears the contents of the text box.
|
245
|
-
# Raises UnknownObjectException if the object can't be found
|
246
|
-
# Raises ObjectDisabledException if the object is disabled
|
247
|
-
# Raises ObjectReadOnlyException if the object is read only
|
248
|
-
def clear
|
249
|
-
assert_exists
|
250
|
-
assert_enabled
|
251
|
-
assert_not_readonly
|
252
|
-
|
253
|
-
highlight(:set)
|
254
|
-
|
255
|
-
@o.scrollIntoView
|
256
|
-
@o.focus(0)
|
257
|
-
@o.select(0)
|
258
|
-
dispatch_event("onSelect")
|
259
|
-
@o.value = ""
|
260
|
-
dispatch_event("onKeyPress")
|
261
|
-
dispatch_event("onChange")
|
262
|
-
@container.wait
|
263
|
-
highlight(:clear)
|
264
|
-
end
|
265
|
-
|
266
|
-
# Appends the specified string value to the contents of the text box.
|
267
|
-
# Raises UnknownObjectException if the object cant be found
|
268
|
-
# Raises ObjectDisabledException if the object is disabled
|
269
|
-
# Raises ObjectReadOnlyException if the object is read only
|
270
|
-
def append(value)
|
271
|
-
assert_exists
|
272
|
-
assert_enabled
|
273
|
-
assert_not_readonly
|
274
|
-
|
275
|
-
highlight(:set)
|
276
|
-
@o.scrollIntoView
|
277
|
-
@o.focus(0)
|
278
|
-
type_by_character(value)
|
279
|
-
highlight(:clear)
|
280
|
-
end
|
281
|
-
|
282
|
-
# Sets the contents of the text box to the specified text value
|
283
|
-
# Raises UnknownObjectException if the object cant be found
|
284
|
-
# Raises ObjectDisabledException if the object is disabled
|
285
|
-
# Raises ObjectReadOnlyException if the object is read only
|
286
|
-
def set(value)
|
287
|
-
assert_exists
|
288
|
-
assert_enabled
|
289
|
-
assert_not_readonly
|
290
|
-
|
291
|
-
highlight(:set)
|
292
|
-
@o.scrollIntoView
|
293
|
-
if type_keys
|
294
|
-
@o.focus(0)
|
295
|
-
@o.select(0)
|
296
|
-
dispatch_event("onSelect")
|
297
|
-
dispatch_event("onKeyPress")
|
298
|
-
@o.value = ""
|
299
|
-
type_by_character(value)
|
300
|
-
dispatch_event("onChange")
|
301
|
-
dispatch_event("onBlur")
|
302
|
-
else
|
303
|
-
@o.value = limit_to_maxlength(value)
|
304
|
-
end
|
305
|
-
highlight(:clear)
|
306
|
-
end
|
307
312
|
|
308
|
-
|
309
|
-
# It causes no events to be fired or exceptions to be raised,
|
310
|
-
# so generally shouldn't be used.
|
311
|
-
# It is preffered to use the set method.
|
312
|
-
def value=(v)
|
313
|
+
def to_s
|
313
314
|
assert_exists
|
314
|
-
|
315
|
+
r = string_creator
|
316
|
+
r += text_string_creator
|
317
|
+
r.join("\n")
|
315
318
|
end
|
316
319
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
+
# @private
|
321
|
+
def requires_typing
|
322
|
+
@type_keys = true
|
323
|
+
self
|
320
324
|
end
|
321
|
-
|
322
|
-
|
323
|
-
|
325
|
+
|
326
|
+
# @private
|
327
|
+
def abhors_typing
|
328
|
+
@type_keys = false
|
329
|
+
self
|
324
330
|
end
|
325
331
|
|
326
|
-
|
327
|
-
|
332
|
+
# @private
|
333
|
+
def assert_not_readonly
|
334
|
+
if self.readonly?
|
335
|
+
raise ObjectReadOnlyException,
|
336
|
+
"Textfield #{@specifiers.inspect} is read only."
|
337
|
+
end
|
328
338
|
end
|
329
339
|
|
330
340
|
private
|
@@ -342,7 +352,7 @@ module Watir
|
|
342
352
|
dispatch_event("onKeyUp")
|
343
353
|
end
|
344
354
|
end
|
345
|
-
|
355
|
+
|
346
356
|
# Supports double-byte characters
|
347
357
|
def characters_in(value, &blk)
|
348
358
|
if RUBY_VERSION =~ /^1\.8/
|
@@ -356,7 +366,7 @@ module Watir
|
|
356
366
|
value.each_char(&blk)
|
357
367
|
end
|
358
368
|
end
|
359
|
-
|
369
|
+
|
360
370
|
# Return the value (a string), limited to the maxlength of the element.
|
361
371
|
def limit_to_maxlength(value)
|
362
372
|
return value if @o.invoke('type') =~ /textarea/i # text areas don't have maxlength
|
@@ -366,31 +376,40 @@ module Watir
|
|
366
376
|
value
|
367
377
|
end
|
368
378
|
|
379
|
+
def text_string_creator
|
380
|
+
n = []
|
381
|
+
n << "length:".ljust(TO_S_SIZE) + self.size.to_s
|
382
|
+
n << "max length:".ljust(TO_S_SIZE) + self.maxlength.to_s
|
383
|
+
n << "read only:".ljust(TO_S_SIZE) + self.readonly?.to_s
|
384
|
+
n
|
385
|
+
end
|
386
|
+
|
369
387
|
end
|
370
388
|
|
371
|
-
#
|
372
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#hidden method
|
389
|
+
# Returned by the {Container#hidden}.
|
373
390
|
class Hidden < TextField
|
374
|
-
#
|
375
|
-
def set(
|
376
|
-
self.value =
|
391
|
+
# @see TextField#set
|
392
|
+
def set(value)
|
393
|
+
self.value = value
|
377
394
|
end
|
378
|
-
|
379
|
-
#
|
380
|
-
def append(
|
381
|
-
self.value = self.value.to_s +
|
395
|
+
|
396
|
+
# @see TextField#append
|
397
|
+
def append(value)
|
398
|
+
self.value = self.value.to_s + value.to_s
|
382
399
|
end
|
383
|
-
|
384
|
-
#
|
400
|
+
|
401
|
+
# @see TextField#clear
|
385
402
|
def clear
|
386
403
|
self.value = ""
|
387
404
|
end
|
388
|
-
|
389
|
-
#
|
405
|
+
|
406
|
+
# This method will do nothing since it is impossible to set focus to
|
407
|
+
# a hidden field.
|
390
408
|
def focus
|
391
409
|
end
|
392
|
-
|
393
|
-
#
|
410
|
+
|
411
|
+
# @return [Boolean] always false, since hidden element is never visible.
|
412
|
+
# @macro exists
|
394
413
|
def visible?
|
395
414
|
assert_exists
|
396
415
|
false
|
@@ -398,7 +417,7 @@ module Watir
|
|
398
417
|
end
|
399
418
|
|
400
419
|
# This module contains common methods to both radio buttons and check boxes.
|
401
|
-
# Normally a user would not need to create this object as it is returned by the
|
420
|
+
# Normally a user would not need to create this object as it is returned by the {Container#checkbox} or by {Container#radio} methods.
|
402
421
|
module RadioCheckCommon
|
403
422
|
def self.included(base)
|
404
423
|
base.instance_eval do
|
@@ -411,65 +430,51 @@ module Watir
|
|
411
430
|
'#<%s:0x%x located=%s specifiers=%s value=%s>' % [self.class, hash*2, !!ole_object, @specifiers.inspect, @value.inspect]
|
412
431
|
end
|
413
432
|
end
|
414
|
-
|
415
|
-
|
416
|
-
# this class makes the docs better
|
417
|
-
#++
|
418
|
-
# This class is the watir representation of a radio button.
|
419
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#radio method
|
433
|
+
|
434
|
+
# Returned by {Container#radio}.
|
420
435
|
class Radio < InputElement
|
421
436
|
include RadioCheckCommon
|
422
|
-
|
423
|
-
#
|
424
|
-
#
|
425
|
-
#
|
437
|
+
|
438
|
+
# Clear a radio button.
|
439
|
+
#
|
440
|
+
# @macro exists
|
441
|
+
# @macro enabled
|
426
442
|
def clear
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
# This method sets the radio list item.
|
436
|
-
# Raises UnknownObjectException if it's unable to locate an object
|
437
|
-
# ObjectDisabledException if the object is disabled
|
443
|
+
perform_action { @o.checked = false }
|
444
|
+
end
|
445
|
+
|
446
|
+
# Check a radio button.
|
447
|
+
#
|
448
|
+
# @macro exists
|
449
|
+
# @macro enabled
|
438
450
|
def set
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
click
|
445
|
-
highlight(:clear)
|
451
|
+
perform_action do
|
452
|
+
@o.scrollIntoView
|
453
|
+
@o.checked = true
|
454
|
+
click
|
455
|
+
end
|
446
456
|
end
|
447
457
|
|
448
458
|
end
|
449
459
|
|
450
|
-
#
|
451
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#checkbox method
|
460
|
+
# Returned by the {Watir::Container#checkbox} method.
|
452
461
|
class CheckBox < InputElement
|
453
462
|
include RadioCheckCommon
|
454
|
-
|
455
|
-
#
|
456
|
-
#
|
457
|
-
#
|
458
|
-
#
|
463
|
+
|
464
|
+
# Check or clear the checkbox.
|
465
|
+
# @param [Boolean] value If set to true (default) then checkbox is set, cleared otherwise.
|
466
|
+
# @macro exists
|
467
|
+
# @macro enabled
|
459
468
|
def set(value=true)
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
current_value = @o.checked
|
464
|
-
unless value == current_value
|
465
|
-
click
|
469
|
+
perform_action do
|
470
|
+
current_value = @o.checked
|
471
|
+
click unless value == current_value
|
466
472
|
end
|
467
|
-
highlight :clear
|
468
473
|
end
|
469
|
-
|
470
|
-
#
|
471
|
-
#
|
472
|
-
#
|
474
|
+
|
475
|
+
# Clear the checkbox.
|
476
|
+
# @macro exists
|
477
|
+
# @macro enabled
|
473
478
|
def clear
|
474
479
|
set false
|
475
480
|
end
|