watir 7.2.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,533 +2,533 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Browser' do
6
- describe '#exists?' do
7
- it 'returns true if we are at a page' do
8
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
9
- expect(browser).to exist
10
- end
11
-
12
- it 'returns false if window is closed',
13
- except: {browser: :safari,
14
- reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'},
15
- exclude: {browser: :ie,
16
- reason: 'IE does not like switching windows'} do
17
- browser.goto WatirSpec.url_for('window_switching.html')
18
- browser.a(id: 'open').click
19
- browser.windows.wait_until(size: 2)
20
- browser.window(title: 'closeable window').use
21
- browser.a(id: 'close').click
22
- browser.windows.wait_until(size: 1)
23
- expect(browser.exists?).to be false
24
- ensure
25
- browser.windows.restore!
26
- end
27
-
28
- it 'returns false after Browser#close' do
29
- browser.close
30
- expect(browser).to_not exist
31
- end
32
- end
33
-
34
- describe '#closed?' do
35
- it 'returns false if not closed' do
36
- expect(browser).to_not be_closed
37
- end
38
-
39
- it 'returns false if window is closed but browser is not',
40
- except: {browser: :safari,
41
- reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'} do
42
- browser.goto WatirSpec.url_for('window_switching.html')
43
- browser.a(id: 'open').click
44
- browser.windows.wait_until(size: 2)
45
- browser.window(title: 'closeable window').use
46
- browser.a(id: 'close').click
47
- browser.windows.wait_until(size: 1)
48
- expect(browser).to_not be_closed
49
- ensure
50
- browser.windows.restore!
51
- end
52
-
53
- it 'returns false after Browser#close' do
54
- browser.close
55
- expect(browser).to be_closed
56
- end
57
- end
58
-
59
- describe '#html' do
60
- it 'returns the DOM of the page as an HTML string' do
61
- browser.goto(WatirSpec.url_for('right_click.html'))
62
- html = browser.html.downcase # varies between browsers
5
+ module Watir
6
+ describe Browser do
7
+ describe '#exists?' do
8
+ it 'returns true if we are at a page' do
9
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
10
+ expect(browser).to exist
11
+ end
63
12
 
64
- expect(html).to match(/^<html/)
65
- expect(html).to include('<meta ')
66
- expect(html).to include(' content="text/html; charset=utf-8"')
67
- expect(html).to match(/http-equiv=("|)content-type/)
68
- end
69
- end
13
+ it 'returns false if window is closed',
14
+ except: {browser: :safari,
15
+ reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'},
16
+ exclude: {browser: :ie,
17
+ reason: 'IE does not like switching windows'} do
18
+ browser.goto WatirSpec.url_for('window_switching.html')
19
+ browser.a(id: 'open').click
20
+ browser.windows.wait_until(size: 2)
21
+ browser.window(title: 'closeable window').use
22
+ browser.a(id: 'close').click
23
+ browser.windows.wait_until(size: 1)
24
+ expect(browser.exists?).to be false
25
+ ensure
26
+ browser.windows.restore!
27
+ end
70
28
 
71
- describe '#title' do
72
- it 'returns the current page title' do
73
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
74
- expect(browser.title).to eq 'Non-control elements'
29
+ it 'returns false after Browser#close' do
30
+ browser.close
31
+ expect(browser).not_to exist
32
+ end
75
33
  end
76
- end
77
34
 
78
- describe '#status' do
79
- it 'returns the current value of window.status',
80
- except: {browser: :ie, reason: 'Status bar not enabled by default'} do
81
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
35
+ describe '#closed?' do
36
+ it 'returns false if not closed' do
37
+ expect(browser).not_to be_closed
38
+ end
82
39
 
83
- browser.execute_script "window.status = 'All done!';"
84
- expect(browser.status).to eq 'All done!'
85
- end
86
- end
40
+ it 'returns false if window is closed but browser is not',
41
+ except: {browser: :safari,
42
+ reason: 'Clicking an Element that Closes a Window is returning NoMatchingWindowFoundException'},
43
+ exclude: {browser: :ie,
44
+ reason: 'IE Mode does not like closed windows'} do
45
+ browser.goto WatirSpec.url_for('window_switching.html')
46
+ browser.a(id: 'open').click
47
+ browser.windows.wait_until(size: 2)
48
+ browser.window(title: 'closeable window').use
49
+ browser.a(id: 'close').click
50
+ browser.windows.wait_until(size: 1)
51
+ expect(browser).not_to be_closed
52
+ ensure
53
+ browser.windows.restore!
54
+ end
87
55
 
88
- describe '#name' do
89
- it 'returns browser name' do
90
- expect(browser.name).to eq(WatirSpec.implementation.browser_name)
56
+ it 'returns false after Browser#close' do
57
+ browser.close
58
+ expect(browser).to be_closed
59
+ end
91
60
  end
92
- end
93
61
 
94
- describe '#send_key{,s}' do
95
- it 'sends keystrokes to the active element' do
96
- browser.goto WatirSpec.url_for 'forms_with_input_elements.html'
62
+ describe '#html' do
63
+ it 'returns the DOM of the page as an HTML string' do
64
+ browser.goto(WatirSpec.url_for('right_click.html'))
65
+ html = browser.html.downcase # varies between browsers
97
66
 
98
- browser.send_keys 'hello'
99
- expect(browser.text_field(id: 'new_user_first_name').value).to eq 'hello'
67
+ expect(html).to match(/^<html/)
68
+ expect(html).to include('<meta ')
69
+ expect(html).to include(' content="text/html; charset=utf-8"')
70
+ expect(html).to match(/http-equiv=("|)content-type/)
71
+ end
100
72
  end
101
73
 
102
- it 'sends keys to a frame' do
103
- browser.goto WatirSpec.url_for 'frames.html'
104
- tf = browser.frame.text_field(id: 'senderElement')
105
- tf.clear
106
- tf.click
74
+ describe '#status' do
75
+ it 'returns the current value of window.status',
76
+ except: {browser: :ie, reason: 'Status bar not enabled by default'} do
77
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
107
78
 
108
- browser.frame.send_keys 'hello'
109
-
110
- expect(tf.value).to eq 'hello'
111
- end
112
- end
113
-
114
- describe '#text' do
115
- it 'returns the text of the page' do
116
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
117
- expect(browser.text).to include('Dubito, ergo cogito, ergo sum.')
79
+ browser.execute_script "window.status = 'All done!';"
80
+ expect(browser.status).to eq 'All done!'
81
+ end
118
82
  end
119
83
 
120
- it 'returns the text also if the content-type is text/plain' do
121
- # more specs for text/plain? what happens if we call other methods?
122
- browser.goto(WatirSpec.url_for('plain_text'))
123
- expect(browser.text.strip).to eq 'This is text/plain'
84
+ describe '#name' do
85
+ it 'returns browser name' do
86
+ expect(browser.name).to eq(WatirSpec.implementation.browser_name)
87
+ end
124
88
  end
125
89
 
126
- it 'returns text of top most browsing context', except: {browser: :safari,
127
- reason: 'Safari does not strip text'} do
128
- browser.goto(WatirSpec.url_for('nested_iframes.html'))
129
- browser.iframe(id: 'two').h3.exists?
130
- expect(browser.text).to eq 'Top Layer'
131
- end
132
- end
90
+ describe '#send_key{,s}' do
91
+ it 'sends keystrokes to the active element' do
92
+ browser.goto WatirSpec.url_for 'forms_with_input_elements.html'
133
93
 
134
- describe '#url' do
135
- it 'returns the current url' do
136
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
137
- expect(browser.url.casecmp(WatirSpec.url_for('non_control_elements.html'))).to eq 0
138
- end
94
+ browser.send_keys 'hello'
95
+ expect(browser.text_field(id: 'new_user_first_name').value).to eq 'hello'
96
+ end
139
97
 
140
- it 'always returns top url' do
141
- browser.goto(WatirSpec.url_for('frames.html'))
142
- browser.frame.body.exists? # switches to frame
143
- expect(browser.url.casecmp(WatirSpec.url_for('frames.html'))).to eq 0
144
- end
145
- end
98
+ it 'sends keys to a frame' do
99
+ browser.goto WatirSpec.url_for 'frames.html'
100
+ tf = browser.frame.text_field(id: 'senderElement')
101
+ tf.clear
102
+ tf.click
146
103
 
147
- describe '#title' do
148
- it 'returns the current title' do
149
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
150
- expect(browser.title).to eq 'Non-control elements'
151
- end
104
+ browser.frame.send_keys 'hello'
152
105
 
153
- it 'always returns top title' do
154
- browser.goto(WatirSpec.url_for('frames.html'))
155
- browser.element(tag_name: 'title').text
156
- browser.frame.body.exists? # switches to frame
157
- expect(browser.title).to eq 'Frames'
106
+ expect(tf.value).to eq 'hello'
107
+ end
158
108
  end
159
- end
160
-
161
- # TODO: Temporarily disabling this before moving it to unit tests
162
- xdescribe '#new' do
163
- context 'with parameters', except: {remote: true} do
164
- let(:url) { 'http://localhost:4544/wd/hub/' }
165
109
 
166
- before(:all) do
167
- @original = WatirSpec.implementation.clone
168
-
169
- require 'watirspec/remote_server'
170
- args = ["-Dwebdriver.chrome.driver=#{Webdrivers::Chromedriver.driver_path}",
171
- "-Dwebdriver.gecko.driver=#{Webdrivers::Geckodriver.driver_path}"]
172
- WatirSpec::RemoteServer.new.start(4544, args: args)
173
- browser.close
110
+ describe '#text' do
111
+ it 'returns the text of the page' do
112
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
113
+ expect(browser.text).to include('Dubito, ergo cogito, ergo sum.')
174
114
  end
175
115
 
176
- before(:each) do
177
- @opts = WatirSpec.implementation.browser_args.last
116
+ it 'returns the text also if the content-type is text/plain' do
117
+ # more specs for text/plain? what happens if we call other methods?
118
+ browser.goto(WatirSpec.url_for('plain_text'))
119
+ expect(browser.text.strip).to eq 'This is text/plain'
178
120
  end
179
121
 
180
- after(:each) do
181
- @new_browser.close
182
- WatirSpec.implementation = @original.clone
122
+ it 'returns text of top most browsing context', except: {browser: :safari,
123
+ reason: 'Safari does not strip text'} do
124
+ browser.goto(WatirSpec.url_for('nested_iframes.html'))
125
+ browser.iframe(id: 'two').h3.exists?
126
+ expect(browser.text).to eq 'Top Layer'
183
127
  end
128
+ end
184
129
 
185
- it 'uses remote client based on provided url' do
186
- @opts[:url] = url
187
- @new_browser = WatirSpec.new_browser
188
-
189
- server_url = @new_browser.driver.instance_variable_get(:@bridge).http.instance_variable_get(:@server_url)
190
- expect(server_url).to eq URI.parse(url)
130
+ describe '#url' do
131
+ it 'returns the current url' do
132
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
133
+ expect(browser.url.casecmp(WatirSpec.url_for('non_control_elements.html'))).to eq 0
191
134
  end
192
135
 
193
- it 'sets client timeout' do
194
- @opts.merge!(url: url, open_timeout: 44, read_timeout: 47)
195
- @new_browser = WatirSpec.new_browser
136
+ it 'always returns top url' do
137
+ browser.goto(WatirSpec.url_for('frames.html'))
138
+ browser.frame.body.exists? # switches to frame
139
+ expect(browser.url.casecmp(WatirSpec.url_for('frames.html'))).to eq 0
140
+ end
141
+ end
196
142
 
197
- http = @new_browser.driver.instance_variable_get(:@bridge).http
143
+ describe '#title' do
144
+ it 'returns the current title' do
145
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
146
+ expect(browser.title).to eq 'Non-control elements'
147
+ end
198
148
 
199
- expect(http.open_timeout).to eq 44
200
- expect(http.read_timeout).to eq 47
149
+ it 'always returns top title' do
150
+ browser.goto(WatirSpec.url_for('frames.html'))
151
+ browser.element(tag_name: 'title').text
152
+ browser.frame.body.exists? # switches to frame
153
+ expect(browser.title).to eq 'Frames'
201
154
  end
155
+ end
202
156
 
203
- it 'accepts http_client' do
204
- http_client = Selenium::WebDriver::Remote::Http::Default.new
205
- @opts[:url] = url
206
- @opts[:http_client] = http_client
207
- @new_browser = WatirSpec.new_browser
157
+ # TODO: Temporarily disabling this before moving it to unit tests
158
+ xdescribe '#new' do
159
+ context 'when using parameters', except: {remote: true} do
160
+ let(:url) { 'http://localhost:4544/wd/hub/' }
208
161
 
209
- expect(@new_browser.driver.instance_variable_get(:@bridge).http).to eq http_client
210
- end
162
+ before(:all) do
163
+ @original = WatirSpec.implementation.clone
211
164
 
212
- it 'accepts Remote::Capabilities instance as :desired_capabilities', only: {browser: :firefox} do
213
- caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
214
- @opts[:url] = url
215
- @opts[:desired_capabilities] = caps
165
+ require 'watirspec/remote_server'
166
+ args = ["-Dwebdriver.chrome.driver=#{Webdrivers::Chromedriver.driver_path}",
167
+ "-Dwebdriver.gecko.driver=#{Webdrivers::Geckodriver.driver_path}"]
168
+ WatirSpec::RemoteServer.new.start(4544, args: args)
169
+ browser.close
170
+ end
216
171
 
217
- msg = /You can pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
218
- expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
219
- expect(@new_browser.driver.capabilities.accept_insecure_certs).to eq true
220
- end
172
+ before do
173
+ @opts = WatirSpec.implementation.browser_args.last
174
+ end
221
175
 
222
- it 'accepts individual driver capabilities', only: {browser: :firefox} do
223
- @opts[:accept_insecure_certs] = true
224
- @new_browser = WatirSpec.new_browser
176
+ after do
177
+ @new_browser.close
178
+ WatirSpec.implementation = @original.clone
179
+ end
225
180
 
226
- expect(@new_browser.driver.capabilities[:accept_insecure_certs]).to eq true
227
- end
181
+ it 'uses remote client based on provided url' do
182
+ @opts[:url] = url
183
+ @new_browser = WatirSpec.new_browser
228
184
 
229
- it 'accepts profile', only: {browser: :firefox} do
230
- home_page = WatirSpec.url_for('special_chars.html')
231
- profile = Selenium::WebDriver::Firefox::Profile.new
232
- profile['browser.startup.homepage'] = home_page
233
- profile['browser.startup.page'] = 1
234
- @opts[:profile] = profile
185
+ server_url = @new_browser.driver.instance_variable_get(:@bridge).http.instance_variable_get(:@server_url)
186
+ expect(server_url).to eq URI.parse(url)
187
+ end
235
188
 
236
- @new_browser = WatirSpec.new_browser
189
+ it 'sets client timeout' do
190
+ @opts.merge!(url: url, open_timeout: 44, read_timeout: 47)
191
+ @new_browser = WatirSpec.new_browser
237
192
 
238
- expect(@new_browser.url).to eq home_page
239
- end
193
+ http = @new_browser.driver.instance_variable_get(:@bridge).http
240
194
 
241
- context 'chrome arguments', only: {browser: :chrome} do
242
- it 'accepts browser options' do
243
- @opts[:options] = {emulation: {userAgent: 'foo;bar'}}
195
+ expect(http.open_timeout).to eq 44
196
+ expect(http.read_timeout).to eq 47
197
+ end
244
198
 
199
+ it 'accepts http_client' do
200
+ http_client = Selenium::WebDriver::Remote::Http::Default.new
201
+ @opts[:url] = url
202
+ @opts[:http_client] = http_client
245
203
  @new_browser = WatirSpec.new_browser
246
204
 
247
- ua = @new_browser.execute_script 'return window.navigator.userAgent'
248
- expect(ua).to eq('foo;bar')
205
+ expect(@new_browser.driver.instance_variable_get(:@bridge).http).to eq http_client
249
206
  end
250
207
 
251
- it 'uses remote client when specifying remote' do
252
- opts = {desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
253
- url: url}
254
- WatirSpec.implementation.browser_args = [:remote, opts]
208
+ it 'accepts Remote::Capabilities instance as :desired_capabilities', only: {browser: :firefox} do
209
+ caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
210
+ @opts[:url] = url
211
+ @opts[:desired_capabilities] = caps
212
+
255
213
  msg = /You can pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
256
214
  expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
257
- server_url = @new_browser.driver.instance_variable_get(:@bridge).http.instance_variable_get(:@server_url)
258
- expect(server_url).to eq URI.parse(url)
215
+ expect(@new_browser.driver.capabilities.accept_insecure_certs).to be true
259
216
  end
260
217
 
261
- it 'accepts switches argument' do
262
- @opts.delete :args
263
- @opts[:switches] = ['--window-size=600,700']
264
-
218
+ it 'accepts individual driver capabilities', only: {browser: :firefox} do
219
+ @opts[:accept_insecure_certs] = true
265
220
  @new_browser = WatirSpec.new_browser
266
- size = @new_browser.window.size
267
- expect(size['height']).to eq 700
268
- expect(size['width']).to eq 600
221
+
222
+ expect(@new_browser.driver.capabilities[:accept_insecure_certs]).to be true
269
223
  end
270
224
 
271
- it 'accepts Chrome::Options instance as :options', except: {headless: true} do
272
- chrome_opts = Selenium::WebDriver::Chrome::Options.new(emulation: {userAgent: 'foo;bar'})
273
- @opts.delete :args
274
- @opts[:options] = chrome_opts
225
+ it 'accepts profile', only: {browser: :firefox} do
226
+ home_page = WatirSpec.url_for('special_chars.html')
227
+ profile = Selenium::WebDriver::Firefox::Profile.new
228
+ profile['browser.startup.homepage'] = home_page
229
+ profile['browser.startup.page'] = 1
230
+ @opts[:profile] = profile
275
231
 
276
232
  @new_browser = WatirSpec.new_browser
277
233
 
278
- ua = @new_browser.execute_script 'return window.navigator.userAgent'
279
- expect(ua).to eq('foo;bar')
234
+ expect(@new_browser.url).to eq home_page
235
+ end
236
+
237
+ context 'when using chrome arguments', only: {browser: :chrome} do
238
+ it 'accepts browser options' do
239
+ @opts[:options] = {emulation: {userAgent: 'foo;bar'}}
240
+
241
+ @new_browser = WatirSpec.new_browser
242
+
243
+ ua = @new_browser.execute_script 'return window.navigator.userAgent'
244
+ expect(ua).to eq('foo;bar')
245
+ end
246
+
247
+ it 'uses remote client when specifying remote' do
248
+ opts = {desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
249
+ url: url}
250
+ WatirSpec.implementation.browser_args = [:remote, opts]
251
+ msg = /You can pass values directly into Watir::Browser opt without needing to use :desired_capabilities/
252
+ expect { @new_browser = WatirSpec.new_browser }.to output(msg).to_stdout_from_any_process
253
+ server_url = @new_browser.driver.instance_variable_get(:@bridge).http.instance_variable_get(:@server_url)
254
+ expect(server_url).to eq URI.parse(url)
255
+ end
256
+
257
+ it 'accepts switches argument' do
258
+ @opts.delete :args
259
+ @opts[:switches] = ['--window-size=600,700']
260
+
261
+ @new_browser = WatirSpec.new_browser
262
+ size = @new_browser.window.size
263
+ expect(size['height']).to eq 700
264
+ expect(size['width']).to eq 600
265
+ end
266
+
267
+ it 'accepts Chrome::Options instance as :options', except: {headless: true} do
268
+ chrome_opts = Selenium::WebDriver::Chrome::Options.new(emulation: {userAgent: 'foo;bar'})
269
+ @opts.delete :args
270
+ @opts[:options] = chrome_opts
271
+
272
+ @new_browser = WatirSpec.new_browser
273
+
274
+ ua = @new_browser.execute_script 'return window.navigator.userAgent'
275
+ expect(ua).to eq('foo;bar')
276
+ end
280
277
  end
281
278
  end
282
- end
283
279
 
284
- it 'takes service as argument', only: {browser: :chrome} do
285
- @original = WatirSpec.implementation.clone
286
- browser.close
287
- @opts = WatirSpec.implementation.browser_args.last
288
- browser_name = WatirSpec.implementation.browser_args.first
280
+ it 'takes service as argument', only: {browser: :chrome} do
281
+ @original = WatirSpec.implementation.clone
282
+ browser.close
283
+ @opts = WatirSpec.implementation.browser_args.last
284
+ browser_name = WatirSpec.implementation.browser_args.first
289
285
 
290
- service = Selenium::WebDriver::Service.send(browser_name, port: '2314', args: ['foo'])
286
+ service = Selenium::WebDriver::Service.send(browser_name, port: '2314', args: ['foo'])
291
287
 
292
- @opts[:service] = service
293
- @opts[:listener] = LocalConfig::SelectorListener.new
288
+ @opts[:service] = service
289
+ @opts[:listener] = LocalConfig::SelectorListener.new
294
290
 
295
- @new_browser = WatirSpec.new_browser
291
+ @new_browser = WatirSpec.new_browser
296
292
 
297
- bridge = @new_browser.wd.instance_variable_get(:@bridge)
298
- expect(bridge).to be_a Selenium::WebDriver::Support::EventFiringBridge
299
- service = @new_browser.wd.instance_variable_get(:@service)
300
- expect(service.instance_variable_get(:@extra_args)).to eq ['foo']
301
- expect(service.instance_variable_get(:@port)).to eq 2314
293
+ bridge = @new_browser.wd.instance_variable_get(:@bridge)
294
+ expect(bridge).to be_a Selenium::WebDriver::Support::EventFiringBridge
295
+ service = @new_browser.wd.instance_variable_get(:@service)
296
+ expect(service.instance_variable_get(:@extra_args)).to eq ['foo']
297
+ expect(service.instance_variable_get(:@port)).to eq 2314
302
298
 
303
- @new_browser.close
304
- ensure
305
- WatirSpec.implementation = @original.clone
306
- end
299
+ @new_browser.close
300
+ ensure
301
+ WatirSpec.implementation = @original.clone
302
+ end
307
303
 
308
- it 'takes a driver instance as argument' do
309
- mock_driver = double(Selenium::WebDriver::Driver)
310
- expect(Selenium::WebDriver::Driver).to receive(:===).with(mock_driver).and_return(true)
311
- expect { Watir::Browser.new(mock_driver) }.to_not raise_error
312
- end
304
+ it 'takes a driver instance as argument' do
305
+ mock_driver = instance_double(Selenium::WebDriver::Driver)
306
+ allow(Selenium::WebDriver::Driver).to receive(:===).and_return(true)
307
+ expect { described_class.new(mock_driver) }.not_to raise_error
308
+ expect(Selenium::WebDriver::Driver).to have_received(:===).with(mock_driver)
309
+ end
313
310
 
314
- it 'raises ArgumentError for invalid args' do
315
- expect { Watir::Browser.new(Object.new) }.to raise_error(ArgumentError)
311
+ it 'raises ArgumentError for invalid args' do
312
+ expect { described_class.new(Struct.new) }.to raise_error(ArgumentError)
313
+ end
316
314
  end
317
- end
318
315
 
319
- describe '.start' do
320
- it 'goes to the given URL and return an instance of itself' do
321
- browser.close
322
- sleep 1
323
- driver, args = WatirSpec.implementation.browser_args
324
- b = Watir::Browser.start(WatirSpec.url_for('non_control_elements.html'), driver, args.dup)
316
+ describe '.start' do
317
+ it 'goes to the given URL and return an instance of itself' do
318
+ browser.close
319
+ sleep 1
320
+ driver, args = WatirSpec.implementation.browser_args
321
+ b = described_class.start(WatirSpec.url_for('non_control_elements.html'), driver, args.dup)
325
322
 
326
- expect(b).to be_instance_of(Watir::Browser)
327
- expect(b.title).to eq 'Non-control elements'
328
- b.close
323
+ expect(b).to be_instance_of(described_class)
324
+ expect(b.title).to eq 'Non-control elements'
325
+ b.close
326
+ end
329
327
  end
330
- end
331
328
 
332
- describe '#goto' do
333
- it 'adds http:// to URLs with no URL scheme specified' do
334
- url = WatirSpec.host[%r{http://(.*)}, 1]
335
- expect(url).to_not be_nil
336
- browser.goto(url)
337
- expect(browser.url).to match(%r{http://#{url}/?})
338
- end
329
+ describe '#goto' do
330
+ it 'adds http:// to URLs with no URL scheme specified' do
331
+ url = WatirSpec.host[%r{http://(.*)}, 1]
332
+ expect(url).not_to be_nil
333
+ browser.goto(url)
334
+ expect(browser.url).to match(%r{http://#{url}/?})
335
+ end
339
336
 
340
- it 'goes to the given url without raising errors' do
341
- expect { browser.goto(WatirSpec.url_for('non_control_elements.html')) }.to_not raise_error
342
- end
337
+ it 'goes to the given url without raising errors' do
338
+ expect { browser.goto(WatirSpec.url_for('non_control_elements.html')) }.not_to raise_error
339
+ end
343
340
 
344
- it "goes to the url 'about:blank' without raising errors" do
345
- expect { browser.goto('about:blank') }.to_not raise_error
346
- end
341
+ it "goes to the url 'about:blank' without raising errors" do
342
+ expect { browser.goto('about:blank') }.not_to raise_error
343
+ end
347
344
 
348
- it 'goes to a data URL scheme address without raising errors' do
349
- expect { browser.goto('data:text/html;content-type=utf-8,foobar') }.to_not raise_error
350
- end
345
+ it 'goes to a data URL scheme address without raising errors' do
346
+ expect { browser.goto('data:text/html;content-type=utf-8,foobar') }.not_to raise_error
347
+ end
351
348
 
352
- it "goes to internal Chrome URL 'chrome://settings/browser' without raising errors",
353
- exclusive: {browser: %i[chrome edge]} do
354
- expect { browser.goto('chrome://settings/browser') }.to_not raise_error
355
- end
349
+ it "goes to internal Chrome URL 'chrome://settings/browser' without raising errors",
350
+ exclusive: {browser: %i[chrome edge]} do
351
+ expect { browser.goto('chrome://settings/browser') }.not_to raise_error
352
+ end
356
353
 
357
- it 'updates the page when location is changed with setTimeout + window.location' do
358
- browser.goto(WatirSpec.url_for('timeout_window_location.html'))
359
- browser.wait_while { |b| b.url.include? 'timeout_window_location.html' }
360
- expect(browser.url).to include('non_control_elements.html')
354
+ it 'updates the page when location is changed with setTimeout + window.location' do
355
+ browser.goto(WatirSpec.url_for('timeout_window_location.html'))
356
+ browser.wait_while { |b| b.url.include? 'timeout_window_location.html' }
357
+ expect(browser.url).to include('non_control_elements.html')
358
+ end
361
359
  end
362
- end
363
360
 
364
- describe '#refresh' do
365
- it 'refreshes the page' do
366
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
361
+ describe '#refresh' do
362
+ it 'refreshes the page' do
363
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
367
364
 
368
- browser.div(id: 'best_language').scroll.to
369
- browser.div(id: 'best_language').click
370
- expect(browser.div(id: 'best_language').text).to include('Ruby!')
371
- browser.refresh
372
- browser.div(id: 'best_language').wait_until(&:present?)
373
- expect(browser.div(id: 'best_language').text).to_not include('Ruby!')
365
+ browser.div(id: 'best_language').scroll.to
366
+ browser.div(id: 'best_language').click
367
+ expect(browser.div(id: 'best_language').text).to include('Ruby!')
368
+ browser.refresh
369
+ browser.div(id: 'best_language').wait_until(&:present?)
370
+ expect(browser.div(id: 'best_language').text).not_to include('Ruby!')
371
+ end
374
372
  end
375
- end
376
373
 
377
- describe '#execute_script' do
378
- before { browser.goto(WatirSpec.url_for('non_control_elements.html')) }
374
+ describe '#execute_script' do
375
+ before { browser.goto(WatirSpec.url_for('non_control_elements.html')) }
379
376
 
380
- it 'executes the given JavaScript on the current page' do
381
- expect(browser.pre(id: 'rspec').text).to_not eq 'javascript text'
382
- browser.execute_script("document.getElementById('rspec').innerHTML = 'javascript text'")
383
- expect(browser.pre(id: 'rspec').text).to eq 'javascript text'
384
- end
377
+ it 'executes the given JavaScript on the current page' do
378
+ expect(browser.pre(id: 'rspec').text).not_to eq 'javascript text'
379
+ browser.execute_script("document.getElementById('rspec').innerHTML = 'javascript text'")
380
+ expect(browser.pre(id: 'rspec').text).to eq 'javascript text'
381
+ end
385
382
 
386
- it 'executes the given JavaScript in the context of an anonymous function' do
387
- expect(browser.execute_script('1 + 1')).to be_nil
388
- expect(browser.execute_script('return 1 + 1')).to eq 2
389
- end
383
+ it 'executes the given JavaScript in the context of an anonymous function' do
384
+ expect(browser.execute_script('1 + 1')).to be_nil
385
+ expect(browser.execute_script('return 1 + 1')).to eq 2
386
+ end
390
387
 
391
- it 'returns correct Ruby objects' do
392
- expect(browser.execute_script('return {a: 1, "b": 2}')).to eq({'a' => 1, 'b' => 2})
393
- expect(browser.execute_script('return [1, 2, "3"]')).to match_array([1, 2, '3'])
394
- expect(browser.execute_script('return 1.2 + 1.3')).to eq 2.5
395
- expect(browser.execute_script('return 2 + 2')).to eq 4
396
- expect(browser.execute_script('return "hello"')).to eq 'hello'
397
- expect(browser.execute_script('return')).to be_nil
398
- expect(browser.execute_script('return null')).to be_nil
399
- expect(browser.execute_script('return undefined')).to be_nil
400
- expect(browser.execute_script('return true')).to be true
401
- expect(browser.execute_script('return false')).to be false
402
- end
388
+ it 'returns correct Ruby objects' do
389
+ expect(browser.execute_script('return {a: 1, "b": 2}')).to eq({'a' => 1, 'b' => 2})
390
+ expect(browser.execute_script('return [1, 2, "3"]')).to match_array([1, 2, '3'])
391
+ expect(browser.execute_script('return 1.2 + 1.3')).to eq 2.5
392
+ expect(browser.execute_script('return 2 + 2')).to eq 4
393
+ expect(browser.execute_script('return "hello"')).to eq 'hello'
394
+ expect(browser.execute_script('return')).to be_nil
395
+ expect(browser.execute_script('return null')).to be_nil
396
+ expect(browser.execute_script('return undefined')).to be_nil
397
+ expect(browser.execute_script('return true')).to be true
398
+ expect(browser.execute_script('return false')).to be false
399
+ end
403
400
 
404
- it 'works correctly with multi-line strings and special characters' do
405
- expect(browser.execute_script("//multiline rocks!
401
+ it 'works correctly with multi-line strings and special characters' do
402
+ expect(browser.execute_script("//multiline rocks!
406
403
  var a = 22; // comment on same line
407
404
  /* more
408
405
  comments */
409
406
  var b = '33';
410
407
  var c = \"44\";
411
408
  return a + b + c")).to eq '223344'
412
- end
413
-
414
- it 'wraps elements as Watir objects' do
415
- returned = browser.execute_script('return document.body')
416
- expect(returned).to be_kind_of(Watir::Body)
417
- end
409
+ end
418
410
 
419
- it 'wraps elements in an array' do
420
- list = browser.execute_script('return [document.body];')
421
- expect(list.size).to eq 1
422
- expect(list.first).to be_kind_of(Watir::Body)
423
- end
411
+ it 'wraps elements as Watir objects' do
412
+ returned = browser.execute_script('return document.body')
413
+ expect(returned).to be_a(Watir::Body)
414
+ end
424
415
 
425
- it 'wraps elements in a Hash' do
426
- hash = browser.execute_script('return {element: document.body};')
427
- expect(hash['element']).to be_kind_of(Watir::Body)
428
- end
416
+ it 'wraps elements in an array' do
417
+ list = browser.execute_script('return [document.body];')
418
+ expect(list.size).to eq 1
419
+ expect(list.first).to be_a(Watir::Body)
420
+ end
429
421
 
430
- it 'wraps elements in a deep object' do
431
- hash = browser.execute_script('return {elements: [document.body], body: {element: document.body }}')
422
+ it 'wraps elements in a Hash' do
423
+ hash = browser.execute_script('return {element: document.body};')
424
+ expect(hash['element']).to be_a(Watir::Body)
425
+ end
432
426
 
433
- expect(hash['elements'].first).to be_kind_of(Watir::Body)
434
- expect(hash['body']['element']).to be_kind_of(Watir::Body)
435
- end
436
- end
427
+ it 'wraps elements in a deep object' do
428
+ hash = browser.execute_script('return {elements: [document.body], body: {element: document.body }}')
437
429
 
438
- describe '#back and #forward' do
439
- it 'goes to the previous page' do
440
- browser.goto WatirSpec.url_for('non_control_elements.html')
441
- orig_url = browser.url
442
- browser.goto WatirSpec.url_for('tables.html')
443
- new_url = browser.url
444
- expect(orig_url).to_not eq new_url
445
- browser.back
446
- expect(orig_url).to eq browser.url
430
+ expect(hash['elements'].first).to be_a(Watir::Body)
431
+ expect(hash['body']['element']).to be_a(Watir::Body)
432
+ end
447
433
  end
448
434
 
449
- it 'goes to the next page' do
450
- urls = []
451
- browser.goto WatirSpec.url_for('non_control_elements.html')
452
- urls << browser.url
453
- browser.goto WatirSpec.url_for('tables.html')
454
- urls << browser.url
455
-
456
- browser.back
457
- expect(browser.url).to eq urls.first
458
- browser.forward
459
- expect(browser.url).to eq urls.last
460
- end
435
+ describe '#back and #forward' do
436
+ it 'goes to the previous page' do
437
+ browser.goto WatirSpec.url_for('non_control_elements.html')
438
+ orig_url = browser.url
439
+ browser.goto WatirSpec.url_for('tables.html')
440
+ new_url = browser.url
441
+ expect(orig_url).not_to eq new_url
442
+ browser.back
443
+ expect(orig_url).to eq browser.url
444
+ end
461
445
 
462
- it 'navigates between several history items' do
463
- urls = ['non_control_elements.html',
464
- 'tables.html',
465
- 'forms_with_input_elements.html',
466
- 'definition_lists.html'].map do |page|
467
- browser.goto WatirSpec.url_for(page)
468
- browser.url
446
+ it 'goes to the next page' do
447
+ urls = []
448
+ browser.goto WatirSpec.url_for('non_control_elements.html')
449
+ urls << browser.url
450
+ browser.goto WatirSpec.url_for('tables.html')
451
+ urls << browser.url
452
+
453
+ browser.back
454
+ expect(browser.url).to eq urls.first
455
+ browser.forward
456
+ expect(browser.url).to eq urls.last
469
457
  end
470
458
 
471
- 3.times { browser.back }
472
- expect(browser.url).to eq urls.first
473
- 2.times { browser.forward }
474
- expect(browser.url).to eq urls[2]
459
+ it 'navigates between several history items' do
460
+ urls = ['non_control_elements.html',
461
+ 'tables.html',
462
+ 'forms_with_input_elements.html',
463
+ 'definition_lists.html'].map do |page|
464
+ browser.goto WatirSpec.url_for(page)
465
+ browser.url
466
+ end
467
+
468
+ 3.times { browser.back }
469
+ expect(browser.url).to eq urls.first
470
+ 2.times { browser.forward }
471
+ expect(browser.url).to eq urls[2]
472
+ end
475
473
  end
476
- end
477
474
 
478
- it 'raises UnknownObjectException when trying to access DOM elements on plain/text-page' do
479
- browser.goto(WatirSpec.url_for('plain_text'))
480
- expect { browser.div(id: 'foo').id }.to raise_unknown_object_exception
481
- end
475
+ it 'raises UnknownObjectException when trying to access DOM elements on plain/text-page' do
476
+ browser.goto(WatirSpec.url_for('plain_text'))
477
+ expect { browser.div(id: 'foo').id }.to raise_unknown_object_exception
478
+ end
482
479
 
483
- it 'raises an error when trying to interact with a closed browser' do
484
- browser.goto WatirSpec.url_for 'definition_lists.html'
485
- browser.close
480
+ it 'raises an error when trying to interact with a closed browser' do
481
+ browser.goto WatirSpec.url_for 'definition_lists.html'
482
+ browser.close
486
483
 
487
- expect { browser.dl(id: 'experience-list').id }.to raise_error(Watir::Exception::Error, 'browser was closed')
488
- end
484
+ expect { browser.dl(id: 'experience-list').id }.to raise_error(Watir::Exception::Error, 'browser was closed')
485
+ end
489
486
 
490
- describe '#ready_state' do
491
- it "gets the document's readyState property" do
492
- expect(browser).to receive(:execute_script).with('return document.readyState')
493
- browser.ready_state
487
+ describe '#ready_state' do
488
+ it "gets the document's readyState property" do
489
+ allow(browser).to receive(:execute_script)
490
+ browser.ready_state
491
+ expect(browser).to have_received(:execute_script).with('return document.readyState')
492
+ end
494
493
  end
495
- end
496
494
 
497
- describe '#wait' do
498
- # The only way to get engage this method is with page load strategy set to "none"
499
- # This spec is both mocking out the response and demonstrating the necessary settings for it to be meaningful
500
- it 'waits for document ready state to be complete' do
501
- @original = WatirSpec.implementation.clone
502
- browser.close
503
- @opts = WatirSpec.implementation.browser_args.last
495
+ describe '#wait' do
496
+ # The only way to get engage this method is with page load strategy set to "none"
497
+ # This spec is both mocking out the response and demonstrating the necessary settings for it to be meaningful
498
+ it 'waits for document ready state to be complete' do
499
+ @original = WatirSpec.implementation.clone
500
+ browser.close
501
+ @opts = WatirSpec.implementation.browser_args.last
504
502
 
505
- @opts[:options] = {page_load_strategy: :none}
506
- browser = WatirSpec.new_browser
503
+ @opts[:options] = {page_load_strategy: :none}
504
+ browser = WatirSpec.new_browser
507
505
 
508
- start_time = Time.now
509
- allow(browser).to receive(:ready_state) { Time.now < start_time + 3 ? 'loading' : 'complete' }
510
- expect(browser.ready_state).to eq 'loading'
506
+ start_time = ::Time.now
507
+ allow(browser).to receive(:ready_state) { ::Time.now < start_time + 3 ? 'loading' : 'complete' }
508
+ expect(browser.ready_state).to eq 'loading'
511
509
 
512
- browser.wait(20)
513
- expect(Time.now - start_time).to be > 3
514
- expect(browser.ready_state).to eq 'complete'
510
+ browser.wait(20)
511
+ expect(::Time.now - start_time).to be > 3
512
+ expect(browser.ready_state).to eq 'complete'
515
513
 
516
- browser.close
517
- ensure
518
- WatirSpec.implementation = @original.clone
514
+ browser.close
515
+ ensure
516
+ WatirSpec.implementation = @original.clone
517
+ end
519
518
  end
520
- end
521
519
 
522
- describe '#inspect' do
523
- it 'works even if browser is closed' do
524
- expect(browser).to receive(:url).and_raise(Errno::ECONNREFUSED)
525
- expect { browser.inspect }.to_not raise_error
520
+ describe '#inspect' do
521
+ it 'works even if browser is closed' do
522
+ allow(browser).to receive(:url).and_raise(Errno::ECONNREFUSED)
523
+ expect { browser.inspect }.not_to raise_error
524
+ expect(browser).to have_received(:url).once
525
+ end
526
526
  end
527
- end
528
527
 
529
- describe '#screenshot' do
530
- it 'returns an instance of of Watir::Screenshot' do
531
- expect(browser.screenshot).to be_kind_of(Watir::Screenshot)
528
+ describe '#screenshot' do
529
+ it 'returns an instance of of Watir::Screenshot' do
530
+ expect(browser.screenshot).to be_a(Watir::Screenshot)
531
+ end
532
532
  end
533
533
  end
534
534
  end