watir 7.2.0 → 7.2.1

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