watir 7.0.0 → 7.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +29 -16
  3. data/.github/workflows/edge.yml +19 -11
  4. data/.github/workflows/firefox.yml +28 -16
  5. data/.github/workflows/ie.yml +13 -7
  6. data/.github/workflows/safari.yml +22 -11
  7. data/.github/workflows/unit.yml +31 -23
  8. data/.rubocop.yml +33 -13
  9. data/.rubocop_todo.yml +7 -26
  10. data/CHANGES.md +33 -0
  11. data/Gemfile +6 -1
  12. data/LICENSE +2 -2
  13. data/README.md +15 -11
  14. data/Rakefile +9 -7
  15. data/lib/watir/adjacent.rb +3 -1
  16. data/lib/watir/after_hooks.rb +5 -3
  17. data/lib/watir/alert.rb +2 -0
  18. data/lib/watir/aliases.rb +2 -0
  19. data/lib/watir/attribute_helper.rb +4 -2
  20. data/lib/watir/browser.rb +10 -14
  21. data/lib/watir/capabilities.rb +53 -33
  22. data/lib/watir/cell_container.rb +2 -0
  23. data/lib/watir/container.rb +2 -0
  24. data/lib/watir/cookies.rb +5 -5
  25. data/lib/watir/element_collection.rb +3 -1
  26. data/lib/watir/elements/button.rb +2 -0
  27. data/lib/watir/elements/cell.rb +2 -0
  28. data/lib/watir/elements/checkbox.rb +2 -0
  29. data/lib/watir/elements/date_field.rb +2 -0
  30. data/lib/watir/elements/date_time_field.rb +2 -0
  31. data/lib/watir/elements/dlist.rb +3 -1
  32. data/lib/watir/elements/element.rb +68 -118
  33. data/lib/watir/elements/file_field.rb +2 -0
  34. data/lib/watir/elements/font.rb +2 -0
  35. data/lib/watir/elements/form.rb +2 -0
  36. data/lib/watir/elements/hidden.rb +2 -0
  37. data/lib/watir/elements/iframe.rb +2 -0
  38. data/lib/watir/elements/image.rb +2 -0
  39. data/lib/watir/elements/input.rb +2 -0
  40. data/lib/watir/elements/link.rb +2 -0
  41. data/lib/watir/elements/list.rb +2 -0
  42. data/lib/watir/elements/option.rb +2 -0
  43. data/lib/watir/elements/radio.rb +2 -0
  44. data/lib/watir/elements/row.rb +2 -0
  45. data/lib/watir/elements/select.rb +2 -0
  46. data/lib/watir/elements/table.rb +3 -1
  47. data/lib/watir/elements/table_cell.rb +2 -0
  48. data/lib/watir/elements/table_row.rb +2 -0
  49. data/lib/watir/elements/table_section.rb +2 -0
  50. data/lib/watir/elements/text_area.rb +2 -0
  51. data/lib/watir/elements/text_field.rb +2 -0
  52. data/lib/watir/exception.rb +2 -0
  53. data/lib/watir/extensions/nokogiri.rb +2 -0
  54. data/lib/watir/generator/base/generator.rb +2 -0
  55. data/lib/watir/generator/base/idl_sorter.rb +3 -1
  56. data/lib/watir/generator/base/spec_extractor.rb +6 -4
  57. data/lib/watir/generator/base/util.rb +2 -0
  58. data/lib/watir/generator/base/visitor.rb +5 -5
  59. data/lib/watir/generator/base.rb +2 -1
  60. data/lib/watir/generator/html/generator.rb +2 -0
  61. data/lib/watir/generator/html/spec_extractor.rb +2 -0
  62. data/lib/watir/generator/html/visitor.rb +2 -0
  63. data/lib/watir/generator/html.rb +2 -0
  64. data/lib/watir/generator/svg/generator.rb +2 -0
  65. data/lib/watir/generator/svg/spec_extractor.rb +2 -0
  66. data/lib/watir/generator/svg/visitor.rb +2 -0
  67. data/lib/watir/generator/svg.rb +2 -0
  68. data/lib/watir/generator.rb +2 -0
  69. data/lib/watir/has_window.rb +3 -1
  70. data/lib/watir/http_client.rb +2 -0
  71. data/lib/watir/js_execution.rb +2 -0
  72. data/lib/watir/js_snippets/isElementInViewport.js +20 -0
  73. data/lib/watir/js_snippets.rb +2 -0
  74. data/lib/watir/locators/anchor/selector_builder.rb +5 -0
  75. data/lib/watir/locators/button/matcher.rb +2 -0
  76. data/lib/watir/locators/button/selector_builder/xpath.rb +15 -19
  77. data/lib/watir/locators/button/selector_builder.rb +2 -0
  78. data/lib/watir/locators/cell/selector_builder/xpath.rb +2 -0
  79. data/lib/watir/locators/cell/selector_builder.rb +2 -0
  80. data/lib/watir/locators/element/locator.rb +2 -0
  81. data/lib/watir/locators/element/matcher.rb +4 -1
  82. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +4 -1
  83. data/lib/watir/locators/element/selector_builder/xpath.rb +16 -15
  84. data/lib/watir/locators/element/selector_builder/xpath_support.rb +4 -2
  85. data/lib/watir/locators/element/selector_builder.rb +16 -6
  86. data/lib/watir/locators/option/matcher.rb +2 -0
  87. data/lib/watir/locators/option/selector_builder/xpath.rb +2 -0
  88. data/lib/watir/locators/option/selector_builder.rb +2 -0
  89. data/lib/watir/locators/row/selector_builder/xpath.rb +2 -0
  90. data/lib/watir/locators/row/selector_builder.rb +2 -0
  91. data/lib/watir/locators/text_area/selector_builder/xpath.rb +2 -0
  92. data/lib/watir/locators/text_area/selector_builder.rb +2 -0
  93. data/lib/watir/locators/text_field/matcher.rb +2 -4
  94. data/lib/watir/locators/text_field/selector_builder/xpath.rb +2 -0
  95. data/lib/watir/locators/text_field/selector_builder.rb +2 -0
  96. data/lib/watir/locators.rb +2 -0
  97. data/lib/watir/logger.rb +2 -0
  98. data/lib/watir/navigation.rb +3 -1
  99. data/lib/watir/radio_set.rb +2 -0
  100. data/lib/watir/row_container.rb +2 -0
  101. data/lib/watir/screenshot.rb +2 -0
  102. data/lib/watir/scroll.rb +29 -3
  103. data/lib/watir/search_context.rb +96 -0
  104. data/lib/watir/shadow_root.rb +60 -0
  105. data/lib/watir/user_editable.rb +3 -1
  106. data/lib/watir/version.rb +3 -1
  107. data/lib/watir/wait/timer.rb +3 -1
  108. data/lib/watir/wait.rb +5 -5
  109. data/lib/watir/window.rb +7 -3
  110. data/lib/watir/window_collection.rb +4 -1
  111. data/lib/watir.rb +4 -0
  112. data/lib/watirspec/guards.rb +2 -0
  113. data/lib/watirspec/implementation.rb +14 -10
  114. data/lib/watirspec/rake_tasks.rb +4 -4
  115. data/lib/watirspec/remote_server.rb +5 -3
  116. data/lib/watirspec/runner.rb +3 -1
  117. data/lib/watirspec/server/app.rb +2 -0
  118. data/lib/watirspec/server.rb +2 -0
  119. data/lib/watirspec.rb +7 -4
  120. data/spec/locator_spec_helper.rb +2 -8
  121. data/spec/spec_helper.rb +2 -0
  122. data/spec/unit/capabilities_spec.rb +561 -550
  123. data/spec/unit/element_locator_spec.rb +71 -58
  124. data/spec/unit/match_elements/button_spec.rb +58 -49
  125. data/spec/unit/match_elements/element_spec.rb +305 -309
  126. data/spec/unit/match_elements/text_field_spec.rb +78 -73
  127. data/spec/unit/selector_builder/anchor_spec.rb +41 -33
  128. data/spec/unit/selector_builder/button_spec.rb +211 -201
  129. data/spec/unit/selector_builder/cell_spec.rb +50 -42
  130. data/spec/unit/selector_builder/element_spec.rb +636 -628
  131. data/spec/unit/selector_builder/row_spec.rb +121 -104
  132. data/spec/unit/selector_builder/text_field_spec.rb +197 -182
  133. data/spec/unit/selector_builder/textarea_spec.rb +24 -14
  134. data/spec/unit/unit_helper.rb +2 -0
  135. data/spec/unit/wait_spec.rb +77 -71
  136. data/spec/watirspec/adjacent_spec.rb +251 -247
  137. data/spec/watirspec/after_hooks_spec.rb +160 -162
  138. data/spec/watirspec/alert_spec.rb +63 -58
  139. data/spec/watirspec/browser_spec.rb +411 -407
  140. data/spec/watirspec/capabilities_spec.rb +566 -0
  141. data/spec/watirspec/cookies_spec.rb +122 -118
  142. data/spec/watirspec/drag_and_drop_spec.rb +30 -14
  143. data/spec/watirspec/element_hidden_spec.rb +68 -60
  144. data/spec/watirspec/elements/area_spec.rb +51 -47
  145. data/spec/watirspec/elements/areas_spec.rb +29 -25
  146. data/spec/watirspec/elements/button_spec.rb +255 -251
  147. data/spec/watirspec/elements/buttons_spec.rb +38 -34
  148. data/spec/watirspec/elements/checkbox_spec.rb +50 -36
  149. data/spec/watirspec/elements/checkboxes_spec.rb +31 -27
  150. data/spec/watirspec/elements/collections_spec.rb +128 -119
  151. data/spec/watirspec/elements/date_field_spec.rb +187 -183
  152. data/spec/watirspec/elements/date_fields_spec.rb +31 -27
  153. data/spec/watirspec/elements/date_time_field_spec.rb +199 -195
  154. data/spec/watirspec/elements/date_time_fields_spec.rb +32 -28
  155. data/spec/watirspec/elements/dd_spec.rb +89 -85
  156. data/spec/watirspec/elements/dds_spec.rb +29 -25
  157. data/spec/watirspec/elements/del_spec.rb +108 -104
  158. data/spec/watirspec/elements/dels_spec.rb +28 -24
  159. data/spec/watirspec/elements/div_spec.rb +227 -211
  160. data/spec/watirspec/elements/divs_spec.rb +39 -35
  161. data/spec/watirspec/elements/dl_spec.rb +112 -110
  162. data/spec/watirspec/elements/dls_spec.rb +30 -26
  163. data/spec/watirspec/elements/dt_spec.rb +88 -84
  164. data/spec/watirspec/elements/dts_spec.rb +29 -25
  165. data/spec/watirspec/elements/element_spec.rb +815 -715
  166. data/spec/watirspec/elements/elements_spec.rb +42 -38
  167. data/spec/watirspec/elements/em_spec.rb +64 -60
  168. data/spec/watirspec/elements/ems_spec.rb +30 -26
  169. data/spec/watirspec/elements/filefield_spec.rb +100 -96
  170. data/spec/watirspec/elements/filefields_spec.rb +30 -26
  171. data/spec/watirspec/elements/font_spec.rb +22 -18
  172. data/spec/watirspec/elements/form_spec.rb +53 -49
  173. data/spec/watirspec/elements/forms_spec.rb +31 -27
  174. data/spec/watirspec/elements/frame_spec.rb +91 -87
  175. data/spec/watirspec/elements/frames_spec.rb +29 -25
  176. data/spec/watirspec/elements/hidden_spec.rb +81 -77
  177. data/spec/watirspec/elements/hiddens_spec.rb +30 -26
  178. data/spec/watirspec/elements/hn_spec.rb +61 -57
  179. data/spec/watirspec/elements/hns_spec.rb +28 -24
  180. data/spec/watirspec/elements/iframe_spec.rb +197 -191
  181. data/spec/watirspec/elements/iframes_spec.rb +33 -29
  182. data/spec/watirspec/elements/image_spec.rb +146 -142
  183. data/spec/watirspec/elements/images_spec.rb +28 -24
  184. data/spec/watirspec/elements/input_spec.rb +11 -7
  185. data/spec/watirspec/elements/ins_spec.rb +108 -104
  186. data/spec/watirspec/elements/inses_spec.rb +28 -24
  187. data/spec/watirspec/elements/label_spec.rb +58 -54
  188. data/spec/watirspec/elements/labels_spec.rb +28 -24
  189. data/spec/watirspec/elements/li_spec.rb +76 -72
  190. data/spec/watirspec/elements/link_spec.rb +175 -179
  191. data/spec/watirspec/elements/links_spec.rb +47 -43
  192. data/spec/watirspec/elements/lis_spec.rb +29 -25
  193. data/spec/watirspec/elements/list_spec.rb +46 -42
  194. data/spec/watirspec/elements/map_spec.rb +59 -55
  195. data/spec/watirspec/elements/maps_spec.rb +29 -25
  196. data/spec/watirspec/elements/meta_spec.rb +18 -14
  197. data/spec/watirspec/elements/metas_spec.rb +28 -24
  198. data/spec/watirspec/elements/ol_spec.rb +58 -65
  199. data/spec/watirspec/elements/ols_spec.rb +28 -24
  200. data/spec/watirspec/elements/option_spec.rb +93 -89
  201. data/spec/watirspec/elements/p_spec.rb +79 -75
  202. data/spec/watirspec/elements/pre_spec.rb +77 -73
  203. data/spec/watirspec/elements/pres_spec.rb +28 -24
  204. data/spec/watirspec/elements/ps_spec.rb +28 -24
  205. data/spec/watirspec/elements/radio_spec.rb +253 -249
  206. data/spec/watirspec/elements/radios_spec.rb +30 -26
  207. data/spec/watirspec/elements/select_list_spec.rb +539 -522
  208. data/spec/watirspec/elements/select_lists_spec.rb +34 -30
  209. data/spec/watirspec/elements/span_spec.rb +114 -110
  210. data/spec/watirspec/elements/spans_spec.rb +28 -24
  211. data/spec/watirspec/elements/strong_spec.rb +60 -58
  212. data/spec/watirspec/elements/strongs_spec.rb +30 -26
  213. data/spec/watirspec/elements/table_spec.rb +194 -139
  214. data/spec/watirspec/elements/tables_spec.rb +30 -26
  215. data/spec/watirspec/elements/tbody_spec.rb +71 -67
  216. data/spec/watirspec/elements/tbodys_spec.rb +42 -38
  217. data/spec/watirspec/elements/td_spec.rb +68 -64
  218. data/spec/watirspec/elements/tds_spec.rb +43 -39
  219. data/spec/watirspec/elements/text_field_spec.rb +208 -204
  220. data/spec/watirspec/elements/text_fields_spec.rb +32 -28
  221. data/spec/watirspec/elements/textarea_spec.rb +22 -18
  222. data/spec/watirspec/elements/textareas_spec.rb +20 -16
  223. data/spec/watirspec/elements/tfoot_spec.rb +67 -63
  224. data/spec/watirspec/elements/tfoots_spec.rb +44 -40
  225. data/spec/watirspec/elements/thead_spec.rb +67 -63
  226. data/spec/watirspec/elements/theads_spec.rb +44 -40
  227. data/spec/watirspec/elements/tr_spec.rb +50 -46
  228. data/spec/watirspec/elements/trs_spec.rb +44 -40
  229. data/spec/watirspec/elements/ul_spec.rb +58 -54
  230. data/spec/watirspec/elements/uls_spec.rb +28 -24
  231. data/spec/watirspec/html/child_frame.html +29 -0
  232. data/spec/watirspec/html/class_locator.html +2 -0
  233. data/spec/watirspec/html/scroll.html +8 -25
  234. data/spec/watirspec/html/scroll_nested.html +17 -0
  235. data/spec/watirspec/html/scroll_nested_offscreen.html +18 -0
  236. data/spec/watirspec/html/shadow_dom.html +28 -0
  237. data/spec/watirspec/html/sticky_elements.html +10 -0
  238. data/spec/watirspec/radio_set_spec.rb +271 -267
  239. data/spec/watirspec/screenshot_spec.rb +22 -18
  240. data/spec/watirspec/scroll_spec.rb +179 -77
  241. data/spec/watirspec/shadow_root_spec.rb +106 -0
  242. data/spec/watirspec/support/rspec_matchers.rb +35 -32
  243. data/spec/watirspec/user_editable_spec.rb +202 -198
  244. data/spec/watirspec/wait_spec.rb +291 -295
  245. data/spec/watirspec/window_switching_spec.rb +426 -428
  246. data/spec/watirspec_helper.rb +25 -42
  247. data/support/doctest_helper.rb +2 -0
  248. data/support/version_differ.rb +2 -0
  249. data/watir.gemspec +14 -10
  250. metadata +91 -240
  251. data/.github/actions/enable-safari/action.yml +0 -11
  252. data/.github/actions/install-chrome/action.yml +0 -12
  253. data/.github/actions/setup-linux/action.yml +0 -8
  254. data/lib/watir-webdriver.rb +0 -2
  255. data/spec/watirspec/attributes_spec.rb +0 -16
  256. data/spec/watirspec/elements/table_nesting_spec.rb +0 -49
  257. data/spec/watirspec/html/hover.html +0 -12
  258. data/spec/watirspec/special_chars_spec.rb +0 -21
