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.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -2
  3. data/CHANGES.md +10 -1
  4. data/Gemfile +4 -0
  5. data/README.md +37 -23
  6. data/Rakefile +6 -10
  7. data/appveyor.yml +13 -0
  8. data/lib/watir.rb +20 -21
  9. data/lib/watir/alert.rb +21 -5
  10. data/lib/watir/browser.rb +9 -3
  11. data/lib/watir/elements/checkbox.rb +0 -1
  12. data/lib/watir/elements/element.rb +92 -50
  13. data/lib/watir/elements/form.rb +1 -2
  14. data/lib/watir/elements/iframe.rb +6 -2
  15. data/lib/watir/elements/image.rb +1 -1
  16. data/lib/watir/elements/option.rb +0 -1
  17. data/lib/watir/elements/radio.rb +0 -1
  18. data/lib/watir/elements/select.rb +1 -10
  19. data/lib/watir/extensions/select_text.rb +1 -1
  20. data/lib/watir/legacy_wait.rb +126 -0
  21. data/lib/watir/locators/text_field/locator.rb +0 -3
  22. data/lib/watir/locators/text_field/selector_builder.rb +1 -4
  23. data/lib/watir/locators/text_field/selector_builder/xpath.rb +0 -2
  24. data/lib/watir/locators/text_field/validator.rb +1 -9
  25. data/lib/watir/row_container.rb +1 -1
  26. data/lib/watir/user_editable.rb +7 -5
  27. data/lib/watir/wait.rb +56 -135
  28. data/lib/watir/wait/timer.rb +29 -2
  29. data/lib/watir/window.rb +11 -1
  30. data/lib/watirspec.rb +81 -0
  31. data/lib/watirspec/guards.rb +58 -0
  32. data/lib/watirspec/implementation.rb +33 -0
  33. data/lib/watirspec/rake_tasks.rb +115 -0
  34. data/lib/watirspec/runner.rb +53 -0
  35. data/lib/watirspec/server.rb +99 -0
  36. data/lib/watirspec/server/app.rb +62 -0
  37. data/spec/browser_spec.rb +5 -5
  38. data/spec/click_spec.rb +1 -1
  39. data/spec/container_spec.rb +1 -1
  40. data/spec/element_locator_spec.rb +1 -1
  41. data/spec/element_spec.rb +20 -34
  42. data/spec/implementation_spec.rb +24 -0
  43. data/spec/input_spec.rb +1 -1
  44. data/spec/spec_helper.rb +35 -3
  45. data/spec/special_chars_spec.rb +1 -1
  46. data/spec/watirspec/.gitignore +2 -0
  47. data/spec/watirspec/after_hooks_spec.rb +179 -0
  48. data/spec/watirspec/alert_spec.rb +101 -0
  49. data/spec/watirspec/browser_spec.rb +291 -0
  50. data/spec/watirspec/cookies_spec.rb +147 -0
  51. data/spec/watirspec/drag_and_drop_spec.rb +49 -0
  52. data/spec/watirspec/element_hidden_spec.rb +65 -0
  53. data/spec/watirspec/elements/area_spec.rb +76 -0
  54. data/spec/watirspec/elements/areas_spec.rb +42 -0
  55. data/spec/watirspec/elements/button_spec.rb +270 -0
  56. data/spec/watirspec/elements/buttons_spec.rb +55 -0
  57. data/spec/watirspec/elements/checkbox_spec.rb +279 -0
  58. data/spec/watirspec/elements/checkboxes_spec.rb +44 -0
  59. data/spec/watirspec/elements/collections_spec.rb +16 -0
  60. data/spec/watirspec/elements/dd_spec.rb +126 -0
  61. data/spec/watirspec/elements/dds_spec.rb +42 -0
  62. data/spec/watirspec/elements/del_spec.rb +128 -0
  63. data/spec/watirspec/elements/dels_spec.rb +40 -0
  64. data/spec/watirspec/elements/div_spec.rb +199 -0
  65. data/spec/watirspec/elements/divs_spec.rb +42 -0
  66. data/spec/watirspec/elements/dl_spec.rb +144 -0
  67. data/spec/watirspec/elements/dls_spec.rb +43 -0
  68. data/spec/watirspec/elements/dt_spec.rb +126 -0
  69. data/spec/watirspec/elements/dts_spec.rb +42 -0
  70. data/spec/watirspec/elements/element_spec.rb +361 -0
  71. data/spec/watirspec/elements/elements_spec.rb +15 -0
  72. data/spec/watirspec/elements/em_spec.rb +100 -0
  73. data/spec/watirspec/elements/ems_spec.rb +43 -0
  74. data/spec/watirspec/elements/filefield_spec.rb +181 -0
  75. data/spec/watirspec/elements/filefields_spec.rb +43 -0
  76. data/spec/watirspec/elements/font_spec.rb +29 -0
  77. data/spec/watirspec/elements/form_spec.rb +70 -0
  78. data/spec/watirspec/elements/forms_spec.rb +44 -0
  79. data/spec/watirspec/elements/frame_spec.rb +121 -0
  80. data/spec/watirspec/elements/frames_spec.rb +41 -0
  81. data/spec/watirspec/elements/hidden_spec.rb +102 -0
  82. data/spec/watirspec/elements/hiddens_spec.rb +43 -0
  83. data/spec/watirspec/elements/hn_spec.rb +96 -0
  84. data/spec/watirspec/elements/hns_spec.rb +38 -0
  85. data/spec/watirspec/elements/iframe_spec.rb +174 -0
  86. data/spec/watirspec/elements/iframes_spec.rb +47 -0
  87. data/spec/watirspec/elements/image_spec.rb +164 -0
  88. data/spec/watirspec/elements/images_spec.rb +40 -0
  89. data/spec/watirspec/elements/ins_spec.rb +129 -0
  90. data/spec/watirspec/elements/inses_spec.rb +40 -0
  91. data/spec/watirspec/elements/label_spec.rb +79 -0
  92. data/spec/watirspec/elements/labels_spec.rb +40 -0
  93. data/spec/watirspec/elements/li_spec.rb +115 -0
  94. data/spec/watirspec/elements/link_spec.rb +174 -0
  95. data/spec/watirspec/elements/links_spec.rb +44 -0
  96. data/spec/watirspec/elements/lis_spec.rb +42 -0
  97. data/spec/watirspec/elements/map_spec.rb +79 -0
  98. data/spec/watirspec/elements/maps_spec.rb +41 -0
  99. data/spec/watirspec/elements/meta_spec.rb +23 -0
  100. data/spec/watirspec/elements/metas_spec.rb +40 -0
  101. data/spec/watirspec/elements/ol_spec.rb +89 -0
  102. data/spec/watirspec/elements/ols_spec.rb +40 -0
  103. data/spec/watirspec/elements/option_spec.rb +152 -0
  104. data/spec/watirspec/elements/p_spec.rb +115 -0
  105. data/spec/watirspec/elements/pre_spec.rb +115 -0
  106. data/spec/watirspec/elements/pres_spec.rb +40 -0
  107. data/spec/watirspec/elements/ps_spec.rb +40 -0
  108. data/spec/watirspec/elements/radio_spec.rb +263 -0
  109. data/spec/watirspec/elements/radios_spec.rb +43 -0
  110. data/spec/watirspec/elements/select_list_spec.rb +379 -0
  111. data/spec/watirspec/elements/select_lists_spec.rb +46 -0
  112. data/spec/watirspec/elements/span_spec.rb +129 -0
  113. data/spec/watirspec/elements/spans_spec.rb +40 -0
  114. data/spec/watirspec/elements/strong_spec.rb +92 -0
  115. data/spec/watirspec/elements/strongs_spec.rb +43 -0
  116. data/spec/watirspec/elements/table_nesting_spec.rb +51 -0
  117. data/spec/watirspec/elements/table_spec.rb +146 -0
  118. data/spec/watirspec/elements/tables_spec.rb +42 -0
  119. data/spec/watirspec/elements/tbody_spec.rb +96 -0
  120. data/spec/watirspec/elements/tbodys_spec.rb +62 -0
  121. data/spec/watirspec/elements/td_spec.rb +71 -0
  122. data/spec/watirspec/elements/tds_spec.rb +53 -0
  123. data/spec/watirspec/elements/text_field_spec.rb +302 -0
  124. data/spec/watirspec/elements/text_fields_spec.rb +44 -0
  125. data/spec/watirspec/elements/textarea_spec.rb +26 -0
  126. data/spec/watirspec/elements/textareas_spec.rb +24 -0
  127. data/spec/watirspec/elements/tfoot_spec.rb +91 -0
  128. data/spec/watirspec/elements/tfoots_spec.rb +68 -0
  129. data/spec/watirspec/elements/thead_spec.rb +91 -0
  130. data/spec/watirspec/elements/theads_spec.rb +68 -0
  131. data/spec/watirspec/elements/tr_spec.rb +80 -0
  132. data/spec/watirspec/elements/trs_spec.rb +61 -0
  133. data/spec/watirspec/elements/ul_spec.rb +79 -0
  134. data/spec/watirspec/elements/uls_spec.rb +39 -0
  135. data/spec/watirspec/html/alerts.html +12 -0
  136. data/spec/watirspec/html/aria_attributes.html +9 -0
  137. data/spec/watirspec/html/class_locator.html +8 -0
  138. data/spec/watirspec/html/clicks.html +19 -0
  139. data/spec/watirspec/html/closeable.html +13 -0
  140. data/spec/watirspec/html/collections.html +15 -0
  141. data/spec/watirspec/html/css/jquery-ui-1.8.17.custom.css +287 -0
  142. data/spec/watirspec/html/data_attributes.html +9 -0
  143. data/spec/watirspec/html/definition_lists.html +48 -0
  144. data/spec/watirspec/html/drag_and_drop.html +106 -0
  145. data/spec/watirspec/html/font.html +10 -0
  146. data/spec/watirspec/html/forms_with_input_elements.html +170 -0
  147. data/spec/watirspec/html/frame_1.html +22 -0
  148. data/spec/watirspec/html/frame_2.html +16 -0
  149. data/spec/watirspec/html/frames.html +11 -0
  150. data/spec/watirspec/html/hover.html +12 -0
  151. data/spec/watirspec/html/iframe_1.html +22 -0
  152. data/spec/watirspec/html/iframes.html +12 -0
  153. data/spec/watirspec/html/images.html +28 -0
  154. data/spec/watirspec/html/images/1.gif +0 -0
  155. data/spec/watirspec/html/images/2.gif +0 -0
  156. data/spec/watirspec/html/images/3.gif +0 -0
  157. data/spec/watirspec/html/images/button.png +0 -0
  158. data/spec/watirspec/html/images/circle.png +0 -0
  159. data/spec/watirspec/html/images/map.gif +0 -0
  160. data/spec/watirspec/html/images/map2.gif +0 -0
  161. data/spec/watirspec/html/images/minus.gif +0 -0
  162. data/spec/watirspec/html/images/originaltriangle.png +0 -0
  163. data/spec/watirspec/html/images/plus.gif +0 -0
  164. data/spec/watirspec/html/images/square.png +0 -0
  165. data/spec/watirspec/html/images/triangle.png +0 -0
  166. data/spec/watirspec/html/inner_outer.html +5 -0
  167. data/spec/watirspec/html/javascript/helpers.js +16 -0
  168. data/spec/watirspec/html/javascript/jquery-1.7.1.min.js +4 -0
  169. data/spec/watirspec/html/javascript/jquery-ui-1.8.17.custom.min.js +68 -0
  170. data/spec/watirspec/html/keylogger.html +15 -0
  171. data/spec/watirspec/html/modal_dialog.html +9 -0
  172. data/spec/watirspec/html/multiple_ids.html +14 -0
  173. data/spec/watirspec/html/nested_frame_1.html +1 -0
  174. data/spec/watirspec/html/nested_frame_2.html +9 -0
  175. data/spec/watirspec/html/nested_frame_3.html +14 -0
  176. data/spec/watirspec/html/nested_frames.html +10 -0
  177. data/spec/watirspec/html/nested_iframe_2.html +12 -0
  178. data/spec/watirspec/html/nested_iframes.html +9 -0
  179. data/spec/watirspec/html/nested_tables.html +203 -0
  180. data/spec/watirspec/html/non_control_elements.html +135 -0
  181. data/spec/watirspec/html/removed_element.html +24 -0
  182. data/spec/watirspec/html/right_click.html +11 -0
  183. data/spec/watirspec/html/special_chars.html +12 -0
  184. data/spec/watirspec/html/tables.html +121 -0
  185. data/spec/watirspec/html/timeout_window_location.html +19 -0
  186. data/spec/watirspec/html/uneven_table.html +20 -0
  187. data/spec/watirspec/html/wait.html +65 -0
  188. data/spec/watirspec/html/watirspec.css +0 -0
  189. data/spec/watirspec/html/window_switching.html +12 -0
  190. data/spec/watirspec/relaxed_locate_spec.rb +214 -0
  191. data/spec/watirspec/screenshot_spec.rb +29 -0
  192. data/spec/watirspec/wait_spec.rb +304 -0
  193. data/spec/watirspec/window_switching_spec.rb +411 -0
  194. data/spec/{implementation.rb → watirspec_helper.rb} +13 -13
  195. data/support/appveyor.cmd +9 -0
  196. data/support/doctest_helper.rb +5 -1
  197. data/support/travis.sh +0 -1
  198. data/watir.gemspec +3 -4
  199. metadata +323 -30
  200. data/.gitmodules +0 -3
