watir 6.10.0 → 6.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/.document +5 -5
  3. data/.github/ISSUE_TEMPLATE.md +16 -16
  4. data/.gitignore +21 -21
  5. data/.travis.yml +72 -72
  6. data/CHANGES.md +6 -0
  7. data/Gemfile +16 -16
  8. data/LICENSE +23 -23
  9. data/README.md +106 -106
  10. data/Rakefile +153 -153
  11. data/appveyor.yml +13 -13
  12. data/lib/watir-webdriver.rb +2 -2
  13. data/lib/watir.rb +158 -158
  14. data/lib/watir/adjacent.rb +126 -126
  15. data/lib/watir/after_hooks.rb +132 -132
  16. data/lib/watir/alert.rb +120 -120
  17. data/lib/watir/aliases.rb +6 -6
  18. data/lib/watir/attribute_helper.rb +96 -96
  19. data/lib/watir/browser.rb +349 -349
  20. data/lib/watir/capabilities.rb +123 -123
  21. data/lib/watir/cell_container.rb +25 -25
  22. data/lib/watir/container.rb +51 -51
  23. data/lib/watir/cookies.rb +134 -134
  24. data/lib/watir/element_collection.rb +138 -138
  25. data/lib/watir/elements/area.rb +12 -12
  26. data/lib/watir/elements/button.rb +37 -37
  27. data/lib/watir/elements/cell.rb +17 -17
  28. data/lib/watir/elements/checkbox.rb +56 -56
  29. data/lib/watir/elements/dlist.rb +12 -12
  30. data/lib/watir/elements/element.rb +6 -5
  31. data/lib/watir/elements/file_field.rb +41 -41
  32. data/lib/watir/elements/font.rb +25 -25
  33. data/lib/watir/elements/form.rb +16 -16
  34. data/lib/watir/elements/hidden.rb +25 -25
  35. data/lib/watir/elements/html_elements.rb +2035 -2035
  36. data/lib/watir/elements/iframe.rb +166 -166
  37. data/lib/watir/elements/image.rb +21 -21
  38. data/lib/watir/elements/input.rb +15 -15
  39. data/lib/watir/elements/link.rb +18 -18
  40. data/lib/watir/elements/list.rb +49 -49
  41. data/lib/watir/elements/option.rb +72 -72
  42. data/lib/watir/elements/radio.rb +60 -60
  43. data/lib/watir/elements/row.rb +17 -17
  44. data/lib/watir/elements/select.rb +250 -250
  45. data/lib/watir/elements/svg_elements.rb +613 -613
  46. data/lib/watir/elements/table.rb +76 -76
  47. data/lib/watir/elements/table_cell.rb +31 -31
  48. data/lib/watir/elements/table_row.rb +32 -32
  49. data/lib/watir/elements/table_section.rb +15 -15
  50. data/lib/watir/elements/text_area.rb +5 -5
  51. data/lib/watir/elements/text_field.rb +39 -39
  52. data/lib/watir/exception.rb +16 -16
  53. data/lib/watir/extensions/nokogiri.rb +14 -14
  54. data/lib/watir/generator.rb +3 -3
  55. data/lib/watir/generator/base.rb +11 -11
  56. data/lib/watir/generator/base/generator.rb +115 -115
  57. data/lib/watir/generator/base/idl_sorter.rb +47 -47
  58. data/lib/watir/generator/base/spec_extractor.rb +138 -138
  59. data/lib/watir/generator/base/util.rb +21 -21
  60. data/lib/watir/generator/base/visitor.rb +162 -162
  61. data/lib/watir/generator/html.rb +15 -15
  62. data/lib/watir/generator/html/generator.rb +36 -36
  63. data/lib/watir/generator/html/spec_extractor.rb +50 -50
  64. data/lib/watir/generator/html/visitor.rb +21 -21
  65. data/lib/watir/generator/svg.rb +7 -7
  66. data/lib/watir/generator/svg/generator.rb +38 -38
  67. data/lib/watir/generator/svg/spec_extractor.rb +53 -53
  68. data/lib/watir/generator/svg/visitor.rb +21 -21
  69. data/lib/watir/has_window.rb +68 -68
  70. data/lib/watir/js_execution.rb +143 -143
  71. data/lib/watir/js_snippets.rb +16 -16
  72. data/lib/watir/js_snippets/backgroundColor.js +7 -7
  73. data/lib/watir/js_snippets/fireEvent.js +31 -31
  74. data/lib/watir/js_snippets/focus.js +3 -3
  75. data/lib/watir/js_snippets/getInnerHtml.js +19 -19
  76. data/lib/watir/js_snippets/getInnerText.js +19 -19
  77. data/lib/watir/js_snippets/getOuterHtml.js +20 -20
  78. data/lib/watir/js_snippets/getTextContent.js +19 -19
  79. data/lib/watir/js_snippets/isImageLoaded.js +3 -3
  80. data/lib/watir/js_snippets/selectOptionsLabel.js +10 -10
  81. data/lib/watir/js_snippets/selectOptionsText.js +10 -10
  82. data/lib/watir/js_snippets/selectOptionsValue.js +10 -10
  83. data/lib/watir/js_snippets/selectText.js +64 -64
  84. data/lib/watir/js_snippets/selectedOptions.js +11 -11
  85. data/lib/watir/js_snippets/setValue.js +3 -3
  86. data/lib/watir/legacy_wait.rb +126 -126
  87. data/lib/watir/locators.rb +60 -60
  88. data/lib/watir/locators/button/locator.rb +31 -31
  89. data/lib/watir/locators/button/selector_builder.rb +30 -30
  90. data/lib/watir/locators/button/selector_builder/xpath.rb +29 -29
  91. data/lib/watir/locators/button/validator.rb +15 -15
  92. data/lib/watir/locators/cell/locator.rb +15 -15
  93. data/lib/watir/locators/cell/selector_builder.rb +24 -24
  94. data/lib/watir/locators/element/locator.rb +1 -0
  95. data/lib/watir/locators/element/selector_builder.rb +150 -150
  96. data/lib/watir/locators/element/selector_builder/xpath.rb +119 -119
  97. data/lib/watir/locators/element/validator.rb +18 -18
  98. data/lib/watir/locators/row/locator.rb +15 -15
  99. data/lib/watir/locators/row/selector_builder.rb +29 -29
  100. data/lib/watir/locators/text_area/locator.rb +13 -13
  101. data/lib/watir/locators/text_area/selector_builder.rb +22 -22
  102. data/lib/watir/locators/text_field/locator.rb +30 -30
  103. data/lib/watir/locators/text_field/selector_builder.rb +31 -31
  104. data/lib/watir/locators/text_field/selector_builder/xpath.rb +17 -17
  105. data/lib/watir/locators/text_field/validator.rb +12 -12
  106. data/lib/watir/logger.rb +109 -109
  107. data/lib/watir/radio_set.rb +231 -231
  108. data/lib/watir/row_container.rb +36 -36
  109. data/lib/watir/screenshot.rb +50 -50
  110. data/lib/watir/user_editable.rb +56 -56
  111. data/lib/watir/wait.rb +200 -200
  112. data/lib/watir/wait/timer.rb +52 -52
  113. data/lib/watir/window.rb +257 -257
  114. data/lib/watir/xpath_support.rb +20 -20
  115. data/lib/watirspec.rb +86 -86
  116. data/lib/watirspec/guards.rb +60 -60
  117. data/lib/watirspec/implementation.rb +51 -51
  118. data/lib/watirspec/rake_tasks.rb +115 -115
  119. data/lib/watirspec/remote_server.rb +38 -38
  120. data/lib/watirspec/runner.rb +53 -53
  121. data/lib/watirspec/server.rb +99 -99
  122. data/lib/watirspec/server/app.rb +76 -76
  123. data/spec/browser_spec.rb +278 -278
  124. data/spec/click_spec.rb +19 -19
  125. data/spec/container_spec.rb +34 -34
  126. data/spec/element_locator_spec.rb +517 -517
  127. data/spec/element_spec.rb +158 -158
  128. data/spec/implementation_spec.rb +24 -24
  129. data/spec/input_spec.rb +14 -14
  130. data/spec/locator_spec_helper.rb +55 -55
  131. data/spec/logger_spec.rb +46 -46
  132. data/spec/spec_helper.rb +22 -22
  133. data/spec/special_chars_spec.rb +13 -13
  134. data/spec/watirspec/adjacent_spec.rb +227 -227
  135. data/spec/watirspec/after_hooks_spec.rb +182 -182
  136. data/spec/watirspec/alert_spec.rb +108 -108
  137. data/spec/watirspec/attributes_spec.rb +16 -16
  138. data/spec/watirspec/browser_spec.rb +281 -281
  139. data/spec/watirspec/cookies_spec.rb +154 -154
  140. data/spec/watirspec/drag_and_drop_spec.rb +49 -49
  141. data/spec/watirspec/element_hidden_spec.rb +75 -75
  142. data/spec/watirspec/elements/area_spec.rb +72 -72
  143. data/spec/watirspec/elements/areas_spec.rb +42 -42
  144. data/spec/watirspec/elements/button_spec.rb +277 -277
  145. data/spec/watirspec/elements/buttons_spec.rb +55 -55
  146. data/spec/watirspec/elements/checkbox_spec.rb +275 -275
  147. data/spec/watirspec/elements/checkboxes_spec.rb +44 -44
  148. data/spec/watirspec/elements/collections_spec.rb +52 -52
  149. data/spec/watirspec/elements/dd_spec.rb +124 -124
  150. data/spec/watirspec/elements/dds_spec.rb +42 -42
  151. data/spec/watirspec/elements/del_spec.rb +126 -126
  152. data/spec/watirspec/elements/dels_spec.rb +40 -40
  153. data/spec/watirspec/elements/div_spec.rb +245 -245
  154. data/spec/watirspec/elements/divs_spec.rb +42 -42
  155. data/spec/watirspec/elements/dl_spec.rb +142 -142
  156. data/spec/watirspec/elements/dls_spec.rb +43 -43
  157. data/spec/watirspec/elements/dt_spec.rb +122 -122
  158. data/spec/watirspec/elements/dts_spec.rb +42 -42
  159. data/spec/watirspec/elements/element_spec.rb +483 -483
  160. data/spec/watirspec/elements/elements_spec.rb +47 -47
  161. data/spec/watirspec/elements/em_spec.rb +96 -96
  162. data/spec/watirspec/elements/ems_spec.rb +43 -43
  163. data/spec/watirspec/elements/filefield_spec.rb +170 -170
  164. data/spec/watirspec/elements/filefields_spec.rb +43 -43
  165. data/spec/watirspec/elements/font_spec.rb +29 -29
  166. data/spec/watirspec/elements/form_spec.rb +66 -66
  167. data/spec/watirspec/elements/forms_spec.rb +46 -46
  168. data/spec/watirspec/elements/frame_spec.rb +123 -123
  169. data/spec/watirspec/elements/frames_spec.rb +41 -41
  170. data/spec/watirspec/elements/hidden_spec.rb +104 -104
  171. data/spec/watirspec/elements/hiddens_spec.rb +43 -43
  172. data/spec/watirspec/elements/hn_spec.rb +92 -92
  173. data/spec/watirspec/elements/hns_spec.rb +38 -38
  174. data/spec/watirspec/elements/iframe_spec.rb +10 -0
  175. data/spec/watirspec/elements/iframes_spec.rb +47 -47
  176. data/spec/watirspec/elements/image_spec.rb +158 -158
  177. data/spec/watirspec/elements/images_spec.rb +40 -40
  178. data/spec/watirspec/elements/ins_spec.rb +127 -127
  179. data/spec/watirspec/elements/inses_spec.rb +40 -40
  180. data/spec/watirspec/elements/label_spec.rb +75 -75
  181. data/spec/watirspec/elements/labels_spec.rb +40 -40
  182. data/spec/watirspec/elements/li_spec.rb +111 -111
  183. data/spec/watirspec/elements/link_spec.rb +171 -171
  184. data/spec/watirspec/elements/links_spec.rb +44 -44
  185. data/spec/watirspec/elements/lis_spec.rb +42 -42
  186. data/spec/watirspec/elements/list_spec.rb +32 -32
  187. data/spec/watirspec/elements/map_spec.rb +75 -75
  188. data/spec/watirspec/elements/maps_spec.rb +41 -41
  189. data/spec/watirspec/elements/meta_spec.rb +23 -23
  190. data/spec/watirspec/elements/metas_spec.rb +40 -40
  191. data/spec/watirspec/elements/ol_spec.rb +87 -87
  192. data/spec/watirspec/elements/ols_spec.rb +40 -40
  193. data/spec/watirspec/elements/option_spec.rb +121 -121
  194. data/spec/watirspec/elements/p_spec.rb +111 -111
  195. data/spec/watirspec/elements/pre_spec.rb +111 -111
  196. data/spec/watirspec/elements/pres_spec.rb +40 -40
  197. data/spec/watirspec/elements/ps_spec.rb +40 -40
  198. data/spec/watirspec/elements/radio_spec.rb +273 -273
  199. data/spec/watirspec/elements/radios_spec.rb +43 -43
  200. data/spec/watirspec/elements/select_list_spec.rb +553 -553
  201. data/spec/watirspec/elements/select_lists_spec.rb +46 -46
  202. data/spec/watirspec/elements/span_spec.rb +128 -128
  203. data/spec/watirspec/elements/spans_spec.rb +40 -40
  204. data/spec/watirspec/elements/strong_spec.rb +88 -88
  205. data/spec/watirspec/elements/strongs_spec.rb +43 -43
  206. data/spec/watirspec/elements/table_nesting_spec.rb +51 -51
  207. data/spec/watirspec/elements/table_spec.rb +156 -156
  208. data/spec/watirspec/elements/tables_spec.rb +42 -42
  209. data/spec/watirspec/elements/tbody_spec.rb +93 -93
  210. data/spec/watirspec/elements/tbodys_spec.rb +62 -62
  211. data/spec/watirspec/elements/td_spec.rb +93 -93
  212. data/spec/watirspec/elements/tds_spec.rb +53 -53
  213. data/spec/watirspec/elements/text_field_spec.rb +360 -360
  214. data/spec/watirspec/elements/text_fields_spec.rb +44 -44
  215. data/spec/watirspec/elements/textarea_spec.rb +26 -26
  216. data/spec/watirspec/elements/textareas_spec.rb +24 -24
  217. data/spec/watirspec/elements/tfoot_spec.rb +86 -86
  218. data/spec/watirspec/elements/tfoots_spec.rb +68 -68
  219. data/spec/watirspec/elements/thead_spec.rb +86 -86
  220. data/spec/watirspec/elements/theads_spec.rb +68 -68
  221. data/spec/watirspec/elements/tr_spec.rb +78 -78
  222. data/spec/watirspec/elements/trs_spec.rb +61 -61
  223. data/spec/watirspec/elements/ul_spec.rb +76 -76
  224. data/spec/watirspec/elements/uls_spec.rb +39 -39
  225. data/spec/watirspec/html/alerts.html +12 -12
  226. data/spec/watirspec/html/aria_attributes.html +9 -9
  227. data/spec/watirspec/html/class_locator.html +8 -8
  228. data/spec/watirspec/html/clicks.html +19 -19
  229. data/spec/watirspec/html/closeable.html +12 -12
  230. data/spec/watirspec/html/collections.html +14 -14
  231. data/spec/watirspec/html/css/jquery-ui-1.8.17.custom.css +286 -286
  232. data/spec/watirspec/html/data_attributes.html +9 -9
  233. data/spec/watirspec/html/definition_lists.html +47 -47
  234. data/spec/watirspec/html/drag_and_drop.html +106 -106
  235. data/spec/watirspec/html/font.html +10 -10
  236. data/spec/watirspec/html/forms_with_input_elements.html +174 -174
  237. data/spec/watirspec/html/frame_1.html +22 -22
  238. data/spec/watirspec/html/frame_2.html +15 -15
  239. data/spec/watirspec/html/frames.html +10 -10
  240. data/spec/watirspec/html/hover.html +11 -11
  241. data/spec/watirspec/html/iframe_1.html +22 -22
  242. data/spec/watirspec/html/iframes.html +12 -12
  243. data/spec/watirspec/html/images.html +27 -27
  244. data/spec/watirspec/html/inner_outer.html +4 -4
  245. data/spec/watirspec/html/javascript/angular.min.js +331 -331
  246. data/spec/watirspec/html/javascript/helpers.js +16 -16
  247. data/spec/watirspec/html/javascript/jquery-1.7.1.min.js +3 -3
  248. data/spec/watirspec/html/javascript/jquery-ui-1.8.17.custom.min.js +67 -67
  249. data/spec/watirspec/html/keylogger.html +14 -14
  250. data/spec/watirspec/html/modal_dialog.html +9 -9
  251. data/spec/watirspec/html/multiple_ids.html +14 -14
  252. data/spec/watirspec/html/nested_elements.html +33 -33
  253. data/spec/watirspec/html/nested_frame_2.html +9 -9
  254. data/spec/watirspec/html/nested_frame_3.html +14 -14
  255. data/spec/watirspec/html/nested_frames.html +10 -10
  256. data/spec/watirspec/html/nested_iframe_2.html +12 -12
  257. data/spec/watirspec/html/nested_iframes.html +13 -13
  258. data/spec/watirspec/html/nested_tables.html +202 -202
  259. data/spec/watirspec/html/non_control_elements.html +140 -140
  260. data/spec/watirspec/html/removed_element.html +24 -24
  261. data/spec/watirspec/html/right_click.html +10 -10
  262. data/spec/watirspec/html/special_chars.html +11 -11
  263. data/spec/watirspec/html/tables.html +120 -120
  264. data/spec/watirspec/html/timeout_window_location.html +19 -19
  265. data/spec/watirspec/html/uneven_table.html +20 -20
  266. data/spec/watirspec/html/wait.html +84 -84
  267. data/spec/watirspec/html/window_switching.html +11 -11
  268. data/spec/watirspec/radio_set_spec.rb +336 -336
  269. data/spec/watirspec/relaxed_locate_spec.rb +99 -99
  270. data/spec/watirspec/screenshot_spec.rb +29 -29
  271. data/spec/watirspec/support/raise_exception_matchers.rb +36 -36
  272. data/spec/watirspec/wait_spec.rb +381 -381
  273. data/spec/watirspec/window_switching_spec.rb +415 -415
  274. data/spec/watirspec_helper.rb +161 -161
  275. data/support/appveyor.cmd +9 -9
  276. data/support/doctest_helper.rb +101 -101
  277. data/support/travis.sh +11 -11
  278. data/support/version_differ.rb +59 -59
  279. data/watir.gemspec +1 -1
  280. metadata +4 -170