@@ -1,581 +1,579 @@
1
- require 'watirspec_helper'
2
-
3
- describe Watir::Browser do
4
- before do
5
- browser.goto WatirSpec.url_for('window_switching.html')
6
- browser.a(id: 'open').click
7
- browser.windows.wait_until(size: 2)
8
- end
1
+ # frozen_string_literal: true
9
2
 
10
- after do
11
- browser.windows.restore!
12
- end
3
+ require 'watirspec_helper'
13
4
 
14
- describe '#windows' do
15
- it 'returns a WindowCollection' do
16
- expect(browser.windows).to be_a(Watir::WindowCollection)
5
+ module Watir
6
+ describe Browser, exclude: {browser: :ie, reason: 'Cannot call #restore!'} do
7
+ before do
8
+ browser.goto WatirSpec.url_for('window_switching.html')
9
+ browser.a(id: 'open').click
10
+ browser.windows.wait_until(size: 2)
17
11
  end
18
12
 
19
- it 'stores Window instances' do
20
- expect(browser.windows(title: 'closeable window')).to all(be_a(Watir::Window))
13
+ after do
14
+ browser.windows.restore!
21
15
  end
22
16
 
23
- it 'filters windows to match the given selector' do
24
- expect(browser.windows(title: 'closeable window').size).to eq 1
25
- end
17
+ describe '#windows' do
18
+ it 'returns a WindowCollection' do
19
+ expect(browser.windows).to be_a(WindowCollection)
20
+ end
26
21
 
