watir 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/changes.rb +13 -2
- data/readme.rb +2 -0
- data/unittests/form_test.rb +1 -1
- data/unittests/html/forms2.html +1 -1
- data/unittests/setup.rb +1 -1
- data/unittests/speed_settings_test.rb +39 -5
- data/unittests/textfield_for_ch_char_test.rb +30 -0
- data/unittests/textfields_test.rb +3 -3
- data/watir/assertions.rb +1 -1
- data/watir/close_all.rb +1 -1
- data/watir/container.rb +8 -57
- data/watir/element.rb +4 -1
- data/watir/ie.rb +62 -32
- data/watir/input_elements.rb +79 -46
- data/watir/locator.rb +69 -0
- metadata +12 -2
data/changes.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
=begin rdoc
|
2
|
-
|
2
|
+
== Version 1.5.3
|
3
|
+
Bug fixes and minor cleanup.
|
4
|
+
|
5
|
+
* Fix text areas bugs.
|
6
|
+
* Fix warning messages caused by redefined constants.
|
7
|
+
* Break out watir.rb into multiple files.
|
8
|
+
* Fix [WTR-90] error when running tests when installing gem.
|
9
|
+
http://jira.openqa.org/browse/WTR-90
|
10
|
+
* Fix tests.
|
11
|
+
* Update documentation.
|
12
|
+
|
13
|
+
Major Changes in 1.5.1
|
3
14
|
Support for IE's Modal Dialogs.
|
4
15
|
showModalDialog()
|
5
16
|
Any method can be used to specify an element (:text, :class, etc.).
|
@@ -9,7 +20,7 @@ Major Changes in 1.5
|
|
9
20
|
One can now use multiple attributes to specify an element.
|
10
21
|
ie.span(:class =>'Label', :text => 'Add new').click
|
11
22
|
|
12
|
-
Other Changes in 1.5
|
23
|
+
Other Changes in 1.5.1
|
13
24
|
* Migrated IE.new_process from watir/contrib and improved its reliability. We now recommend IE.new_process over IE.new as a way to avoid numerous errors detailed in http://jira.openqa.org/browse/WTR-150.
|
14
25
|
* Added IE.start_process. This works like IE.start, but uses the new_process mechanism to start IE.
|
15
26
|
* Added IE.new_window and IE.start_window. This are synonyms for IE.new and IE.start.
|
data/readme.rb
CHANGED
data/unittests/form_test.rb
CHANGED
data/unittests/html/forms2.html
CHANGED
data/unittests/setup.rb
CHANGED
@@ -41,7 +41,7 @@ $non_core_tests =
|
|
41
41
|
$core_tests = $all_tests - $non_core_tests - $window_tests - $xpath_tests
|
42
42
|
|
43
43
|
$ie = Watir::IE.new
|
44
|
-
$ie.
|
44
|
+
$ie.speed = :fast
|
45
45
|
|
46
46
|
$myDir = File.expand_path(File.dirname(__FILE__))
|
47
47
|
$myDir.sub!( %r{/cygdrive/(\w)/}, '\1:/' ) # convert from cygwin to dos
|
@@ -1,22 +1,56 @@
|
|
1
1
|
# tests for ability to set defaults for Watir
|
2
|
-
# revision: $Revision:
|
2
|
+
# revision: $Revision: 1293 $
|
3
3
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
|
4
4
|
require 'test/unit'
|
5
5
|
require 'watir'
|
6
6
|
|
7
|
-
class
|
7
|
+
class TC_instance_options < Test::Unit::TestCase
|
8
8
|
include Watir
|
9
9
|
|
10
10
|
def test_using_default
|
11
|
-
@ie1 = IE.new
|
11
|
+
@ie1 = Watir::IE.new
|
12
12
|
@ie1.speed = :fast
|
13
13
|
assert_equal(:fast, @ie1.speed)
|
14
14
|
@ie1.speed = :slow
|
15
15
|
assert_equal(:slow, @ie1.speed)
|
16
16
|
assert_raise(ArgumentError){@ie1.speed = :fubar}
|
17
|
-
end
|
18
|
-
|
17
|
+
end
|
18
|
+
|
19
19
|
def teardown
|
20
20
|
@ie1.close if @ie1
|
21
21
|
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class TC_class_options < Test::Unit::TestCase
|
25
|
+
include Watir
|
26
|
+
@@hide_ie = $HIDE_IE
|
27
|
+
def setup
|
28
|
+
@previous = Watir::IE.defaults
|
29
|
+
end
|
30
|
+
def test_class_defaults
|
31
|
+
assert_equal({:speed => :slow, :visible => ! @@hide_ie}, IE.defaults)
|
32
|
+
end
|
33
|
+
def test_change_defaults
|
34
|
+
IE.defaults = {:speed => :fast}
|
35
|
+
assert_equal(:fast, IE.speed)
|
36
|
+
IE.defaults = {:visible => false}
|
37
|
+
assert_equal(false, IE.visible)
|
38
|
+
IE.defaults = {:speed => :slow}
|
39
|
+
assert_equal(:slow, IE.speed)
|
40
|
+
IE.defaults = {:visible => true}
|
41
|
+
assert_equal(true, IE.visible)
|
42
|
+
end
|
43
|
+
def test_defaults_affect_on_instance
|
44
|
+
IE.defaults = {:speed => :fast}
|
45
|
+
@ie1 = IE.new
|
46
|
+
assert_equal(:fast, @ie1.speed)
|
47
|
+
IE.defaults = {:speed => :slow}
|
48
|
+
@ie2 = IE.new
|
49
|
+
assert_equal(:slow, @ie2.speed)
|
50
|
+
end
|
51
|
+
def teardown
|
52
|
+
IE.defaults = @previous
|
53
|
+
@ie1.close if @ie1
|
54
|
+
@ie2.close if @ie2
|
55
|
+
end
|
22
56
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
|
2
|
+
require 'unittests/setup'
|
3
|
+
|
4
|
+
class TC_Fields_For_Chinese_Char < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup()
|
7
|
+
$ie.goto($htmlRoot + "textfields1.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_chinese_char_should_be_appended_to_text_field
|
11
|
+
$ie.text_field(:name, "text1").append(" ijij")
|
12
|
+
assert_equal( "Hello World ijij" , $ie.text_field(:name, "text1").getContents )
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_mixed_char_should_be_appended_to_text_field
|
16
|
+
$ie.text_field(:name, "text1").append(" ijaija")
|
17
|
+
assert_equal( "Hello World ijaija" , $ie.text_field(:name, "text1").getContents )
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_chinese_char_should_be_set_to_text_field
|
21
|
+
$ie.text_field(:name, "text1").set("ijij")
|
22
|
+
assert_equal( "ijij" , $ie.text_field(:name, "text1").getContents )
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_mixed_char_should_be_set_to_text_field
|
26
|
+
$ie.text_field(:name, "text1").set("ijaija")
|
27
|
+
assert_equal( "ijaija" , $ie.text_field(:name, "text1").getContents )
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# feature tests for Text Fields & Labels
|
2
|
-
# revision: $Revision:
|
2
|
+
# revision: $Revision: 1295 $
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
|
5
5
|
require 'unittests/setup'
|
@@ -151,12 +151,12 @@ class TC_Fields < Test::Unit::TestCase
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def test_JS_Events
|
154
|
-
$ie.text_field(:name, 'events_tester').set('p')
|
154
|
+
$ie.text_field(:name, 'events_tester').requires_typing.set('p')
|
155
155
|
|
156
156
|
# the following line has an extra keypress at the begining, as we mimic the delete key being pressed
|
157
157
|
assert_equal( "keypresskeydownkeypresskeyup" , $ie.text_field(:name , 'events_text').value.gsub("\r\n" , "") )
|
158
158
|
$ie.button(:value , "Clear Events Box").click
|
159
|
-
$ie.text_field(:name , 'events_tester').set('ab')
|
159
|
+
$ie.text_field(:name , 'events_tester').requires_typing.set('ab')
|
160
160
|
|
161
161
|
# the following line has an extra keypress at the begining, as we mimic the delete key being pressed
|
162
162
|
assert_equal( "keypresskeydownkeypresskeyupkeydownkeypresskeyup" , $ie.text_field(:name , 'events_text').value.gsub("\r\n" , "") )
|
data/watir/assertions.rb
CHANGED
@@ -10,7 +10,7 @@ module Watir
|
|
10
10
|
# Whether true or false, the assertion count is incremented.
|
11
11
|
def verify boolean, message = 'verify failed.'
|
12
12
|
add_assertion
|
13
|
-
add_failure message, caller unless boolean
|
13
|
+
add_failure message.to_s, caller unless boolean
|
14
14
|
end
|
15
15
|
|
16
16
|
def verify_equal expected, actual, message=nil
|
data/watir/close_all.rb
CHANGED
@@ -14,7 +14,7 @@ module Watir
|
|
14
14
|
def self.close_all_but(except=nil)
|
15
15
|
Watir::IE.each do |ie|
|
16
16
|
ie.close_modal
|
17
|
-
ie.close unless except and except.hwnd ==
|
17
|
+
ie.close unless except and except.hwnd == ie.hwnd
|
18
18
|
end
|
19
19
|
sleep 1.0 # replace with polling for window count to be zero?
|
20
20
|
end
|
data/watir/container.rb
CHANGED
@@ -25,6 +25,7 @@ module Watir
|
|
25
25
|
|
26
26
|
# This is used to change the typing speed when entering text on a page.
|
27
27
|
attr_accessor :typingspeed
|
28
|
+
attr_accessor :type_keys
|
28
29
|
# The color we want to use for the active object. This can be any valid web-friendly color.
|
29
30
|
attr_accessor :activeObjectHighLightColor
|
30
31
|
# The PageContainer object containing this element
|
@@ -32,6 +33,7 @@ module Watir
|
|
32
33
|
|
33
34
|
def copy_test_config(container) # only used by form and frame
|
34
35
|
@typingspeed = container.typingspeed
|
36
|
+
@type_keys = container.type_keys
|
35
37
|
@activeObjectHighLightColor = container.activeObjectHighLightColor
|
36
38
|
end
|
37
39
|
private :copy_test_config
|
@@ -813,63 +815,12 @@ module Watir
|
|
813
815
|
# * types - what object types we will look at.
|
814
816
|
# * value - used for objects that have one name, but many values. ex. radio lists and checkboxes
|
815
817
|
def locate_input_element(how, what, types, value=nil)
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
# where the :name matches, so we will only return the results of
|
823
|
-
# getElementById() if the matching element actually HAS a matching
|
824
|
-
# :id.
|
825
|
-
begin
|
826
|
-
if what.class == String # Only use fast calls with String what.
|
827
|
-
if how == :id
|
828
|
-
element = document.getElementById(what)
|
829
|
-
# Return if our fast match really HAS a matching :id
|
830
|
-
return element if element.nil? or element.invoke('id') == what
|
831
|
-
elsif how == :name
|
832
|
-
elements = document.getElementsByName(what)
|
833
|
-
end
|
834
|
-
end
|
835
|
-
rescue
|
836
|
-
end
|
837
|
-
# Use slow methods if the faster methods didn't match
|
838
|
-
elements = ole_inner_elements if elements.nil?
|
839
|
-
|
840
|
-
how = :value if how == :caption
|
841
|
-
how = :class_name if how == :class
|
842
|
-
what = what.to_i if how == :index
|
843
|
-
value = value.to_s if value
|
844
|
-
log "getting object - how is #{how} what is #{what} types = #{types} value = #{value}"
|
845
|
-
|
846
|
-
object_index = 1
|
847
|
-
elements.each do |object|
|
848
|
-
element = Element.new(object)
|
849
|
-
if types.include?(element.type)
|
850
|
-
if how == :index
|
851
|
-
attribute = object_index
|
852
|
-
else
|
853
|
-
begin
|
854
|
-
attribute = element.send(how)
|
855
|
-
rescue NoMethodError
|
856
|
-
raise MissingWayOfFindingObjectException,
|
857
|
-
"#{how} is an unknown way of finding an <INPUT> element (#{what})"
|
858
|
-
end
|
859
|
-
end
|
860
|
-
if what.matches(attribute)
|
861
|
-
if value
|
862
|
-
if element.value == value
|
863
|
-
return object
|
864
|
-
end
|
865
|
-
else
|
866
|
-
return object
|
867
|
-
end
|
868
|
-
end
|
869
|
-
object_index += 1
|
870
|
-
end
|
871
|
-
end
|
872
|
-
return nil
|
818
|
+
locator = InputElementLocator.new self, types
|
819
|
+
locator.document = document rescue true
|
820
|
+
return locator.element if locator.fast_locate
|
821
|
+
locator.elements = ole_inner_elements if locator.elements.nil?
|
822
|
+
locator.specifier = [how, what, value]
|
823
|
+
locator.locate
|
873
824
|
end
|
874
825
|
|
875
826
|
# returns the ole object for the specified element
|
data/watir/element.rb
CHANGED
@@ -147,7 +147,10 @@ module Watir
|
|
147
147
|
def typingspeed
|
148
148
|
@container.typingspeed
|
149
149
|
end
|
150
|
-
|
150
|
+
def type_keys
|
151
|
+
return @container.type_keys if @type_keys.nil?
|
152
|
+
@type_keys
|
153
|
+
end
|
151
154
|
def activeObjectHighLightColor
|
152
155
|
@container.activeObjectHighLightColor
|
153
156
|
end
|
data/watir/ie.rb
CHANGED
@@ -18,27 +18,51 @@ module Watir
|
|
18
18
|
def self.attach_timeout=(timeout)
|
19
19
|
@@attach_timeout = timeout
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
|
+
def self.defaults
|
23
|
+
{:speed => self.speed, :visible => self.visible}
|
24
|
+
end
|
25
|
+
def self.defaults= options
|
26
|
+
options.each do |name, value|
|
27
|
+
send "#{name}=", value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
# The globals $FAST_SPEED and $HIDE_IE are checked both at initialization
|
31
|
+
# and later, because they
|
32
|
+
# might be set after initialization. Setting them beforehand (e.g. from
|
33
|
+
# the command line) will affect the class, otherwise it is only a temporary
|
34
|
+
# effect
|
35
|
+
@@speed = $FAST_SPEED ? :fast : :slow
|
36
|
+
def self.speed
|
37
|
+
return :fast if $FAST_SPEED
|
38
|
+
@@speed
|
39
|
+
end
|
40
|
+
def self.speed= x
|
41
|
+
$FAST_SPEED = nil
|
42
|
+
@@speed = x
|
43
|
+
end
|
44
|
+
@@visible = $HIDE_IE ? false : true
|
45
|
+
def self.visible
|
46
|
+
return false if $HIDE_IE
|
47
|
+
@@visible
|
48
|
+
end
|
49
|
+
def self.visible= x
|
50
|
+
$HIDE_IE = nil
|
51
|
+
@@visible = x
|
52
|
+
end
|
53
|
+
|
22
54
|
# The revision number (according to Subversion)
|
23
55
|
REVISION_STRING = '$Revision: 1263 $'
|
24
56
|
REVISION_STRING.scan(/Revision: (\d*)/)
|
25
57
|
REVISION = $1 or 'unknown'
|
26
58
|
|
27
59
|
# The Release number
|
28
|
-
VERSION_SHORT = '1.5.
|
60
|
+
VERSION_SHORT = '1.5.4'
|
29
61
|
VERSION = VERSION_SHORT + '.' + REVISION
|
30
62
|
|
31
63
|
# Used internally to determine when IE has finished loading a page
|
32
64
|
READYSTATE_COMPLETE = 4
|
33
|
-
|
34
|
-
# TODO: the following constants should be able to be specified by object (not class)
|
35
|
-
|
36
|
-
# The delay when entering text on a web page when speed = :slow.
|
37
|
-
DEFAULT_TYPING_SPEED = 0.08
|
38
|
-
|
39
|
-
# The default time we wait after a page has loaded when speed = :slow.
|
40
|
-
DEFAULT_SLEEP_TIME = 0.1
|
41
|
-
|
65
|
+
|
42
66
|
# The default color for highlighting objects as they are accessed.
|
43
67
|
HIGHLIGHT_COLOR = 'yellow'
|
44
68
|
|
@@ -77,7 +101,7 @@ module Watir
|
|
77
101
|
|
78
102
|
def _new_window_init
|
79
103
|
create_browser_window
|
80
|
-
|
104
|
+
initialize_options
|
81
105
|
goto 'about:blank' # this avoids numerous problems caused by lack of a document
|
82
106
|
end
|
83
107
|
|
@@ -108,7 +132,7 @@ module Watir
|
|
108
132
|
iep = Process.start
|
109
133
|
@ie = iep.window
|
110
134
|
@process_id = iep.process_id
|
111
|
-
|
135
|
+
initialize_options
|
112
136
|
goto 'about:blank'
|
113
137
|
end
|
114
138
|
|
@@ -138,7 +162,7 @@ module Watir
|
|
138
162
|
# this method is used internally to attach to an existing window
|
139
163
|
def _attach_init how, what
|
140
164
|
attach_browser_window how, what
|
141
|
-
|
165
|
+
initialize_options
|
142
166
|
wait
|
143
167
|
end
|
144
168
|
|
@@ -147,7 +171,7 @@ module Watir
|
|
147
171
|
def self.bind window
|
148
172
|
ie = new true
|
149
173
|
ie.ie = window
|
150
|
-
ie.
|
174
|
+
ie.initialize_options
|
151
175
|
ie
|
152
176
|
end
|
153
177
|
|
@@ -156,18 +180,15 @@ module Watir
|
|
156
180
|
end
|
157
181
|
private :create_browser_window
|
158
182
|
|
159
|
-
def
|
160
|
-
self.visible =
|
183
|
+
def initialize_options
|
184
|
+
self.visible = IE.visible
|
185
|
+
self.speed = IE.speed
|
186
|
+
|
161
187
|
@ole_object = nil
|
162
188
|
@page_container = self
|
163
189
|
@error_checkers = []
|
164
190
|
@activeObjectHighLightColor = HIGHLIGHT_COLOR
|
165
191
|
|
166
|
-
if $FAST_SPEED
|
167
|
-
set_fast_speed
|
168
|
-
else
|
169
|
-
set_slow_speed
|
170
|
-
end
|
171
192
|
|
172
193
|
@logger = DefaultLogger.new
|
173
194
|
@url_list = []
|
@@ -175,8 +196,21 @@ module Watir
|
|
175
196
|
|
176
197
|
def speed= how_fast
|
177
198
|
case how_fast
|
178
|
-
when :
|
179
|
-
|
199
|
+
when :zippy :
|
200
|
+
@typingspeed = 0
|
201
|
+
@pause_after_wait = 0.01
|
202
|
+
@type_keys = false
|
203
|
+
@speed = :fast
|
204
|
+
when :fast :
|
205
|
+
@typingspeed = 0
|
206
|
+
@pause_after_wait = 0.01
|
207
|
+
@type_keys = true
|
208
|
+
@speed = :fast
|
209
|
+
when :slow :
|
210
|
+
@typingspeed = 0.08
|
211
|
+
@pause_after_wait = 0.1
|
212
|
+
@type_keys = true
|
213
|
+
@speed = :slow
|
180
214
|
else
|
181
215
|
raise ArgumentError, "Invalid speed: #{how_fast}"
|
182
216
|
end
|
@@ -184,16 +218,12 @@ module Watir
|
|
184
218
|
|
185
219
|
# deprecated: use speed = :fast instead
|
186
220
|
def set_fast_speed
|
187
|
-
|
188
|
-
@defaultSleepTime = 0.01
|
189
|
-
@speed = :fast
|
221
|
+
self.speed = :fast
|
190
222
|
end
|
191
223
|
|
192
224
|
# deprecated: use speed = :slow instead
|
193
225
|
def set_slow_speed
|
194
|
-
|
195
|
-
@defaultSleepTime = DEFAULT_SLEEP_TIME
|
196
|
-
@speed = :slow
|
226
|
+
self.speed = :slow
|
197
227
|
end
|
198
228
|
|
199
229
|
def visible
|
@@ -453,7 +483,7 @@ module Watir
|
|
453
483
|
|
454
484
|
rescue WIN32OLERuntimeError # IE window must have been closed
|
455
485
|
@down_load_time = Time.now - start_load_time
|
456
|
-
sleep @
|
486
|
+
sleep @pause_after_wait unless no_sleep
|
457
487
|
return @down_load_time
|
458
488
|
end
|
459
489
|
|
@@ -475,7 +505,7 @@ module Watir
|
|
475
505
|
|
476
506
|
@down_load_time = Time.now - start_load_time
|
477
507
|
run_error_checks
|
478
|
-
sleep @
|
508
|
+
sleep @pause_after_wait unless no_sleep
|
479
509
|
@down_load_time
|
480
510
|
end
|
481
511
|
|
data/watir/input_elements.rb
CHANGED
@@ -17,6 +17,10 @@ module Watir
|
|
17
17
|
super(nil)
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Input: Select
|
23
|
+
#
|
20
24
|
|
21
25
|
# This class is the way in which select boxes are manipulated.
|
22
26
|
# Normally a user would not need to create this object as it is returned by the Watir::Container#select_list method
|
@@ -26,6 +30,7 @@ module Watir
|
|
26
30
|
attr_accessor :o
|
27
31
|
|
28
32
|
# This method clears the selected items in the select box
|
33
|
+
# TODO: fix Camel case
|
29
34
|
def clearSelection
|
30
35
|
assert_exists
|
31
36
|
highlight(:set)
|
@@ -99,7 +104,7 @@ module Watir
|
|
99
104
|
|
100
105
|
# Returns the selected items as an array.
|
101
106
|
# Raises UnknownObjectException if the select box is not found.
|
102
|
-
def getSelectedItems
|
107
|
+
def getSelectedItems # TODO: fix camel case
|
103
108
|
assert_exists
|
104
109
|
returnArray = []
|
105
110
|
@container.log "There are #{@o.length} items"
|
@@ -185,12 +190,18 @@ module Watir
|
|
185
190
|
end
|
186
191
|
end
|
187
192
|
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
193
|
+
#
|
194
|
+
# Input: Button
|
195
|
+
#
|
196
|
+
|
197
|
+
# Returned by the Watir::Container#button method
|
191
198
|
class Button < InputElement
|
192
199
|
INPUT_TYPES = ["button", "submit", "image", "reset"]
|
193
200
|
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Input: Text
|
204
|
+
#
|
194
205
|
|
195
206
|
# This class is the main class for Text Fields
|
196
207
|
# Normally a user would not need to create this object as it is returned by the Watir::Container#text_field method
|
@@ -203,23 +214,21 @@ module Watir
|
|
203
214
|
assert_exists
|
204
215
|
begin
|
205
216
|
ole_object.invoke('maxlength').to_i
|
206
|
-
rescue
|
217
|
+
rescue WIN32OLERuntimeError
|
207
218
|
0
|
208
219
|
end
|
209
220
|
end
|
210
|
-
|
211
|
-
|
221
|
+
|
212
222
|
# Returns true or false if the text field is read only.
|
213
223
|
# Raises UnknownObjectException if the object can't be found.
|
214
224
|
def_wrap :readonly?, :readOnly
|
215
225
|
|
216
226
|
def text_string_creator
|
217
227
|
n = []
|
218
|
-
n <<
|
219
|
-
n <<
|
220
|
-
n <<
|
221
|
-
|
222
|
-
return n
|
228
|
+
n << "length:".ljust(TO_S_SIZE) + self.size.to_s
|
229
|
+
n << "max length:".ljust(TO_S_SIZE) + self.maxlength.to_s
|
230
|
+
n << "read only:".ljust(TO_S_SIZE) + self.readonly?.to_s
|
231
|
+
n
|
223
232
|
end
|
224
233
|
private :text_string_creator
|
225
234
|
|
@@ -227,28 +236,30 @@ module Watir
|
|
227
236
|
assert_exists
|
228
237
|
r = string_creator
|
229
238
|
r += text_string_creator
|
230
|
-
|
239
|
+
r.join("\n")
|
231
240
|
end
|
232
241
|
|
233
242
|
def assert_not_readonly
|
234
|
-
|
243
|
+
if self.readonly?
|
244
|
+
raise ObjectReadOnlyException,
|
245
|
+
"Textfield #{@how} and #{@what} is read only."
|
246
|
+
end
|
235
247
|
end
|
236
248
|
|
237
|
-
#
|
238
|
-
#
|
249
|
+
# Returns true if the text field contents is matches the specified target,
|
250
|
+
# which can be either a string or a regular expression.
|
239
251
|
# Raises UnknownObjectException if the object can't be found
|
240
|
-
#
|
241
|
-
def verify_contains(containsThis) # FIXME: verify_contains should have same name and semantics as IE#contains_text (prolly make this work for all elements)
|
252
|
+
def verify_contains(target) # FIXME: verify_contains should have same name and semantics as IE#contains_text (prolly make this work for all elements)
|
242
253
|
assert_exists
|
243
|
-
if
|
244
|
-
return true if self.value ==
|
245
|
-
elsif
|
246
|
-
return true if self.value.match(
|
254
|
+
if target.kind_of? String
|
255
|
+
return true if self.value == target
|
256
|
+
elsif target.kind_of? Regexp
|
257
|
+
return true if self.value.match(target) != nil
|
247
258
|
end
|
248
259
|
return false
|
249
260
|
end
|
250
261
|
|
251
|
-
#
|
262
|
+
# Drag the entire contents of the text field to another text field
|
252
263
|
# 19 Jan 2005 - It is added as prototype functionality, and may change
|
253
264
|
# * destination_how - symbol, :id, :name how we identify the drop target
|
254
265
|
# * destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target
|
@@ -273,7 +284,7 @@ module Watir
|
|
273
284
|
self.value = ""
|
274
285
|
end
|
275
286
|
|
276
|
-
#
|
287
|
+
# Clears the contents of the text box.
|
277
288
|
# Raises UnknownObjectException if the object can't be found
|
278
289
|
# Raises ObjectDisabledException if the object is disabled
|
279
290
|
# Raises ObjectReadOnlyException if the object is read only
|
@@ -294,61 +305,73 @@ module Watir
|
|
294
305
|
highlight(:clear)
|
295
306
|
end
|
296
307
|
|
297
|
-
#
|
308
|
+
# Appends the specified string value to the contents of the text box.
|
298
309
|
# Raises UnknownObjectException if the object cant be found
|
299
310
|
# Raises ObjectDisabledException if the object is disabled
|
300
311
|
# Raises ObjectReadOnlyException if the object is read only
|
301
|
-
|
302
|
-
def append(setThis)
|
312
|
+
def append(value)
|
303
313
|
assert_enabled
|
304
314
|
assert_not_readonly
|
305
315
|
|
306
316
|
highlight(:set)
|
307
317
|
@o.scrollIntoView
|
308
318
|
@o.focus
|
309
|
-
|
319
|
+
type_by_character(value)
|
310
320
|
highlight(:clear)
|
311
321
|
end
|
312
322
|
|
313
|
-
#
|
323
|
+
# Sets the contents of the text box to the specified text value
|
314
324
|
# Raises UnknownObjectException if the object cant be found
|
315
325
|
# Raises ObjectDisabledException if the object is disabled
|
316
326
|
# Raises ObjectReadOnlyException if the object is read only
|
317
|
-
|
318
|
-
def set(setThis)
|
327
|
+
def set(value)
|
319
328
|
assert_enabled
|
320
329
|
assert_not_readonly
|
321
330
|
|
322
331
|
highlight(:set)
|
323
332
|
@o.scrollIntoView
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
333
|
+
if type_keys
|
334
|
+
@o.focus
|
335
|
+
@o.select
|
336
|
+
@o.fireEvent("onSelect")
|
337
|
+
@o.fireEvent("onKeyPress")
|
338
|
+
@o.value = ""
|
339
|
+
type_by_character(value)
|
340
|
+
@o.fireEvent("onChange")
|
341
|
+
@o.fireEvent("onBlur")
|
342
|
+
else
|
343
|
+
@o.value = limit_to_maxlength(value)
|
344
|
+
end
|
330
345
|
highlight(:clear)
|
331
|
-
@o.fireEvent("onChange")
|
332
|
-
@o.fireEvent("onBlur")
|
333
346
|
end
|
334
347
|
|
335
|
-
#
|
336
|
-
#
|
348
|
+
# Sets the value of the text field directly.
|
349
|
+
# It causes no events to be fired or exceptions to be raised,
|
350
|
+
# so generally shouldn't be used.
|
351
|
+
# It is preffered to use the set method.
|
337
352
|
def value=(v)
|
338
353
|
assert_exists
|
339
354
|
@o.value = v.to_s
|
340
355
|
end
|
341
356
|
|
357
|
+
def requires_typing
|
358
|
+
@type_keys = true
|
359
|
+
self
|
360
|
+
end
|
361
|
+
def abhors_typing
|
362
|
+
@type_keys = false
|
363
|
+
self
|
364
|
+
end
|
365
|
+
|
342
366
|
private
|
343
367
|
|
344
|
-
#
|
368
|
+
# Type the characters in the specified string (value) one by one.
|
345
369
|
# It should not be used externally.
|
346
370
|
# * value - string - The string to enter into the text field
|
347
|
-
def
|
371
|
+
def type_by_character(value)
|
348
372
|
value = limit_to_maxlength(value)
|
349
|
-
|
373
|
+
characters_in(value) do |c|
|
350
374
|
sleep @container.typingspeed
|
351
|
-
c = value[i,1]
|
352
375
|
@o.value = @o.value.to_s + c
|
353
376
|
@o.fireEvent("onKeyDown")
|
354
377
|
@o.fireEvent("onKeyPress")
|
@@ -356,6 +379,16 @@ module Watir
|
|
356
379
|
end
|
357
380
|
end
|
358
381
|
|
382
|
+
# Supports double-byte characters
|
383
|
+
def characters_in(value)
|
384
|
+
index = 0
|
385
|
+
while index < value.length
|
386
|
+
len = value[index] > 128 ? 2 : 1
|
387
|
+
yield value[index, len]
|
388
|
+
index += len
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
359
392
|
# Return the value (a string), limited to the maxlength of the element.
|
360
393
|
def limit_to_maxlength(value)
|
361
394
|
return value if @o.invoke('type') =~ /textarea/i # text areas don't have maxlength
|
@@ -393,7 +426,7 @@ module Watir
|
|
393
426
|
|
394
427
|
end
|
395
428
|
|
396
|
-
#
|
429
|
+
# For fields that accept file uploads
|
397
430
|
# Windows dialog is opened and handled in this case by autoit
|
398
431
|
# launching into a new process.
|
399
432
|
class FileField < InputElement
|
data/watir/locator.rb
CHANGED
@@ -76,4 +76,73 @@ module Watir
|
|
76
76
|
end
|
77
77
|
|
78
78
|
end
|
79
|
+
class InputElementLocator
|
80
|
+
attr_accessor :document, :element, :elements
|
81
|
+
def initialize container, types
|
82
|
+
@container = container
|
83
|
+
@types = types
|
84
|
+
@elements = nil
|
85
|
+
end
|
86
|
+
def specifier= arg
|
87
|
+
how, what, value = arg
|
88
|
+
how = :value if how == :caption
|
89
|
+
how = :class_name if how == :class
|
90
|
+
what = what.to_i if how == :index
|
91
|
+
value = value.to_s if value
|
92
|
+
@how = how
|
93
|
+
@what = what
|
94
|
+
@value = value
|
95
|
+
end
|
96
|
+
def locate
|
97
|
+
object_index = 1
|
98
|
+
@elements.each do |object|
|
99
|
+
element = Element.new(object)
|
100
|
+
if @types.include?(element.type)
|
101
|
+
if @how == :index
|
102
|
+
attribute = object_index
|
103
|
+
else
|
104
|
+
begin
|
105
|
+
attribute = element.send(@how)
|
106
|
+
rescue NoMethodError
|
107
|
+
raise MissingWayOfFindingObjectException,
|
108
|
+
"#{@how} is an unknown way of finding an <INPUT> element (#{@what})"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
if @what.matches(attribute)
|
112
|
+
if @value
|
113
|
+
if element.value == @value
|
114
|
+
return object
|
115
|
+
end
|
116
|
+
else
|
117
|
+
return object
|
118
|
+
end
|
119
|
+
end
|
120
|
+
object_index += 1
|
121
|
+
end
|
122
|
+
end
|
123
|
+
return nil
|
124
|
+
end
|
125
|
+
def fast_locate
|
126
|
+
# Searching through all elements returned by ole_inner_elements
|
127
|
+
# is *significantly* slower than IE's getElementById() and
|
128
|
+
# getElementsByName() calls when how is :id or :name. However
|
129
|
+
# IE doesn't match Regexps, so first we make sure what is a String.
|
130
|
+
# In addition, IE's getElementById() will also return an element
|
131
|
+
# where the :name matches, so we will only return the results of
|
132
|
+
# getElementById() if the matching element actually HAS a matching
|
133
|
+
# :id.
|
134
|
+
begin
|
135
|
+
if @what.class == String # Only use fast calls with String what.
|
136
|
+
if @how == :id
|
137
|
+
@element = @document.getElementById(what)
|
138
|
+
# Return if our fast match really HAS a matching :id
|
139
|
+
return @element if @element.nil? or @element.invoke('id') == what
|
140
|
+
elsif how == :name
|
141
|
+
@elements = @document.getElementsByName(what)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
rescue
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
79
148
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: watir
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.5.
|
7
|
-
date:
|
6
|
+
version: 1.5.4
|
7
|
+
date: 2008-04-23 00:00:00 -05:00
|
8
8
|
summary: Automated testing tool for web applications.
|
9
9
|
require_paths:
|
10
10
|
- .
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- unittests/textarea_xpath_test.rb
|
125
125
|
- unittests/textfields_test.rb
|
126
126
|
- unittests/textfields_xpath_test.rb
|
127
|
+
- unittests/textfield_for_ch_char_test.rb
|
127
128
|
- unittests/window_tests.rb
|
128
129
|
- unittests/xpath_tests.rb
|
129
130
|
- unittests/html/blankpage.html
|
@@ -249,3 +250,12 @@ dependencies:
|
|
249
250
|
- !ruby/object:Gem::Version
|
250
251
|
version: 0.5.1
|
251
252
|
version:
|
253
|
+
- !ruby/object:Gem::Dependency
|
254
|
+
name: windows-pr
|
255
|
+
version_requirement:
|
256
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
257
|
+
requirements:
|
258
|
+
- - ">="
|
259
|
+
- !ruby/object:Gem::Version
|
260
|
+
version: 0.6.6
|
261
|
+
version:
|