@@ -3,7 +3,7 @@ Watir::Atoms.load :selectText
3
3
  module Watir
4
4
  class Element
5
5
  def select_text(str)
6
- assert_exists
6
+ wait_for_exists
7
7
  execute_atom :selectText, @element, str
8
8
  end
9
9
  end # Element
@@ -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
 
@@ -6,8 +6,6 @@ module Watir
6
6
  def lhs_for(building, key)
7
7
  if building == :input && key == :text
8
8
  "@value"
9
- elsif building == :textarea && key == :value
10
- "text()"
11
9
  else
12
10
  super
13
11
  end
@@ -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
- element_tag_name = element.tag_name.downcase
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
@@ -24,7 +24,7 @@ module Watir
24
24
  #
25
25
 
26
26
  def strings
27
- assert_exists
27
+ wait_for_exists
28
28
 
29
29
  rows.inject [] do |res, row|
30
30
  res << row.cells.map(&:text)
@@ -8,8 +8,10 @@ module Watir
8
8
  #
9
9
 
10
10
  def set(*args)
11
- clear
12
- element_call { @element.send_keys(*args) }
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
- assert_exists
33
- assert_writable
34
- element_call { @element.clear }
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(timeout = nil, message = nil)
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(self)
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(timeout = nil, message = nil)
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(self) }
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 == 0
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 element is present.
102
+ # Waits until the condition is true.
163
103
  #