27
- it 'raises ArgumentError if the selector is invalid' do
28
- expect { browser.windows(name: 'foo') }.to raise_error(ArgumentError)
29
- end
22
+ it 'stores Window instances' do
23
+ expect(browser.windows(title: 'closeable window')).to all(be_a(Window))
24
+ end
30
25
 
31
- it 'returns an empty array if no window matches the selector' do
32
- expect(browser.windows(title: 'noop')).to be_empty
33
- end
34
- end
26
+ it 'filters windows to match the given selector' do
27
+ expect(browser.windows(title: 'closeable window').size).to eq 1
28
+ end
35
29
 
36
- describe '#window' do
37
- it 'finds window by :url' do
38
- expect(browser.window(url: /closeable\.html/).use).to be_a(Watir::Window)
39
- end
30
+ it 'raises ArgumentError if the selector is invalid' do
31
+ expect { browser.windows(name: 'foo') }.to raise_error(ArgumentError)
32
+ end
40
33
 
41
- it 'finds window by :title' do
42
- expect(browser.window(title: 'closeable window').use).to be_a(Watir::Window)
34
+ it 'returns an empty array if no window matches the selector' do
35
+ expect(browser.windows(title: 'noop')).to be_empty
36
+ end
43
37
  end
44
38
 
45
- it 'finds window by :element' do
46
- expect(browser.window(element: browser.a(id: 'close')).use).to be_a(Watir::Window)
47
- end
39
+ describe '#window' do
40
+ it 'finds window by :url' do
41
+ expect(browser.window(url: /closeable\.html/).use).to be_a(Window)
42
+ end
48
43
 
49
- it 'finds window by multiple values' do
50
- expect(browser.window(title: 'closeable window', url: /closeable\.html/).use).to be_a(Watir::Window)
51
- end
44
+ it 'finds window by :title' do
45
+ expect(browser.window(title: 'closeable window').use).to be_a(Window)
46
+ end
52
47
 
53
- it 'should not find incorrect handle' do
54
- expect(browser.window(handle: 'bar')).to_not be_present
55
- end
48
+ it 'finds window by :element' do
49
+ expect(browser.window(element: browser.a(id: 'close')).use).to be_a(Window)
50
+ end
56
51
 
