watir 6.0.0.beta5 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/CHANGES.md +10 -1
- data/Gemfile +4 -0
- data/README.md +37 -23
- data/Rakefile +6 -10
- data/appveyor.yml +13 -0
- data/lib/watir.rb +20 -21
- data/lib/watir/alert.rb +21 -5
- data/lib/watir/browser.rb +9 -3
- data/lib/watir/elements/checkbox.rb +0 -1
- data/lib/watir/elements/element.rb +92 -50
- data/lib/watir/elements/form.rb +1 -2
- data/lib/watir/elements/iframe.rb +6 -2
- data/lib/watir/elements/image.rb +1 -1
- data/lib/watir/elements/option.rb +0 -1
- data/lib/watir/elements/radio.rb +0 -1
- data/lib/watir/elements/select.rb +1 -10
- data/lib/watir/extensions/select_text.rb +1 -1
- data/lib/watir/legacy_wait.rb +126 -0
- data/lib/watir/locators/text_field/locator.rb +0 -3
- data/lib/watir/locators/text_field/selector_builder.rb +1 -4
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +0 -2
- data/lib/watir/locators/text_field/validator.rb +1 -9
- data/lib/watir/row_container.rb +1 -1
- data/lib/watir/user_editable.rb +7 -5
- data/lib/watir/wait.rb +56 -135
- data/lib/watir/wait/timer.rb +29 -2
- data/lib/watir/window.rb +11 -1
- data/lib/watirspec.rb +81 -0
- data/lib/watirspec/guards.rb +58 -0
- data/lib/watirspec/implementation.rb +33 -0
- data/lib/watirspec/rake_tasks.rb +115 -0
- data/lib/watirspec/runner.rb +53 -0
- data/lib/watirspec/server.rb +99 -0
- data/lib/watirspec/server/app.rb +62 -0
- data/spec/browser_spec.rb +5 -5
- data/spec/click_spec.rb +1 -1
- data/spec/container_spec.rb +1 -1
- data/spec/element_locator_spec.rb +1 -1
- data/spec/element_spec.rb +20 -34
- data/spec/implementation_spec.rb +24 -0
- data/spec/input_spec.rb +1 -1
- data/spec/spec_helper.rb +35 -3
- data/spec/special_chars_spec.rb +1 -1
- data/spec/watirspec/.gitignore +2 -0
- data/spec/watirspec/after_hooks_spec.rb +179 -0
- data/spec/watirspec/alert_spec.rb +101 -0
- data/spec/watirspec/browser_spec.rb +291 -0
- data/spec/watirspec/cookies_spec.rb +147 -0
- data/spec/watirspec/drag_and_drop_spec.rb +49 -0
- data/spec/watirspec/element_hidden_spec.rb +65 -0
- data/spec/watirspec/elements/area_spec.rb +76 -0
- data/spec/watirspec/elements/areas_spec.rb +42 -0
- data/spec/watirspec/elements/button_spec.rb +270 -0
- data/spec/watirspec/elements/buttons_spec.rb +55 -0
- data/spec/watirspec/elements/checkbox_spec.rb +279 -0
- data/spec/watirspec/elements/checkboxes_spec.rb +44 -0
- data/spec/watirspec/elements/collections_spec.rb +16 -0
- data/spec/watirspec/elements/dd_spec.rb +126 -0
- data/spec/watirspec/elements/dds_spec.rb +42 -0
- data/spec/watirspec/elements/del_spec.rb +128 -0
- data/spec/watirspec/elements/dels_spec.rb +40 -0
- data/spec/watirspec/elements/div_spec.rb +199 -0
- data/spec/watirspec/elements/divs_spec.rb +42 -0
- data/spec/watirspec/elements/dl_spec.rb +144 -0
- data/spec/watirspec/elements/dls_spec.rb +43 -0
- data/spec/watirspec/elements/dt_spec.rb +126 -0
- data/spec/watirspec/elements/dts_spec.rb +42 -0
- data/spec/watirspec/elements/element_spec.rb +361 -0
- data/spec/watirspec/elements/elements_spec.rb +15 -0
- data/spec/watirspec/elements/em_spec.rb +100 -0
- data/spec/watirspec/elements/ems_spec.rb +43 -0
- data/spec/watirspec/elements/filefield_spec.rb +181 -0
- data/spec/watirspec/elements/filefields_spec.rb +43 -0
- data/spec/watirspec/elements/font_spec.rb +29 -0
- data/spec/watirspec/elements/form_spec.rb +70 -0
- data/spec/watirspec/elements/forms_spec.rb +44 -0
- data/spec/watirspec/elements/frame_spec.rb +121 -0
- data/spec/watirspec/elements/frames_spec.rb +41 -0
- data/spec/watirspec/elements/hidden_spec.rb +102 -0
- data/spec/watirspec/elements/hiddens_spec.rb +43 -0
- data/spec/watirspec/elements/hn_spec.rb +96 -0
- data/spec/watirspec/elements/hns_spec.rb +38 -0
- data/spec/watirspec/elements/iframe_spec.rb +174 -0
- data/spec/watirspec/elements/iframes_spec.rb +47 -0
- data/spec/watirspec/elements/image_spec.rb +164 -0
- data/spec/watirspec/elements/images_spec.rb +40 -0
- data/spec/watirspec/elements/ins_spec.rb +129 -0
- data/spec/watirspec/elements/inses_spec.rb +40 -0
- data/spec/watirspec/elements/label_spec.rb +79 -0
- data/spec/watirspec/elements/labels_spec.rb +40 -0
- data/spec/watirspec/elements/li_spec.rb +115 -0
- data/spec/watirspec/elements/link_spec.rb +174 -0
- data/spec/watirspec/elements/links_spec.rb +44 -0
- data/spec/watirspec/elements/lis_spec.rb +42 -0
- data/spec/watirspec/elements/map_spec.rb +79 -0
- data/spec/watirspec/elements/maps_spec.rb +41 -0
- data/spec/watirspec/elements/meta_spec.rb +23 -0
- data/spec/watirspec/elements/metas_spec.rb +40 -0
- data/spec/watirspec/elements/ol_spec.rb +89 -0
- data/spec/watirspec/elements/ols_spec.rb +40 -0
- data/spec/watirspec/elements/option_spec.rb +152 -0
- data/spec/watirspec/elements/p_spec.rb +115 -0
- data/spec/watirspec/elements/pre_spec.rb +115 -0
- data/spec/watirspec/elements/pres_spec.rb +40 -0
- data/spec/watirspec/elements/ps_spec.rb +40 -0
- data/spec/watirspec/elements/radio_spec.rb +263 -0
- data/spec/watirspec/elements/radios_spec.rb +43 -0
- data/spec/watirspec/elements/select_list_spec.rb +379 -0
- data/spec/watirspec/elements/select_lists_spec.rb +46 -0
- data/spec/watirspec/elements/span_spec.rb +129 -0
- data/spec/watirspec/elements/spans_spec.rb +40 -0
- data/spec/watirspec/elements/strong_spec.rb +92 -0
- data/spec/watirspec/elements/strongs_spec.rb +43 -0
- data/spec/watirspec/elements/table_nesting_spec.rb +51 -0
- data/spec/watirspec/elements/table_spec.rb +146 -0
- data/spec/watirspec/elements/tables_spec.rb +42 -0
- data/spec/watirspec/elements/tbody_spec.rb +96 -0
- data/spec/watirspec/elements/tbodys_spec.rb +62 -0
- data/spec/watirspec/elements/td_spec.rb +71 -0
- data/spec/watirspec/elements/tds_spec.rb +53 -0
- data/spec/watirspec/elements/text_field_spec.rb +302 -0
- data/spec/watirspec/elements/text_fields_spec.rb +44 -0
- data/spec/watirspec/elements/textarea_spec.rb +26 -0
- data/spec/watirspec/elements/textareas_spec.rb +24 -0
- data/spec/watirspec/elements/tfoot_spec.rb +91 -0
- data/spec/watirspec/elements/tfoots_spec.rb +68 -0
- data/spec/watirspec/elements/thead_spec.rb +91 -0
- data/spec/watirspec/elements/theads_spec.rb +68 -0
- data/spec/watirspec/elements/tr_spec.rb +80 -0
- data/spec/watirspec/elements/trs_spec.rb +61 -0
- data/spec/watirspec/elements/ul_spec.rb +79 -0
- data/spec/watirspec/elements/uls_spec.rb +39 -0
- data/spec/watirspec/html/alerts.html +12 -0
- data/spec/watirspec/html/aria_attributes.html +9 -0
- data/spec/watirspec/html/class_locator.html +8 -0
- data/spec/watirspec/html/clicks.html +19 -0
- data/spec/watirspec/html/closeable.html +13 -0
- data/spec/watirspec/html/collections.html +15 -0
- data/spec/watirspec/html/css/jquery-ui-1.8.17.custom.css +287 -0
- data/spec/watirspec/html/data_attributes.html +9 -0
- data/spec/watirspec/html/definition_lists.html +48 -0
- data/spec/watirspec/html/drag_and_drop.html +106 -0
- data/spec/watirspec/html/font.html +10 -0
- data/spec/watirspec/html/forms_with_input_elements.html +170 -0
- data/spec/watirspec/html/frame_1.html +22 -0
- data/spec/watirspec/html/frame_2.html +16 -0
- data/spec/watirspec/html/frames.html +11 -0
- data/spec/watirspec/html/hover.html +12 -0
- data/spec/watirspec/html/iframe_1.html +22 -0
- data/spec/watirspec/html/iframes.html +12 -0
- data/spec/watirspec/html/images.html +28 -0
- data/spec/watirspec/html/images/1.gif +0 -0
- data/spec/watirspec/html/images/2.gif +0 -0
- data/spec/watirspec/html/images/3.gif +0 -0
- data/spec/watirspec/html/images/button.png +0 -0
- data/spec/watirspec/html/images/circle.png +0 -0
- data/spec/watirspec/html/images/map.gif +0 -0
- data/spec/watirspec/html/images/map2.gif +0 -0
- data/spec/watirspec/html/images/minus.gif +0 -0
- data/spec/watirspec/html/images/originaltriangle.png +0 -0
- data/spec/watirspec/html/images/plus.gif +0 -0
- data/spec/watirspec/html/images/square.png +0 -0
- data/spec/watirspec/html/images/triangle.png +0 -0
- data/spec/watirspec/html/inner_outer.html +5 -0
- data/spec/watirspec/html/javascript/helpers.js +16 -0
- data/spec/watirspec/html/javascript/jquery-1.7.1.min.js +4 -0
- data/spec/watirspec/html/javascript/jquery-ui-1.8.17.custom.min.js +68 -0
- data/spec/watirspec/html/keylogger.html +15 -0
- data/spec/watirspec/html/modal_dialog.html +9 -0
- data/spec/watirspec/html/multiple_ids.html +14 -0
- data/spec/watirspec/html/nested_frame_1.html +1 -0
- data/spec/watirspec/html/nested_frame_2.html +9 -0
- data/spec/watirspec/html/nested_frame_3.html +14 -0
- data/spec/watirspec/html/nested_frames.html +10 -0
- data/spec/watirspec/html/nested_iframe_2.html +12 -0
- data/spec/watirspec/html/nested_iframes.html +9 -0
- data/spec/watirspec/html/nested_tables.html +203 -0
- data/spec/watirspec/html/non_control_elements.html +135 -0
- data/spec/watirspec/html/removed_element.html +24 -0
- data/spec/watirspec/html/right_click.html +11 -0
- data/spec/watirspec/html/special_chars.html +12 -0
- data/spec/watirspec/html/tables.html +121 -0
- data/spec/watirspec/html/timeout_window_location.html +19 -0
- data/spec/watirspec/html/uneven_table.html +20 -0
- data/spec/watirspec/html/wait.html +65 -0
- data/spec/watirspec/html/watirspec.css +0 -0
- data/spec/watirspec/html/window_switching.html +12 -0
- data/spec/watirspec/relaxed_locate_spec.rb +214 -0
- data/spec/watirspec/screenshot_spec.rb +29 -0
- data/spec/watirspec/wait_spec.rb +304 -0
- data/spec/watirspec/window_switching_spec.rb +411 -0
- data/spec/{implementation.rb → watirspec_helper.rb} +13 -13
- data/support/appveyor.cmd +9 -0
- data/support/doctest_helper.rb +5 -1
- data/support/travis.sh +0 -1
- data/watir.gemspec +3 -4
- metadata +323 -30
- data/.gitmodules +0 -3
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
# TODO - remove this file for future release
|
4
|
+
module Watir
|
5
|
+
|
6
|
+
class BaseDecorator
|
7
|
+
def initialize(element, timeout, message = nil)
|
8
|
+
@element = element
|
9
|
+
@timeout = timeout
|
10
|
+
@message = message
|
11
|
+
end
|
12
|
+
|
13
|
+
def respond_to?(*args)
|
14
|
+
@element.respond_to?(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(m, *args, &block)
|
18
|
+
unless @element.respond_to?(m)
|
19
|
+
raise NoMethodError, "undefined method `#{m}' for #{@element.inspect}:#{@element.class}"
|
20
|
+
end
|
21
|
+
|
22
|
+
Watir::Wait.until(@timeout, @message) { wait_until }
|
23
|
+
|
24
|
+
@element.__send__(m, *args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Wraps an Element so that any subsequent method calls are
|
30
|
+
# put on hold until the element is present (exists and is visible) on the page.
|
31
|
+
#
|
32
|
+
|
33
|
+
class WhenPresentDecorator < BaseDecorator
|
34
|
+
def present?
|
35
|
+
Watir::Wait.until(@timeout, @message) { wait_until }
|
36
|
+
true
|
37
|
+
rescue Watir::Wait::TimeoutError
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def wait_until
|
44
|
+
@element.present?
|
45
|
+
end
|
46
|
+
end # WhenPresentDecorator
|
47
|
+
|
48
|
+
#
|
49
|
+
# Wraps an Element so that any subsequent method calls are
|
50
|
+
# put on hold until the element is enabled (exists and is enabled) on the page.
|
51
|
+
#
|
52
|
+
|
53
|
+
class WhenEnabledDecorator < BaseDecorator
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def wait_until
|
58
|
+
@element.enabled?
|
59
|
+
end
|
60
|
+
end # WhenEnabledDecorator
|
61
|
+
|
62
|
+
#
|
63
|
+
# Convenience methods for things that eventually become present.
|
64
|
+
#
|
65
|
+
# Includers should implement a public #present? and a (possibly private) #selector_string method.
|
66
|
+
#
|
67
|
+
|
68
|
+
module EventuallyPresent
|
69
|
+
#
|
70
|
+
# Waits until the element is present.
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# browser.text_field(name: "new_user_first_name").when_present.click
|
74
|
+
# browser.text_field(name: "new_user_first_name").when_present { |field| field.set "Watir" }
|
75
|
+
# browser.text_field(name: "new_user_first_name").when_present(60).text
|
76
|
+
#
|
77
|
+
# @param [Fixnum] timeout seconds to wait before timing out
|
78
|
+
#
|
79
|
+
# @see Watir::Wait
|
80
|
+
# @see Watir::Element#present?
|
81
|
+
#
|
82
|
+
|
83
|
+
def when_present(timeout = nil)
|
84
|
+
warning = '#when_present has been deprecated and is unlikely to be needed; '
|
85
|
+
warning << 'replace this with #wait_until_present if a wait is still needed'
|
86
|
+
warn warning
|
87
|
+
|
88
|
+
timeout ||= Watir.default_timeout
|
89
|
+
message = "waiting for #{selector_string} to become present"
|
90
|
+
|
91
|
+
if block_given?
|
92
|
+
Watir::Wait.until(timeout, message) { present? }
|
93
|
+
yield self
|
94
|
+
else
|
95
|
+
WhenPresentDecorator.new(self, timeout, message)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Waits until the element is enabled.
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# browser.button(name: "new_user_button_2").when_enabled.click
|
104
|
+
#
|
105
|
+
# @param [Fixnum] timeout seconds to wait before timing out
|
106
|
+
#
|
107
|
+
# @see Watir::Wait
|
108
|
+
# @see Watir::Element#enabled?
|
109
|
+
#
|
110
|
+
|
111
|
+
def when_enabled(timeout = nil)
|
112
|
+
warn '#when_enabled has been deprecated and is unlikely to be needed'
|
113
|
+
|
114
|
+
timeout ||= Watir.default_timeout
|
115
|
+
message = "waiting for #{selector_string} to become enabled"
|
116
|
+
|
117
|
+
if block_given?
|
118
|
+
Watir::Wait.until(timeout, message) { enabled? }
|
119
|
+
yield self
|
120
|
+
else
|
121
|
+
WhenEnabledDecorator.new(self, timeout, message)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end # EventuallyPresent
|
126
|
+
end # Watir
|
@@ -32,9 +32,6 @@ module Watir
|
|
32
32
|
element = super
|
33
33
|
|
34
34
|
if element && !Watir::TextField::NON_TEXT_TYPES.include?(element.attribute(:type))
|
35
|
-
if element.tag_name.downcase == 'textarea'
|
36
|
-
warn "Locating textareas with '#text_field' is deprecated. Please, use '#textarea' method instead."
|
37
|
-
end
|
38
35
|
element
|
39
36
|
end
|
40
37
|
end
|
@@ -7,14 +7,11 @@ module Watir
|
|
7
7
|
|
8
8
|
selectors.delete(:tag_name)
|
9
9
|
|
10
|
-
textarea_attr_exp = xpath_builder.attribute_expression(:textarea, selectors)
|
11
10
|
input_attr_exp = xpath_builder.attribute_expression(:input, selectors)
|
12
11
|
|
13
12
|
xpath = ".//input[(not(@type) or (#{negative_type_expr}))"
|
14
13
|
xpath << " and #{input_attr_exp}" unless input_attr_exp.empty?
|
15
|
-
xpath << "]
|
16
|
-
xpath << "| .//textarea"
|
17
|
-
xpath << "[#{textarea_attr_exp}]" unless textarea_attr_exp.empty?
|
14
|
+
xpath << "]"
|
18
15
|
|
19
16
|
p build_wd_selector: xpath if $DEBUG
|
20
17
|
|
@@ -2,16 +2,8 @@ module Watir
|
|
2
2
|
module Locators
|
3
3
|
class TextField
|
4
4
|
class Validator < Element::Validator
|
5
|
-
VALID_TEXT_FIELD_TAGS = %w[input textarea]
|
6
|
-
|
7
5
|
def validate(element, selector)
|
8
|
-
|
9
|
-
|
10
|
-
if element.tag_name.downcase == 'textarea'
|
11
|
-
warn "Locating textareas with '#text_field' is deprecated. Please, use '#textarea' method instead."
|
12
|
-
end
|
13
|
-
return unless VALID_TEXT_FIELD_TAGS.include?(element_tag_name)
|
14
|
-
|
6
|
+
return unless element.tag_name.downcase == 'input'
|
15
7
|
element
|
16
8
|
end
|
17
9
|
end
|
data/lib/watir/row_container.rb
CHANGED
data/lib/watir/user_editable.rb
CHANGED
@@ -8,8 +8,10 @@ module Watir
|
|
8
8
|
#
|
9
9
|
|
10
10
|
def set(*args)
|
11
|
-
|
12
|
-
|
11
|
+
element_call(:wait_for_writable) do
|
12
|
+
@element.clear
|
13
|
+
@element.send_keys(*args)
|
14
|
+
end
|
13
15
|
end
|
14
16
|
alias_method :value=, :set
|
15
17
|
|
@@ -29,9 +31,9 @@ module Watir
|
|
29
31
|
#
|
30
32
|
|
31
33
|
def clear
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
element_call(:wait_for_writable) do
|
35
|
+
@element.clear
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
end # UserEditable
|
data/lib/watir/wait.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'forwardable'
|
2
1
|
require 'watir/wait/timer'
|
3
2
|
|
4
3
|
module Watir
|
@@ -32,13 +31,19 @@ module Watir
|
|
32
31
|
#
|
33
32
|
# @param [Fixnum] timeout How long to wait in seconds
|
34
33
|
# @param [String] message Message to raise if timeout is exceeded
|
34
|
+
# @param [Object, NilClass] object Object to evaluate block against
|
35
35
|
# @raise [TimeoutError] if timeout is exceeded
|
36
36
|
#
|
37
37
|
|
38
|
-
def until(
|
38
|
+
def until(deprecated_timeout = nil, deprecated_message = nil, timeout: nil, message: nil, object: nil)
|
39
|
+
if deprecated_message || deprecated_timeout
|
40
|
+
warn "Instead of passing arguments into Wait#until method, use keywords"
|
41
|
+
timeout = deprecated_timeout
|
42
|
+
message = deprecated_message
|
43
|
+
end
|
39
44
|
timeout ||= Watir.default_timeout
|
40
45
|
run_with_timer(timeout) do
|
41
|
-
result = yield(
|
46
|
+
result = yield(object)
|
42
47
|
return result if result
|
43
48
|
end
|
44
49
|
raise TimeoutError, message_for(timeout, message)
|
@@ -52,12 +57,18 @@ module Watir
|
|
52
57
|
#
|
53
58
|
# @param [Fixnum] timeout How long to wait in seconds
|
54
59
|
# @param [String] message Message to raise if timeout is exceeded
|
60
|
+
# @param [Object, NilClass] object Object to evaluate block against
|
55
61
|
# @raise [TimeoutError] if timeout is exceeded
|
56
62
|
#
|
57
63
|
|
58
|
-
def while(
|
64
|
+
def while(deprecated_timeout = nil, deprecated_message = nil, timeout: nil, message: nil, object: nil)
|
65
|
+
if deprecated_message || deprecated_timeout
|
66
|
+
warn "Instead of passing arguments into Wait#while method, use keywords"
|
67
|
+
timeout = deprecated_timeout
|
68
|
+
message = deprecated_message
|
69
|
+
end
|
59
70
|
timeout ||= Watir.default_timeout
|
60
|
-
run_with_timer(timeout) { return unless yield(
|
71
|
+
run_with_timer(timeout) { return unless yield(object) }
|
61
72
|
raise TimeoutError, message_for(timeout, message)
|
62
73
|
end
|
63
74
|
|
@@ -71,7 +82,7 @@ module Watir
|
|
71
82
|
end
|
72
83
|
|
73
84
|
def run_with_timer(timeout, &block)
|
74
|
-
if timeout
|
85
|
+
if timeout.zero?
|
75
86
|
block.call
|
76
87
|
else
|
77
88
|
timer.wait(timeout) do
|
@@ -84,128 +95,52 @@ module Watir
|
|
84
95
|
end # self
|
85
96
|
end # Wait
|
86
97
|
|
87
|
-
module Waitable
|
88
|
-
def wait_until(*args, &blk)
|
89
|
-
Wait.until(*args, &blk)
|
90
|
-
end
|
91
|
-
|
92
|
-
def wait_while(*args, &blk)
|
93
|
-
Wait.while(*args, &blk)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class BaseDecorator
|
98
|
-
|
99
|
-
def initialize(element, timeout, message = nil)
|
100
|
-
@element = element
|
101
|
-
@timeout = timeout
|
102
|
-
@message = message
|
103
|
-
end
|
104
|
-
|
105
|
-
def respond_to?(*args)
|
106
|
-
@element.respond_to?(*args)
|
107
|
-
end
|
108
|
-
|
109
|
-
def method_missing(m, *args, &block)
|
110
|
-
unless @element.respond_to?(m)
|
111
|
-
raise NoMethodError, "undefined method `#{m}' for #{@element.inspect}:#{@element.class}"
|
112
|
-
end
|
113
|
-
|
114
|
-
Watir::Wait.until(@timeout, @message) { wait_until }
|
115
|
-
|
116
|
-
@element.__send__(m, *args, &block)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
#
|
121
|
-
# Wraps an Element so that any subsequent method calls are
|
122
|
-
# put on hold until the element is present (exists and is visible) on the page.
|
123
|
-
#
|
124
|
-
|
125
|
-
class WhenPresentDecorator < BaseDecorator
|
126
|
-
def present?
|
127
|
-
Watir::Wait.until(@timeout, @message) { wait_until }
|
128
|
-
true
|
129
|
-
rescue Watir::Wait::TimeoutError
|
130
|
-
false
|
131
|
-
end
|
132
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
def wait_until
|
136
|
-
@element.present?
|
137
|
-
end
|
138
|
-
end # WhenPresentDecorator
|
139
|
-
|
140
|
-
#
|
141
|
-
# Wraps an Element so that any subsequent method calls are
|
142
|
-
# put on hold until the element is enabled (exists and is enabled) on the page.
|
143
|
-
#
|
144
|
-
|
145
|
-
class WhenEnabledDecorator < BaseDecorator
|
146
|
-
|
147
|
-
private
|
148
|
-
|
149
|
-
def wait_until
|
150
|
-
@element.enabled?
|
151
|
-
end
|
152
|
-
end # WhenEnabledDecorator
|
153
98
|
|
154
|
-
|
155
|
-
# Convenience methods for things that eventually become present.
|
156
|
-
#
|
157
|
-
# Includers should implement a public #present? and a (possibly private) #selector_string method.
|
158
|
-
#
|
99
|
+
module Waitable
|
159
100
|
|
160
|
-
module EventuallyPresent
|
161
101
|
#
|
162
|
-
# Waits until the
|
102
|
+
# Waits until the condition is true.
|
163
103
|
#
|
164
104
|
# @example
|
165
|
-
# browser.
|
166
|
-
#
|
167
|
-
#
|
105
|
+
# browser.wait_until(timeout: 2) do |browser|
|
106
|
+
# browser.windows.size == 1
|
107
|
+
# end
|
168
108
|
#
|
169
|
-
# @
|
109
|
+
# @example
|
110
|
+
# browser.text_field(name: "new_user_first_name").wait_until(&:present?).click
|
111
|
+
# browser.text_field(name: "new_user_first_name").wait_until(message: 'foo') { |field| field.present? }
|
112
|
+
# browser.text_field(name: "new_user_first_name").wait_until(timeout: 60, &:present?)
|
170
113
|
#
|
171
|
-
# @
|
172
|
-
# @
|
114
|
+
# @param [Fixnum] timeout seconds to wait before timing out
|
115
|
+
# @param [String] message error message for when times out
|
173
116
|
#
|
174
117
|
|
175
|
-
def
|
176
|
-
|
177
|
-
|
118
|
+
def wait_until(timeout: nil, message: nil, &blk)
|
119
|
+
message ||= "waiting for true condition on #{selector_string}"
|
120
|
+
Wait.until(timeout: timeout, message: message, object: self, &blk)
|
178
121
|
|
179
|
-
|
180
|
-
Watir::Wait.until(timeout, message) { present? }
|
181
|
-
yield self
|
182
|
-
else
|
183
|
-
WhenPresentDecorator.new(self, timeout, message)
|
184
|
-
end
|
122
|
+
self
|
185
123
|
end
|
186
124
|
|
187
125
|
#
|
188
|
-
# Waits
|
126
|
+
# Waits while the condition is true.
|
189
127
|
#
|
190
128
|
# @example
|
191
|
-
# browser.
|
129
|
+
# browser.wait_while(timeout: 2) do |browser|
|
130
|
+
# !browser.exists?
|
131
|
+
# end
|
192
132
|
#
|
193
|
-
# @
|
133
|
+
# @todo add element example
|
194
134
|
#
|
195
|
-
# @
|
196
|
-
# @
|
135
|
+
# @param [Fixnum] timeout seconds to wait before timing out
|
136
|
+
# @param [String] message error message for when times out
|
197
137
|
#
|
198
138
|
|
199
|
-
def
|
200
|
-
|
201
|
-
|
139
|
+
def wait_while(timeout: nil, message: nil, &blk)
|
140
|
+
message ||= "waiting for false condition on #{selector_string}"
|
141
|
+
Wait.while(timeout: timeout, message: message, object: self, &blk)
|
202
142
|
|
203
|
-
|
204
|
-
Watir::Wait.until(timeout, message) { enabled? }
|
205
|
-
yield self
|
206
|
-
else
|
207
|
-
WhenEnabledDecorator.new(self, timeout, message)
|
208
|
-
end
|
143
|
+
self
|
209
144
|
end
|
210
145
|
|
211
146
|
#
|
@@ -220,10 +155,12 @@ module Watir
|
|
220
155
|
# @see Watir::Element#present?
|
221
156
|
#
|
222
157
|
|
223
|
-
def wait_until_present(
|
224
|
-
|
225
|
-
|
226
|
-
|
158
|
+
def wait_until_present(deprecated_timeout = nil, timeout: nil)
|
159
|
+
if deprecated_timeout
|
160
|
+
warn "Instead of passing arguments into #wait_until_present method, use keywords"
|
161
|
+
timeout = deprecated_timeout
|
162
|
+
end
|
163
|
+
wait_until(timeout: timeout, &:present?)
|
227
164
|
end
|
228
165
|
|
229
166
|
#
|
@@ -238,29 +175,13 @@ module Watir
|
|
238
175
|
# @see Watir::Element#present?
|
239
176
|
#
|
240
177
|
|
241
|
-
def wait_while_present(
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
#
|
248
|
-
# Waits until the element is stale.
|
249
|
-
#
|
250
|
-
# @example
|
251
|
-
# browser.text_field(name: "abrakadbra").wait_until_stale
|
252
|
-
#
|
253
|
-
# @param [Fixnum] timeout seconds to wait before timing out
|
254
|
-
#
|
255
|
-
# @see Watir::Wait
|
256
|
-
# @see Watir::Element#stale?
|
257
|
-
#
|
258
|
-
|
259
|
-
def wait_until_stale(timeout = nil)
|
260
|
-
timeout ||= Watir.default_timeout
|
261
|
-
message = "waiting for #{selector_string} to become stale"
|
262
|
-
Watir::Wait.until(timeout, message) { stale? }
|
178
|
+
def wait_while_present(deprecated_timeout = nil, timeout: nil)
|
179
|
+
if deprecated_timeout
|
180
|
+
warn "Instead of passing arguments into #wait_while_present method, use keywords"
|
181
|
+
timeout = deprecated_timeout
|
182
|
+
end
|
183
|
+
wait_while(timeout: timeout, &:present?)
|
263
184
|
end
|
264
185
|
|
265
|
-
end #
|
186
|
+
end # Waitable
|
266
187
|
end # Watir
|