@@ -1,52 +1,52 @@
1
- module Watir
2
- module Wait
3
- class Timer
4
-
5
- def initialize(timeout: nil)
6
- @end_time = current_time + timeout if timeout
7
- @remaining_time = @end_time - current_time if @end_time
8
- end
9
-
10
- #
11
- # Executes given block until it returns true or exceeds timeout.
12
- # @param [Integer] timeout
13
- # @yield block
14
- # @api private
15
- #
16
-
17
- def wait(timeout, &block)
18
- end_time = @end_time || current_time + timeout
19
- loop do
20
- yield(block)
21
- @remaining_time = end_time - current_time
22
- break if @remaining_time < 0
23
- end
24
- end
25
-
26
- def remaining_time
27
- @end_time - current_time
28
- end
29
-
30
- def reset!
31
- @end_time = nil
32
- end
33
-
34
- def locked?
35
- !@end_time.nil?
36
- end
37
-
38
- private
39
-
40
- if defined?(Process::CLOCK_MONOTONIC)
41
- def current_time
42
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
43
- end
44
- else
45
- def current_time
46
- ::Time.now.to_f
47
- end
48
- end
49
-
50
- end # Timer
51
- end # Wait
52
- end # Watir
1
+ module Watir
2
+ module Wait
3
+ class Timer
4
+
5
+ def initialize(timeout: nil)
6
+ @end_time = current_time + timeout if timeout
7
+ @remaining_time = @end_time - current_time if @end_time
8
+ end
9
+
10
+ #
11
+ # Executes given block until it returns true or exceeds timeout.
12
+ # @param [Integer] timeout
13
+ # @yield block
14
+ # @api private
15
+ #
16
+
17
+ def wait(timeout, &block)
18
+ end_time = @end_time || current_time + timeout
19
+ loop do
20
+ yield(block)
21
+ @remaining_time = end_time - current_time
22
+ break if @remaining_time < 0
23
+ end
24
+ end
25
+
26
+ def remaining_time
27
+ @end_time - current_time
28
+ end
29
+
30
+ def reset!
31
+ @end_time = nil
32
+ end
33
+
34
+ def locked?
35
+ !@end_time.nil?
36
+ end
37
+
38
+ private
39
+
40
+ if defined?(Process::CLOCK_MONOTONIC)
41
+ def current_time
42
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
43
+ end
44
+ else
45
+ def current_time
46
+ ::Time.now.to_f
47
+ end
48
+ end
49
+
50
+ end # Timer
51
+ end # Wait
52
+ end # Watir
@@ -1,257 +1,257 @@
1
- module Watir
2
- class Window
3
- include EventuallyPresent
4
- include Waitable
5
-
6
- def initialize(browser, selector)
7
- @browser = browser
8
- @driver = browser.driver
9
- @selector = selector
10
-
11
- if selector.empty?
12
- @handle = current_window
13
- elsif selector.key? :handle
14
- @handle = selector.delete :handle
15
- else
16
- unless selector.keys.all? { |k| [:title, :url, :index].include? k }
17
- raise ArgumentError, "invalid window selector: #{selector.inspect}"
18
- end
19
- end
20
- end
21
-
22
- def inspect
23
- '#<%s:0x%x located=%s>' % [self.class, hash*2, !!@handle]
24
- end
25
-
26
- #
27
- # Returns window size.
28
- #
29
- # @example
30
- # size = browser.window.size
31
- # [size.width, size.height] #=> [1600, 1200]
32
- #
33
-
34
- def size
35
- size = nil
36
- use { size = @driver.manage.window.size }
37
-
38
- size
39
- end
40
-
41
- #
42
- # Returns window position.
43
- #
44
- # @example
45
- # position = browser.window.position
46
- # [position.x, position.y] #=> [92, 76]
47
- #
48
-
49
- def position
50
- pos = nil
51
- use { pos = @driver.manage.window.position }
52
-
53
- pos
54
- end
55
-
56
- #
57
- # Resizes window to given width and height.
58
- #
59
- # @example
60
- # browser.window.resize_to 1600, 1200
61
- #
62
- # @param [Integer] width
63
- # @param [Integer] height
64
- #
65
-
66
- def resize_to(width, height)
67
- dimension = Selenium::WebDriver::Dimension.new(Integer(width), Integer(height))
68
- use { @driver.manage.window.size = dimension }
69
-
70
- dimension
71
- end
72
-
73
- #
74
- # Moves window to given x and y coordinates.
75
- #
76
- # @example
77
- # browser.window.move_to 300, 200
78
- #
79
- # @param [Integer] x
80
- # @param [Integer] y
81
- #
82
-
83
- def move_to(x, y)
84
- point = Selenium::WebDriver::Point.new(Integer(x), Integer(y))
85
- use { @driver.manage.window.position = point }
86
-
87
- point
88
- end
89
-
90
- #
91
- # Maximizes window.
92
- #
93
- # @example
94
- # browser.window.maximize
95
- #
96
-
97
- def maximize
98
- use { @driver.manage.window.maximize }
99
- end
100
-
101
- #
102
- # Returns true if window exists.
103
- #
104
- # @return [Boolean]
105
- #
106
-
107
- def exists?
108
- assert_exists
109
- true
110
- rescue Exception::NoMatchingWindowFoundException
111
- false
112
- end
113
-
114
- alias_method :present?, :exists?
115
- alias_method :exist?, :exists?
116
-
117
- #
118
- # Returns true if two windows are equal.
119
- #
120
- # @example
121
- # browser.window(index: 0) == browser.window(index: 1)
122
- # #=> false
123
- #
124
- # @param [Window] other
125
- #
126
-
127
- def ==(other)
128
- return false unless other.kind_of?(self.class)
129
-
130
- handle == other.handle
131
- end
132
- alias_method :eql?, :==
133
-
134
- def hash
135
- handle.hash ^ self.class.hash
136
- end
137
-
138
- #
139
- # Returns true if window is current.
140
- #
141
- # @example
142
- # browser.window.current?
143
- # #=> true
144
- #
145
-
146
- def current?
147
- current_window == handle
148
- end
149
-
150
- #
151
- # Closes window.
152
- #
153
-
154
- def close
155
- @browser.original_window = nil if self == @browser.original_window
156
- use { @driver.close }
157
- end
158
-
159
- #
160
- # Returns window title.
161
- #
162
- # @return [String]
163
- #
164
-
165
- def title
166
- title = nil
167
- use { title = @driver.title }
168
-
169
- title
170
- end
171
-
172
- #
173
- # Returns window URL.
174
- #
175
- # @return [String]
176
- #
177
-
178
- def url
179
- url = nil
180
- use { url = @driver.current_url }
181
-
182
- url
183
- end
184
-
185
- #
186
- # Switches to given window and executes block, then switches back.
187
- #
188
- # @example
189
- # browser.window(title: "closeable window").use do
190
- # browser.a(id: "close").click
191
- # end
192
- #
193
-
194
- def use(&blk)
195
- @browser.original_window ||= current_window
196
- wait_for_exists
197
- @driver.switch_to.window(handle, &blk)
198
- self
199
- end
200
-
201
- protected
202
-
203
- def handle
204
- @handle ||= locate
205
- end
206
-
207
- # Referenced in EventuallyPresent
208
- def selector_string
209
- @selector.inspect
210
- end
211
-
212
- private
213
-
214
- def locate
215
- if @selector.empty?
216
- nil
217
- elsif @selector.key?(:index)
218
- @driver.window_handles[Integer(@selector[:index])]
219
- else
220
- @driver.window_handles.find { |wh| matches?(wh) }
221
- end
222
- end
223
-
224
- def assert_exists
225
- raise(Exception::NoMatchingWindowFoundException, @selector.inspect) unless @driver.window_handles.include?(handle)
226
- end
227
-
228
- # return a handle to the currently active window if it is still open; otherwise nil
229
- def current_window
230
- @driver.window_handle
231
- rescue Selenium::WebDriver::Error::NoSuchWindowError
232
- nil
233
- end
234
-
235
- def matches?(handle)
236
- @driver.switch_to.window(handle) {
237
- matches_title = @selector[:title].nil? || @selector[:title] === @driver.title
238
- matches_url = @selector[:url].nil? || @selector[:url] === @driver.current_url
239
-
240
- matches_title && matches_url
241
- }
242
- rescue Selenium::WebDriver::Error::NoSuchWindowError, Selenium::WebDriver::Error::NoSuchDriverError
243
- # the window may disappear while we're iterating.
244
- false
245
- end
246
-
247
- def wait_for_exists
248
- return assert_exists unless Watir.relaxed_locate?
249
- begin
250
- wait_until(&:exists?)
251
- rescue Wait::TimeoutError
252
- raise Exception::NoMatchingWindowFoundException, @selector.inspect
253
- end
254
- end
255
-
256
- end # Window
257
- end # Watir
1
+ module Watir
2
+ class Window
3
+ include EventuallyPresent
4
+ include Waitable
5
+
6
+ def initialize(browser, selector)
7
+ @browser = browser
8
+ @driver = browser.driver
9
+ @selector = selector
10
+
11
+ if selector.empty?
12
+ @handle = current_window
13
+ elsif selector.key? :handle
14
+ @handle = selector.delete :handle
15
+ else
16
+ unless selector.keys.all? { |k| [:title, :url, :index].include? k }
17
+ raise ArgumentError, "invalid window selector: #{selector.inspect}"
18
+ end
19
+ end
20
+ end
21
+
22
+ def inspect
23
+ '#<%s:0x%x located=%s>' % [self.class, hash*2, !!@handle]
24
+ end
25
+
26
+ #
27
+ # Returns window size.
28
+ #
29
+ # @example
30
+ # size = browser.window.size
31
+ # [size.width, size.height] #=> [1600, 1200]
32
+ #
33
+
34
+ def size
35
+ size = nil
36
+ use { size = @driver.manage.window.size }
37
+
38
+ size
39
+ end
40
+
41
+ #
42
+ # Returns window position.
43
+ #
44
+ # @example
45
+ # position = browser.window.position
46
+ # [position.x, position.y] #=> [92, 76]
47
+ #
48
+
49
+ def position
50
+ pos = nil
51
+ use { pos = @driver.manage.window.position }
52
+
53
+ pos
54
+ end
55
+
56
+ #
57
+ # Resizes window to given width and height.
58
+ #
59
+ # @example
60
+ # browser.window.resize_to 1600, 1200
61
+ #
62
+ # @param [Integer] width
63
+ # @param [Integer] height
64
+ #
65
+
66
+ def resize_to(width, height)
67
+ dimension = Selenium::WebDriver::Dimension.new(Integer(width), Integer(height))
68
+ use { @driver.manage.window.size = dimension }
69
+
70
+ dimension
71
+ end
72
+
73
+ #
74
+ # Moves window to given x and y coordinates.
75
+ #
76
+ # @example
77
+ # browser.window.move_to 300, 200
78
+ #
79
+ # @param [Integer] x
80
+ # @param [Integer] y
81
+ #
82
+
83
+ def move_to(x, y)
84
+ point = Selenium::WebDriver::Point.new(Integer(x), Integer(y))
85
+ use { @driver.manage.window.position = point }
86
+
87
+ point
88
+ end
89
+
90
+ #
91
+ # Maximizes window.
92
+ #
93
+ # @example
94
+ # browser.window.maximize
95
+ #
96
+
97
+ def maximize
98
+ use { @driver.manage.window.maximize }
99
+ end
100
+
101
+ #
102
+ # Returns true if window exists.
103
+ #
104
+ # @return [Boolean]
105
+ #
106
+
107
+ def exists?
108
+ assert_exists
109
+ true
110
+ rescue Exception::NoMatchingWindowFoundException
111
+ false
112
+ end
113
+
114
+ alias_method :present?, :exists?
115
+ alias_method :exist?, :exists?
116
+
117
+ #
118
+ # Returns true if two windows are equal.
119
+ #
120
+ # @example
121
+ # browser.window(index: 0) == browser.window(index: 1)
122
+ # #=> false
123
+ #
124
+ # @param [Window] other
125
+ #
126
+
127
+ def ==(other)
128
+ return false unless other.kind_of?(self.class)
129
+
130
+ handle == other.handle
131
+ end
132
+ alias_method :eql?, :==
133
+
134
+ def hash
135
+ handle.hash ^ self.class.hash
136
+ end
137
+
138
+ #
139
+ # Returns true if window is current.
140
+ #
141
+ # @example
142
+ # browser.window.current?
143
+ # #=> true
144
+ #
145
+
146
+ def current?
147
+ current_window == handle
148
+ end
149
+
150
+ #
151
+ # Closes window.
152
+ #
153
+
154
+ def close
155
+ @browser.original_window = nil if self == @browser.original_window
156
+ use { @driver.close }
157
+ end
158
+
159
+ #
160
+ # Returns window title.
161
+ #
162
+ # @return [String]
163
+ #
164
+
165
+ def title
166
+ title = nil
167
+ use { title = @driver.title }
168
+
169
+ title
170
+ end
171
+
172
+ #
173
+ # Returns window URL.
174
+ #
175
+ # @return [String]
176
+ #
177
+
178
+ def url
179
+ url = nil
180
+ use { url = @driver.current_url }
181
+
182
+ url
183
+ end
184
+
185
+ #
186
+ # Switches to given window and executes block, then switches back.
187
+ #
188
+ # @example
189
+ # browser.window(title: "closeable window").use do
190
+ # browser.a(id: "close").click
191
+ # end
192
+ #
193
+
194
+ def use(&blk)
195
+ @browser.original_window ||= current_window
196
+ wait_for_exists
197
+ @driver.switch_to.window(handle, &blk)
198
+ self
199
+ end
200
+
201
+ protected
202
+
203
+ def handle
204
+ @handle ||= locate
205
+ end
206
+
207
+ # Referenced in EventuallyPresent
208
+ def selector_string
209
+ @selector.inspect
210
+ end
211
+
212
+ private
213
+
214
+ def locate
215
+ if @selector.empty?
216
+ nil
217
+ elsif @selector.key?(:index)
218
+ @driver.window_handles[Integer(@selector[:index])]
219
+ else
220
+ @driver.window_handles.find { |wh| matches?(wh) }
221
+ end
222
+ end
223
+
224
+ def assert_exists
225
+ raise(Exception::NoMatchingWindowFoundException, @selector.inspect) unless @driver.window_handles.include?(handle)
226
+ end
227
+
228
+ # return a handle to the currently active window if it is still open; otherwise nil
229
+ def current_window
230
+ @driver.window_handle
231
+ rescue Selenium::WebDriver::Error::NoSuchWindowError
232
+ nil
233
+ end
234
+
235
+ def matches?(handle)
236
+ @driver.switch_to.window(handle) {
237
+ matches_title = @selector[:title].nil? || @selector[:title] === @driver.title
238
+ matches_url = @selector[:url].nil? || @selector[:url] === @driver.current_url
239
+
240
+ matches_title && matches_url
241
+ }
242
+ rescue Selenium::WebDriver::Error::NoSuchWindowError, Selenium::WebDriver::Error::NoSuchDriverError
243
+ # the window may disappear while we're iterating.
244
+ false
245
+ end
246
+
247
+ def wait_for_exists
248
+ return assert_exists unless Watir.relaxed_locate?
249
+ begin
250
+ wait_until(&:exists?)
251
+ rescue Wait::TimeoutError
252
+ raise Exception::NoMatchingWindowFoundException, @selector.inspect
253
+ end
254
+ end
255
+
256
+ end # Window
257
+ end # Watir