57
- it 'returns the current window if no argument is given' do
58
- expect(browser.window.url).to match(/window_switching\.html/)
59
- end
52
+ it 'finds window by multiple values' do
53
+ expect(browser.window(title: 'closeable window', url: /closeable\.html/).use).to be_a(Window)
54
+ end
60
55
 
61
- it 'stores the reference to a window when no argument is given' do
62
- original_window = browser.window
63
- browser.window(title: 'closeable window').use
64
- expect(original_window.url).to match(/window_switching\.html/)
65
- end
56
+ it 'does not find incorrect handle' do
57
+ expect(browser.window(handle: 'bar')).not_to be_present
58
+ end
66
59
 
67
- it 'it executes the given block in the window',
68
- except: {browser: :safari,
69
- reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
70
- browser.window(title: 'closeable window') do
71
- link = browser.a(id: 'close')
72
- expect(link).to exist
73
- link.click
60
+ it 'returns the current window if no argument is given' do
61
+ expect(browser.window.url).to match(/window_switching\.html/)
74
62
  end
75
63
 
76
- expect { browser.windows.wait_until(size: 1) }.to_not raise_error
77
- end
64
+ it 'stores the reference to a window when no argument is given' do
65
+ original_window = browser.window
66
+ browser.window(title: 'closeable window').use
67
+ expect(original_window.url).to match(/window_switching\.html/)
68
+ end
78
69
 
79
- it 'raises ArgumentError if the selector is invalid' do
80
- expect { browser.window(name: 'foo') }.to raise_error(ArgumentError)
81
- end
70
+ it 'executes the given block in the window',
71
+ except: {browser: :safari,
72
+ reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
73
+ browser.window(title: 'closeable window') do
74
+ link = browser.a(id: 'close')
75
+ expect(link).to exist
76
+ link.click
77
+ end
82
78
 
83
- it 'raises a NoMatchingWindowFoundException error if no window matches the selector' do
84
- expect { browser.window(title: 'noop').use }.to raise_no_matching_window_exception
85
- end
79
+ expect { browser.windows.wait_until(size: 1) }.not_to raise_error
80
+ end
86
81
 
87
- it 'raises NoMatchingWindowFoundException error when attempting to use a window with an incorrect handle' do
88
- expect { browser.window(handle: 'bar').use }.to raise_no_matching_window_exception
89
- end
90
- end
82
+ it 'raises ArgumentError if the selector is invalid' do
83
+ expect { browser.window(name: 'foo') }.to raise_error(ArgumentError)
84
+ end
91
85
 
92
- describe '#switch_window' do
93
- it 'stays on the same window when matches single window' do
94
- browser.switch_window
95
- browser.window.close
96
- browser.original_window.use
86
+ it 'raises a NoMatchingWindowFoundException error if no window matches the selector' do
87
+ expect { browser.window(title: 'noop').use }.to raise_no_matching_window_exception
88
+ end
97
89
 
98
- title = browser.title
99
- expect { browser.window(title: title).use }.not_to raise_exception
90
+ it 'raises NoMatchingWindowFoundException error when attempting to use a window with an incorrect handle' do
91
+ expect { browser.window(handle: 'bar').use }.to raise_no_matching_window_exception
92
+ end
100
93
  end
101
94
 
102
- it 'switches to second window' do
103
- original_window = browser.window
104
- browser.switch_window
105
- new_window = browser.window
95
+ describe '#switch_window' do
96
+ it 'stays on the same window when matches single window' do
97
+ browser.switch_window
98
+ browser.window.close
99
+ browser.original_window.use
106
100
 
107
- expect(original_window).to_not eq new_window
108
- expect(browser.windows).to include(original_window, new_window)
109
- end
101
+ title = browser.title
102
+ expect { browser.window(title: title).use }.not_to raise_exception
103
+ end
110
104
 
111
- it 'returns an instance of Window' do
112
- expect(browser.switch_window).to be_a(Watir::Window)
113
- end
105
+ it 'switches to second window' do
106
+ original_window = browser.window
107
+ browser.switch_window
108
+ new_window = browser.window
114
109
 
115
- it 'times out if there is no second window' do
116
- browser.windows.restore!
117
- message = /waiting for true condition on (.*) title="window switching">$/
118
- expect { browser.switch_window }.to raise_timeout_exception(message)
119
- end
110
+ expect(original_window).not_to eq new_window
111
+ expect(browser.windows).to include(original_window, new_window)
112
+ end
120
113
 
121
- it 'provides previous window value to #original_window' do
122
- browser.switch_window
123
- expect(browser.original_window).to_not be_nil
124
- end
114
+ it 'returns an instance of Window' do
115
+ expect(browser.switch_window).to be_a(Window)
116
+ end
125
117
 
126
- it 'waits for second window', except: {browser: :ie} do
127
- browser.windows.restore!
128
- expect {
129
- browser.a(id: 'delayed').click
130
- browser.switch_window
131
- }.to execute_when_satisfied(min: 1)
132
- end
133
- end
134
- end
118
+ it 'times out if there is no second window' do
119
+ browser.windows.restore!
120
+ message = /waiting for true condition on (.*) title="window switching">$/
121
+ expect { browser.switch_window }.to raise_timeout_exception(message)
122
+ end
135
123
 
136
- describe Watir::Window do
137
- after do
138
- browser.windows.restore!
139
- end
124
+ it 'provides previous window value to #original_window' do
125
+ browser.switch_window
126
+ expect(browser.original_window).not_to be_nil
127
+ end
140
128
 
141
- context 'multiple windows' do
142
- before do
143
- browser.goto WatirSpec.url_for('window_switching.html')
144
- browser.a(id: 'open').click
145
- browser.windows.wait_until(size: 2)
129
+ it 'waits for second window' do
130
+ browser.windows.restore!
131
+ expect {
132
+ browser.a(id: 'delayed').click
133
+ browser.switch_window
134
+ }.to execute_when_satisfied(min: 1)
135
+ end
146
136
  end
137
+ end
147
138
 
148
- it 'allows actions on first window after opening second',
149
- except: {browser: %i[ie safari]}, reason: 'Focus is on newly opened window instead of the first' do
150
- browser.a(id: 'open').click
151
-
152
- expect { browser.windows.wait_until(size: 3) }.to_not raise_timeout_exception
139
+ describe Window, exclude: {browser: :ie, reason: 'Cannot call #restore!'} do
140
+ after do
141
+ browser.windows.restore!
153
142
  end
154
143
 
155
- describe '#close', except: {browser: :ie, reason: 'Click is not opening window'} do
156
- it 'closes a window' do
157
- browser.window(title: 'window switching').use
144
+ context 'when using multiple windows' do
145
+ before do
146
+ browser.goto WatirSpec.url_for('window_switching.html')
158
147
  browser.a(id: 'open').click
159
- browser.windows.wait_until(size: 3)
148
+ browser.windows.wait_until(size: 2)
149
+ end
160
150
 
161
- Watir::Window.new(browser, title: 'closeable window').close
151
+ it 'allows actions on first window after opening second',
152
+ except: {browser: :safari, reason: 'Focus is on newly opened window instead of the first'} do
153
+ browser.a(id: 'open').click
162
154
 
163
- expect { browser.windows.wait_until(size: 2) }.to_not raise_timeout_exception
155
+ expect { browser.windows.wait_until(size: 3) }.not_to raise_timeout_exception
164
156
  end
165
157
 
166
- it 'closes the current window',
167
- except: {browser: %i[ie safari]},
168
- reason: 'Focus is on newly opened window instead of the first' do
169
- browser.a(id: 'open').click
170
- browser.windows.wait_until(size: 3)
158
+ describe '#close' do
159
+ it 'closes a window' do
160
+ browser.window(title: 'window switching').use
161
+ browser.a(id: 'open').click
162
+ browser.windows.wait_until(size: 3)
171
163
 
172
- Watir::Window.new(browser, title: 'closeable window').use.close
164
+ described_class.new(browser, title: 'closeable window').close
173
165
 
174
- expect { browser.windows.wait_until(size: 2) }.to_not raise_timeout_exception
175
- end
176
- end
166
+ expect { browser.windows.wait_until(size: 2) }.not_to raise_timeout_exception
167
+ end
177
168
 
178
- describe '#use' do
179
- it 'switches to the window' do
180
- Watir::Window.new(browser, title: 'closeable window').use
181
- expect(browser.title).to eq 'closeable window'
182
- end
183
- end
169
+ it 'closes the current window',
170
+ except: {browser: :safari},
171
+ reason: 'Focus is on newly opened window instead of the first' do
172
+ browser.a(id: 'open').click
173
+ browser.windows.wait_until(size: 3)
184
174
 
185
- describe '#current?' do
186
- it 'returns true if it is the current window' do
187
- expect(Watir::Window.new(browser, title: browser.title)).to be_current
188
- end
175
+ described_class.new(browser, title: 'closeable window').use.close
189
176
 
190
- it 'returns false if it is not the current window' do
191
- expect(Watir::Window.new(browser, title: 'closeable window')).to_not be_current
177
+ expect { browser.windows.wait_until(size: 2) }.not_to raise_timeout_exception
178
+ end
192
179
  end
193
- end
194
180
 
195
- describe '#title' do
196
- it 'returns the title of the window' do
197
- browser.wait_while { |b| b.window(title: /^$/).exists? }
198
- titles = browser.windows.map(&:title)
199
-
200
- expect(titles).to include 'window switching', 'closeable window'
181
+ describe '#use' do
182
+ it 'switches to the window' do
183
+ described_class.new(browser, title: 'closeable window').use
184
+ expect(browser.title).to eq 'closeable window'
185
+ end
201
186
  end
202
- end
203
187
 
204
- describe '#url' do
205
- it 'returns the url of the window' do
206
- urls = browser.windows.map(&:url)
188
+ describe '#current?' do
189
+ it 'returns true if it is the current window' do
190
+ expect(described_class.new(browser, title: browser.title)).to be_current
191
+ end
207
192
 
208
- expect(urls).to(include(/window_switching\.html/, /closeable\.html$/))
193
+ it 'returns false if it is not the current window' do
194
+ expect(described_class.new(browser, title: 'closeable window')).not_to be_current
195
+ end
209
196
  end
210
- end
211
197
 
212
- describe '#eql?' do
213
- it 'knows when two windows are equal' do
214
- win1 = Watir::Window.new browser, {}
215
- win2 = Watir::Window.new browser, title: 'window switching'
198
+ describe '#title' do
199
+ it 'returns the title of the window' do
200
+ browser.wait_while { |b| b.window(title: /^$/).exists? }
201
+ titles = browser.windows.map(&:title)
216
202
 
217
- expect(win1).to eq win2
203
+ expect(titles).to include 'window switching', 'closeable window'
204
+ end
218
205
  end
219
206
 
220
- it 'knows when two windows are not equal' do
221
- win1 = Watir::Window.new browser, title: 'closeable window'
222
- win2 = Watir::Window.new browser, title: 'window switching'
207
+ describe '#url' do
208
+ it 'returns the url of the window' do
209
+ urls = browser.windows.map(&:url)
223
210
 
224
- expect(win1).to_not eq win2
211
+ expect(urls).to(include(/window_switching\.html/, /closeable\.html$/))
212
+ end
225
213
  end
226
- end
227
214
 
228
- describe '#handle' do
229
- it 'does not find if not matching' do
230
- expect(browser.window(title: 'noop').handle).to be_nil
231
- end
215
+ describe '#eql?' do
216
+ it 'knows when two windows are equal' do
217
+ win1 = described_class.new browser, {}
218
+ win2 = described_class.new browser, title: 'window switching'
232
219
 
233
- it 'finds window by :url' do
234
- expect(browser.window(url: /closeable\.html/).handle).to_not be_nil
235
- end
220
+ expect(win1).to eq win2
221
+ end
236
222
 
237
- it 'finds window by :title' do
238
- expect(browser.window(title: 'closeable window').handle).to_not be_nil
239
- end
223
+ it 'knows when two windows are not equal' do
224
+ win1 = described_class.new browser, title: 'closeable window'
225
+ win2 = described_class.new browser, title: 'window switching'
240
226
 
241
- it 'finds window by :element' do
242
- expect(browser.window(element: browser.a(id: 'close')).handle).to_not be_nil
227
+ expect(win1).not_to eq win2
228
+ end
243
229
  end
244
230
 
245
- it 'finds window by multiple values' do
246
- expect(browser.window(url: /closeable\.html/, title: 'closeable window').handle).to_not be_nil
247
- end
248
- end
249
- end
231
+ describe '#handle' do
232
+ it 'does not find if not matching' do
233
+ expect(browser.window(title: 'noop').handle).to be_nil
234
+ end
250
235
 
251
- context 'with a closed window',
252
- except: {browser: :safari,
253
- reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
254
- before do
255
- @original_window = browser.window
256
- browser.goto WatirSpec.url_for('window_switching.html')
257
- browser.a(id: 'open').click
258
- browser.windows.wait_until(size: 2)
259
- @handles = browser.driver.window_handles
260
- @closed_window = browser.window(title: 'closeable window').use
261
- browser.a(id: 'close').click
262
- browser.windows.wait_until(size: 1)
263
- end
236
+ it 'finds window by :url' do
237
+ expect(browser.window(url: /closeable\.html/).handle).not_to be_nil
238
+ end
264
239
 
265
- describe '#exists?' do
266
- it 'returns false if previously referenced window is closed' do
267
- expect(@closed_window).to_not be_present
268
- end
240
+ it 'finds window by :title' do
241
+ expect(browser.window(title: 'closeable window').handle).not_to be_nil
242
+ end
269
243
 
270
- it 'returns false if closed window is referenced' do
271
- expect(browser.window).to_not exist
272
- end
273
- end
244
+ it 'finds window by :element' do
245
+ expect(browser.window(element: browser.a(id: 'close')).handle).not_to be_nil
246
+ end
274
247
 
275
- describe '#current?' do
276
- it 'returns false if the referenced window is closed' do
277
- expect(@original_window).to_not be_current
248
+ it 'finds window by multiple values' do
249
+ expect(browser.window(url: /closeable\.html/, title: 'closeable window').handle).not_to be_nil
250
+ end
278
251
  end
279
252
  end
280
253
 
281
- describe '#eql?' do
282
- it 'should return false when checking equivalence to a closed window' do
283
- expect(browser.window).not_to eq @closed_widow
254
+ context 'with a closed window',
255
+ except: {browser: :safari,
256
+ reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
257
+ before do
258
+ @original_window = browser.window
259
+ browser.goto WatirSpec.url_for('window_switching.html')
260
+ browser.a(id: 'open').click
261
+ browser.windows.wait_until(size: 2)
262
+ @handles = browser.driver.window_handles
263
+ @closed_window = browser.window(title: 'closeable window').use
264
+ browser.a(id: 'close').click
265
+ browser.windows.wait_until(size: 1)
284
266
  end
285
- end
286
267
 
287
- describe '#use' do
288
- it 'raises NoMatchingWindowFoundException error when attempting to use a referenced window that is closed' do
289
- expect { @closed_window.use }.to raise_no_matching_window_exception
290
- end
268
+ describe '#exists?' do
269
+ it 'returns false if previously referenced window is closed' do
270
+ expect(@closed_window).not_to be_present
271
+ end
291
272
 
292
- it 'raises NoMatchingWindowFoundException error when attempting to use the current window if it is closed' do
293
- expect { browser.window.use }.to raise_no_matching_window_exception
273
+ it 'returns false if closed window is referenced' do
274
+ expect(browser.window).not_to exist
275
+ end
294
276
  end
295
- end
296
277
 
297
- it 'raises an exception when using an element on a closed window',
298
- exclude: {browser: :firefox,
299
- platform: :windows,
300
- reason: 'https://github.com/mozilla/geckodriver/issues/1847'} do
301
- msg = 'browser window was closed'
302
- expect { browser.a.text }.to raise_exception(Watir::Exception::NoMatchingWindowFoundException, msg)
303
- end
278
+ describe '#current?' do
279
+ it 'returns false if the referenced window is closed' do
280
+ expect(@original_window).not_to be_current
281
+ end
282
+ end
304
283
 
305
- it 'raises an exception when locating a closed window' do
306
- expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
307
- end
308
- end
284
+ describe '#eql?' do
285
+ it 'returns false when checking equivalence to a closed window' do
286
+ expect(browser.window).not_to eq @closed_widow
287
+ end
288
+ end
309
289
 
310
- context 'with a closed window on a delay' do
311
- it 'raises an exception when locating a window closed during lookup' do
312
- browser.goto WatirSpec.url_for('window_switching.html')
313
- browser.a(id: 'open').click
314
- browser.windows.wait_until(size: 2)
315
- browser.window(title: 'closeable window').use
316
- browser.a(id: 'close-delay').click
317
-
318
- begin
319
- module Watir
320
- class Browser
321
- alias title_old title
322
-
323
- def title
324
- sleep 0.5
325
- title_old
326
- end
327
- end
290
+ describe '#use' do
291
+ it 'raises NoMatchingWindowFoundException error when attempting to use a referenced window that is closed' do
292
+ expect { @closed_window.use }.to raise_no_matching_window_exception
328
293
  end
329
294
 
330
- expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
331
- ensure
332
- module Watir
333
- class Browser
334
- alias title title_old
335
- end
295
+ it 'raises NoMatchingWindowFoundException error when attempting to use the current window if it is closed' do
296
+ expect { browser.window.use }.to raise_no_matching_window_exception
336
297
  end
337
298
  end
338
- end
339
- end
340
-
341
- context 'with current window closed',
342
- except: {browser: :safari,
343
- reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
344
- before do
345
- browser.goto WatirSpec.url_for('window_switching.html')
346
- browser.a(id: 'open').click
347
- browser.windows.wait_until(size: 2)
348
- browser.window(title: 'closeable window').use
349
- browser.a(id: 'close').click
350
- browser.windows.wait_until(size: 1)
351
- end
352
299
 
353
- describe '#present?' do
354
- it 'should find window by url' do
355
- expect(browser.window(url: /window_switching\.html/)).to be_present
300
+ it 'raises an exception when using an element on a closed window',
301
+ exclude: {browser: :firefox,
302
+ platform: :windows,
303
+ reason: 'https://github.com/mozilla/geckodriver/issues/1847'} do
304
+ msg = 'browser window was closed'
305
+ expect { browser.a.text }.to raise_exception(Exception::NoMatchingWindowFoundException, msg)
356
306
  end
357
307
 
358
- it 'should find window by title' do
359
- expect(browser.window(title: 'window switching')).to be_present
308
+ it 'raises an exception when locating a closed window' do
309
+ expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
360
310
  end
311
+ end
361
312
 
362
- it 'should find window by element' do
363
- expect(browser.window(element: browser.link(id: 'open'))).to be_present
313
+ context 'with a closed window on a delay' do
314
+ it 'raises an exception when locating a window closed during lookup' do
315
+ browser.goto WatirSpec.url_for('window_switching.html')
316
+ browser.a(id: 'open').click
317
+ browser.windows.wait_until(size: 2)
318
+ browser.window(title: 'closeable window').use
319
+ browser.a(id: 'close-delay').click
320
+ allow(browser).to receive(:title).and_invoke(-> { sleep(0.5) && browser.wd.title })
321
+
322
+ expect { browser.window(title: 'closeable window').use }.to raise_no_matching_window_exception
364
323
  end
365
324
  end
366
325
 
367
- describe '#use' do
368
- context 'switching windows without blocks' do
369
- it 'by url' do
370
- browser.window(url: /window_switching\.html/).use
371
- expect(browser.title).to be == 'window switching'
326
+ context 'with current window closed',
327
+ except: {browser: :safari,
328
+ reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
329
+ before do
330
+ browser.goto WatirSpec.url_for('window_switching.html')
331
+ browser.a(id: 'open').click
332
+ browser.windows.wait_until(size: 2)
333
+ browser.window(title: 'closeable window').use
334
+ browser.a(id: 'close').click
335
+ browser.windows.wait_until(size: 1)
336
+ end
337
+
338
+ describe '#present?' do
339
+ it 'finds window by url' do
340
+ expect(browser.window(url: /window_switching\.html/)).to be_present
372
341
  end
373
342
 
374
- it 'by title' do
375
- browser.window(title: 'window switching').use
376
- expect(browser.url).to match(/window_switching\.html/)
343
+ it 'finds window by title' do
344
+ expect(browser.window(title: 'window switching')).to be_present
377
345
  end
378
346
 
379
- it 'by element' do
380
- browser.window(element: browser.link(id: 'open')).use
381
- expect(browser.url).to match(/window_switching\.html/)
347
+ it 'finds window by element' do
348
+ expect(browser.window(element: browser.link(id: 'open'))).to be_present
382
349
  end
383
350
  end
384
351
 
385
- context 'Switching windows with blocks' do
386
- it 'by url' do
387
- browser.window(url: /window_switching\.html/).use { expect(browser.title).to be == 'window switching' }
388
- end
352
+ describe '#use' do
353
+ context 'when switching windows without blocks' do
354
+ it 'by url' do
355
+ browser.window(url: /window_switching\.html/).use
356
+ expect(browser.title).to be == 'window switching'
357
+ end
358
+
359
+ it 'by title' do
360
+ browser.window(title: 'window switching').use
361
+ expect(browser.url).to match(/window_switching\.html/)
362
+ end
389
363
 
390
- it 'by title' do
391
- browser.window(title: 'window switching').use { expect(browser.url).to match(/window_switching\.html/) }
364
+ it 'by element' do
365
+ browser.window(element: browser.link(id: 'open')).use
366
+ expect(browser.url).to match(/window_switching\.html/)
367
+ end
392
368
  end
393
369
 
394
- it 'by element' do
395
- element = browser.link(id: 'open')
396
- browser.window(element: element).use { expect(browser.url).to match(/window_switching\.html/) }
370
+ context 'when switching windows with blocks' do
371
+ it 'by url' do
372
+ browser.window(url: /window_switching\.html/).use { expect(browser.title).to be == 'window switching' }
373
+ end
374
+
375
+ it 'by title' do
376
+ browser.window(title: 'window switching').use { expect(browser.url).to match(/window_switching\.html/) }
377
+ end
378
+
379
+ it 'by element' do
380
+ element = browser.link(id: 'open')
381
+ browser.window(element: element).use { expect(browser.url).to match(/window_switching\.html/) }
382
+ end
397
383
  end
398
384
  end
399
385
  end
400
- end
401
386
 
402
- context 'manipulating size and position', except: {headless: true} do
403
- before do
404
- browser.goto WatirSpec.url_for('window_switching.html')
405
- @initial_size = browser.window.size
406
- end
387
+ context 'when manipulating size and position', except: {headless: true} do
388
+ before(:all) do
389
+ maximized_size = browser.window.size
407
390
 
408
- after do
409
- browser.window.resize_to @initial_size.width, @initial_size.height
410
- end
391
+ browser.window.resize_to(
392
+ maximized_size.width - 100,
393
+ maximized_size.height - 100
394
+ )
395
+ browser.wait_until { |b| b.window.size != maximized_size }
411
396
 
412
- it 'should get the size of the current window' do
413
- expect(@initial_size.width).to eq browser.execute_script('return window.outerWidth;')
414
- expect(@initial_size.height).to eq browser.execute_script('return window.outerHeight;')
415
- end
397
+ current_position = browser.window.position
416
398
 
417
- it 'should get the position of the current window' do
418
- pos = browser.window.position
399
+ browser.window.move_to(
400
+ current_position.x + 40,
401
+ current_position.y + 40
402
+ )
403
+ browser.wait_until { |b| b.window.position != current_position }
419
404
 
420
- expect(pos.x).to eq browser.execute_script('return window.screenX;')
421
- expect(pos.y).to eq browser.execute_script('return window.screenY;')
422
- end
405
+ @initial_size = browser.window.size
406
+ @initial_position = browser.window.position
407
+ end
423
408
 
424
- it 'should resize the window' do
425
- browser.window.resize_to(
426
- @initial_size.width - 20,
427
- @initial_size.height - 20
428
- )
409
+ before do
410
+ browser.goto WatirSpec.url_for('window_switching.html')
411
+ end
429
412
 
430
- new_size = browser.window.size
413
+ after do
414
+ browser.window.resize_to @initial_size.width, @initial_size.height
415
+ browser.window.move_to @initial_position.x, @initial_position.y
416
+ end
431
417
 
432
- expect(new_size.width).to eq @initial_size.width - 20
433
- expect(new_size.height).to eq @initial_size.height - 20
434
- end
418
+ it 'gets the size of the current window' do
419
+ expect(@initial_size.width).to eq browser.execute_script('return window.outerWidth;')
420
+ expect(@initial_size.height).to eq browser.execute_script('return window.outerHeight;')
421
+ end
435
422
 
436
- it 'should move the window' do
437
- initial_pos = browser.window.position
423
+ it 'gets the position of the current window' do
424
+ expect(@initial_position.x).to eq browser.execute_script('return window.screenX;')
425
+ expect(@initial_position.y).to eq browser.execute_script('return window.screenY;')
426
+ end
438
427
 
439
- browser.window.move_to(
440
- initial_pos.x + 2,
441
- initial_pos.y + 2
442
- )
428
+ it 'resizes the window' do
429
+ browser.window.resize_to(
430
+ @initial_size.width - 20,
431
+ @initial_size.height - 20
432
+ )
443
433
 
444
- new_pos = browser.window.position
445
- expect(new_pos.x).to eq initial_pos.x + 2
446
- expect(new_pos.y).to eq initial_pos.y + 2
447
- end
434
+ browser.wait_until { |b| b.window.size != @initial_size }
448
435
 
449
- it 'should maximize the window', except: {browser: :firefox, window_manager: false} do
450
- browser.window.resize_to(
451
- @initial_size.width - 40,
452
- @initial_size.height - 40
453
- )
454
- browser.wait_until { |b| b.window.size != @initial_size }
455
- new_size = browser.window.size
436
+ new_size = browser.window.size
437
+ expect(new_size.width).to eq @initial_size.width - 20
438
+ expect(new_size.height).to eq @initial_size.height - 20
439
+ end
456
440
 
457
- browser.window.maximize
458
- browser.wait_until { |b| b.window.size != new_size }
441
+ it 'moves the window' do
442
+ browser.window.move_to(
443
+ @initial_position.x + 5,
444
+ @initial_position.y + 5
445
+ )
459
446
 
460
- final_size = browser.window.size
461
- expect(final_size.width).to be >= new_size.width
462
- expect(final_size.height).to be > new_size.height
463
- end
447
+ browser.wait_until { |b| b.window.position != @initial_position }
464
448
 
465
- it 'should make the window full screen', except: {browser: :firefox, window_manager: false} do
466
- browser.window.resize_to(
467
- @initial_size.width - 40,
468
- @initial_size.height - 40
469
- )
470
- new_size = browser.window.size
449
+ new_position = browser.window.position
450
+ expect(new_position.x).to eq @initial_position.x + 5
451
+ expect(new_position.y).to eq @initial_position.y + 5
452
+ end
471
453
 
472
- browser.window.full_screen
473
- browser.wait_until { |b| b.window.size != new_size }
454
+ it 'maximizes the window' do
455
+ browser.window.maximize
456
+ browser.wait_until { |b| b.window.size != @initial_size }
474
457
 
475
- final_size = browser.window.size
476
- expect(final_size.width).to be >= new_size.width
477
- expect(final_size.height).to be > new_size.height
478
- end
458
+ new_size = browser.window.size
459
+ expect(new_size.width).to be >= @initial_size.width
460
+ expect(new_size.height).to be > @initial_size.height
461
+ end
479
462
 
480
- it 'should minimize the window', except: {window_manager: false} do
481
- expect(browser.execute_script('return document.visibilityState;')).to eq 'visible'
463
+ it 'makes the window full screen' do
464
+ browser.window.full_screen
465
+ browser.wait_until { |b| b.window.size != @initial_size }
482
466
 
483
- browser.window.minimize
467
+ new_size = browser.window.size
468
+ expect(new_size.width).to be >= @initial_size.width
469
+ expect(new_size.height).to be > @initial_size.height
470
+ end
484
471
 
485
- browser.wait_until { |b| b.execute_script('return document.visibilityState;') != 'visible' }
472
+ it 'minimizes the window' do
473
+ expect(browser.execute_script('return document.visibilityState;')).to eq 'visible'
486
474
 
487
- expect(browser.execute_script('return document.visibilityState;')).to eq 'hidden'
488
- end
489
- end
490
- end
475
+ browser.window.minimize
491
476
 
492
- describe Watir::WindowCollection do
493
- before do
494
- browser.goto WatirSpec.url_for('window_switching.html')
495
- browser.a(id: 'open').click
496
- browser.windows.wait_until(size: 2)
497
- end
477
+ browser.wait_until { |b| b.execute_script('return document.visibilityState;') != 'visible' }
498
478
 
499
- after do
500
- browser.windows.restore!
479
+ expect(browser.execute_script('return document.visibilityState;')).to eq 'hidden'
480
+ browser.window.maximize
481
+ end
482
+ end
501
483
  end
502
484
 
503
- it '#to_a raises exception' do
504
- expect {
505
- Watir::WindowCollection.new(browser).to_a
506
- }.to raise_exception(NoMethodError, 'indexing not reliable on WindowCollection')
507
- end
485
+ describe WindowCollection, exclude: {browser: :ie, reason: 'Cannot call #restore!'} do
486
+ before do
487
+ browser.goto WatirSpec.url_for('window_switching.html')
488
+ browser.a(id: 'open').click
489
+ browser.windows.wait_until(size: 2)
490
+ end
508
491
 
509
- describe '#new' do
510
- it 'returns all windows by default' do
511
- windows = Watir::WindowCollection.new(browser)
492
+ after do
493
+ browser.windows.restore!
494
+ end
512
495
 
513
- expect(windows.size).to eq 2
496
+ describe '#to_a' do
497
+ it 'raises exception' do
498
+ expect {
499
+ described_class.new(browser).to_a
500
+ }.to raise_exception(NoMethodError, 'indexing not reliable on WindowCollection')
501
+ end
514
502
  end
515
503
 
516
- it 'filters available windows by url' do
517
- windows = Watir::WindowCollection.new(browser, url: /closeable\.html/)
504
+ describe '#new' do
505
+ it 'returns all windows by default' do
506
+ windows = described_class.new(browser)
518
507
 
519
- expect(windows.size).to eq 1
520
- end
508
+ expect(windows.size).to eq 2
509
+ end
521
510
 
522
- it 'filters available windows by title' do
523
- windows = Watir::WindowCollection.new(browser, title: /closeable/)
511
+ it 'filters available windows by url' do
512
+ windows = described_class.new(browser, url: /closeable\.html/)
524
513
 
525
- expect(windows.size).to eq 1
526
- end
514
+ expect(windows.size).to eq 1
515
+ end
527
516
 
528
- it 'filters available windows by element' do
529
- windows = Watir::WindowCollection.new(browser, element: browser.element(id: 'close'))
517
+ it 'filters available windows by title' do
518
+ windows = described_class.new(browser, title: /closeable/)
530
519
 
531
- expect(windows.size).to eq 1
532
- end
520
+ expect(windows.size).to eq 1
521
+ end
533
522
 
534
- it 'raises ArgumentError if unrecognized locator' do
535
- expect {
536
- Watir::WindowCollection.new(browser, foo: /closeable/)
537
- }.to raise_error(ArgumentError)
523
+ it 'filters available windows by element' do
524
+ windows = described_class.new(browser, element: browser.element(id: 'close'))
525
+
526
+ expect(windows.size).to eq 1
527
+ end
528
+
529
+ it 'raises ArgumentError if unrecognized locator' do
530
+ expect {
531
+ described_class.new(browser, foo: /closeable/)
532
+ }.to raise_error(ArgumentError)
533
+ end
538
534
  end
539
- end
540
535
 
541
- describe '#size' do
542
- it 'counts the number of matching windows' do
543
- expect(Watir::WindowCollection.new(browser).size).to eq 2
536
+ describe '#size' do
537
+ it 'counts the number of matching windows' do
538
+ expect(described_class.new(browser).size).to eq 2
539
+ end
544
540
  end
545
- end
546
541
 
547
- describe '#eq?' do
548
- it 'compares the equivalence of window handles' do
549
- windows1 = Watir::WindowCollection.new(browser, title: //)
550
- windows2 = Watir::WindowCollection.new(browser, url: //)
542
+ describe '#eq?' do
543
+ it 'compares the equivalence of window handles' do
544
+ windows1 = described_class.new(browser, title: //)
545
+ windows2 = described_class.new(browser, url: //)
551
546
 
552
- expect(windows1).to eq windows2
547
+ expect(windows1).to eq windows2
548
+ end
553
549
  end
554
- end
555
550
 
556
- it '#reset!' do
557
- wins = browser.windows
558
- expect(wins.size).to eq 2
559
- wins.reset!
560
- expect(wins.instance_variable_get('@window_list')).to be_nil
561
- end
551
+ describe '#reset!' do
552
+ it 'clears window list' do
553
+ wins = browser.windows
554
+ expect(wins.size).to eq 2
555
+ wins.reset!
556
+ expect(wins.instance_variable_get(:@window_list)).to be_nil
557
+ end
558
+ end
562
559
 
563
- describe '#restore!' do
564
- it 'when on other window',
565
- except: {browser: %i[ie safari], reason: 'Focus is on newly opened window instead of the first'} do
566
- browser.a(id: 'open').click
567
- browser.windows.wait_until(size: 3)
568
- browser.window(title: 'closeable window').use
560
+ describe '#restore!' do
561
+ it 'when on other window',
562
+ except: {browser: :safari, reason: 'Focus is on newly opened window instead of the first'} do
563
+ browser.a(id: 'open').click
564
+ browser.windows.wait_until(size: 3)
565
+ browser.window(title: 'closeable window').use
569
566
 
570
- browser.windows.restore!
571
- expect(browser.windows.size).to eq 1
572
- expect(browser.title).to eq 'window switching'
573
- end
567
+ browser.windows.restore!
568
+ expect(browser.windows.size).to eq 1
569
+ expect(browser.title).to eq 'window switching'
570
+ end
574
571
 
575
- it 'when browser closed does not raise exception' do
576
- browser.close
572
+ it 'when browser closed does not raise exception' do
573
+ browser.close
577
574
 
578
- expect { browser.windows.restore! }.not_to raise_exception
575
+ expect { browser.windows.restore! }.not_to raise_exception
576
+ end
579
577
  end
580
578
  end
581
579
  end