164
104
  # @example
165
- # browser.text_field(name: "new_user_first_name").when_present.click
166
- # browser.text_field(name: "new_user_first_name").when_present { |field| field.set "Watir" }
167
- # browser.text_field(name: "new_user_first_name").when_present(60).text
105
+ # browser.wait_until(timeout: 2) do |browser|
106
+ # browser.windows.size == 1
107
+ # end
168
108
  #
169
- # @param [Fixnum] timeout seconds to wait before timing out
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
- # @see Watir::Wait
172
- # @see Watir::Element#present?
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 when_present(timeout = nil)
176
- timeout ||= Watir.default_timeout
177
- message = "waiting for #{selector_string} to become present"
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
- if block_given?
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 until the element is enabled.
126
+ # Waits while the condition is true.
189
127
  #
190
128
  # @example
191
- # browser.button(name: "new_user_button_2").when_enabled.click
129
+ # browser.wait_while(timeout: 2) do |browser|
130
+ # !browser.exists?
131
+ # end
192
132
  #
193
- # @param [Fixnum] timeout seconds to wait before timing out
133
+ # @todo add element example
194
134
  #
195
- # @see Watir::Wait
196
- # @see Watir::Element#enabled?
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 when_enabled(timeout = nil)
200
- timeout ||= Watir.default_timeout
201
- message = "waiting for #{selector_string} to become enabled"
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
- if block_given?
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(timeout = nil)
224
- timeout ||= Watir.default_timeout
225
- message = "waiting for #{selector_string} to become present"
226
- Watir::Wait.until(timeout, message) { present? }
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(timeout = nil)
242
- timeout ||= Watir.default_timeout
243
- message = "waiting for #{selector_string} to disappear"
244
- Watir::Wait.while(timeout, message) { present? }
245
- end
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 # EventuallyPresent
186
+ end # Waitable
266
187
  end # Watir