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.
- checksums.yaml +4 -4
- data/.github/workflows/chrome.yml +1 -1
- data/.github/workflows/edge.yml +1 -1
- data/.github/workflows/firefox.yml +1 -1
- data/.github/workflows/ie.yml +1 -1
- data/.github/workflows/safari.yml +1 -1
- data/.github/workflows/unit.yml +1 -1
- data/.rubocop.yml +25 -12
- data/.rubocop_todo.yml +8 -1
- data/CHANGES.md +6 -1
- data/LICENSE +2 -2
- data/lib/watir/capabilities.rb +1 -1
- data/lib/watir/locators/anchor/selector_builder.rb +3 -0
- data/lib/watir/locators/element/matcher.rb +2 -1
- data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
- data/lib/watir/locators/text_field/matcher.rb +0 -4
- data/lib/watir/version.rb +1 -1
- data/spec/locator_spec_helper.rb +0 -8
- data/spec/unit/capabilities_spec.rb +553 -561
- data/spec/unit/element_locator_spec.rb +89 -78
- data/spec/unit/match_elements/button_spec.rb +69 -62
- data/spec/unit/match_elements/element_spec.rb +303 -309
- data/spec/unit/match_elements/text_field_spec.rb +76 -73
- data/spec/unit/selector_builder/anchor_spec.rb +39 -33
- data/spec/unit/selector_builder/button_spec.rb +209 -202
- data/spec/unit/selector_builder/cell_spec.rb +48 -42
- data/spec/unit/selector_builder/element_spec.rb +634 -627
- data/spec/unit/selector_builder/row_spec.rb +119 -113
- data/spec/unit/selector_builder/text_field_spec.rb +195 -188
- data/spec/unit/selector_builder/textarea_spec.rb +22 -14
- data/spec/unit/wait_spec.rb +85 -81
- data/spec/watirspec/adjacent_spec.rb +249 -247
- data/spec/watirspec/after_hooks_spec.rb +161 -159
- data/spec/watirspec/alert_spec.rb +61 -58
- data/spec/watirspec/browser_spec.rb +409 -409
- data/spec/watirspec/capabilities_spec.rb +89 -99
- data/spec/watirspec/cookies_spec.rb +120 -118
- data/spec/watirspec/drag_and_drop_spec.rb +26 -24
- data/spec/watirspec/element_hidden_spec.rb +66 -60
- data/spec/watirspec/elements/area_spec.rb +49 -47
- data/spec/watirspec/elements/areas_spec.rb +27 -25
- data/spec/watirspec/elements/button_spec.rb +253 -251
- data/spec/watirspec/elements/buttons_spec.rb +36 -34
- data/spec/watirspec/elements/checkbox_spec.rb +48 -36
- data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
- data/spec/watirspec/elements/collections_spec.rb +126 -119
- data/spec/watirspec/elements/date_field_spec.rb +185 -183
- data/spec/watirspec/elements/date_fields_spec.rb +29 -27
- data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
- data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
- data/spec/watirspec/elements/dd_spec.rb +87 -85
- data/spec/watirspec/elements/dds_spec.rb +27 -25
- data/spec/watirspec/elements/del_spec.rb +106 -104
- data/spec/watirspec/elements/dels_spec.rb +26 -24
- data/spec/watirspec/elements/div_spec.rb +225 -221
- data/spec/watirspec/elements/divs_spec.rb +37 -35
- data/spec/watirspec/elements/dl_spec.rb +110 -108
- data/spec/watirspec/elements/dls_spec.rb +28 -26
- data/spec/watirspec/elements/dt_spec.rb +86 -84
- data/spec/watirspec/elements/dts_spec.rb +27 -25
- data/spec/watirspec/elements/element_spec.rb +794 -775
- data/spec/watirspec/elements/elements_spec.rb +40 -38
- data/spec/watirspec/elements/em_spec.rb +62 -60
- data/spec/watirspec/elements/ems_spec.rb +28 -26
- data/spec/watirspec/elements/filefield_spec.rb +116 -114
- data/spec/watirspec/elements/filefields_spec.rb +28 -26
- data/spec/watirspec/elements/font_spec.rb +20 -18
- data/spec/watirspec/elements/form_spec.rb +51 -49
- data/spec/watirspec/elements/forms_spec.rb +29 -27
- data/spec/watirspec/elements/frame_spec.rb +89 -87
- data/spec/watirspec/elements/frames_spec.rb +27 -25
- data/spec/watirspec/elements/hidden_spec.rb +81 -79
- data/spec/watirspec/elements/hiddens_spec.rb +28 -26
- data/spec/watirspec/elements/hn_spec.rb +59 -57
- data/spec/watirspec/elements/hns_spec.rb +26 -24
- data/spec/watirspec/elements/iframe_spec.rb +195 -191
- data/spec/watirspec/elements/iframes_spec.rb +31 -29
- data/spec/watirspec/elements/image_spec.rb +148 -146
- data/spec/watirspec/elements/images_spec.rb +26 -24
- data/spec/watirspec/elements/input_spec.rb +9 -7
- data/spec/watirspec/elements/ins_spec.rb +106 -104
- data/spec/watirspec/elements/inses_spec.rb +26 -24
- data/spec/watirspec/elements/label_spec.rb +56 -54
- data/spec/watirspec/elements/labels_spec.rb +26 -24
- data/spec/watirspec/elements/li_spec.rb +76 -74
- data/spec/watirspec/elements/link_spec.rb +173 -177
- data/spec/watirspec/elements/links_spec.rb +45 -43
- data/spec/watirspec/elements/lis_spec.rb +27 -25
- data/spec/watirspec/elements/list_spec.rb +44 -42
- data/spec/watirspec/elements/map_spec.rb +57 -55
- data/spec/watirspec/elements/maps_spec.rb +27 -25
- data/spec/watirspec/elements/meta_spec.rb +16 -14
- data/spec/watirspec/elements/metas_spec.rb +26 -24
- data/spec/watirspec/elements/ol_spec.rb +56 -65
- data/spec/watirspec/elements/ols_spec.rb +26 -24
- data/spec/watirspec/elements/option_spec.rb +91 -89
- data/spec/watirspec/elements/p_spec.rb +81 -79
- data/spec/watirspec/elements/pre_spec.rb +77 -75
- data/spec/watirspec/elements/pres_spec.rb +26 -24
- data/spec/watirspec/elements/ps_spec.rb +26 -24
- data/spec/watirspec/elements/radio_spec.rb +251 -249
- data/spec/watirspec/elements/radios_spec.rb +28 -26
- data/spec/watirspec/elements/select_list_spec.rb +537 -526
- data/spec/watirspec/elements/select_lists_spec.rb +32 -30
- data/spec/watirspec/elements/span_spec.rb +112 -110
- data/spec/watirspec/elements/spans_spec.rb +26 -24
- data/spec/watirspec/elements/strong_spec.rb +58 -58
- data/spec/watirspec/elements/strongs_spec.rb +28 -26
- data/spec/watirspec/elements/table_spec.rb +192 -139
- data/spec/watirspec/elements/tables_spec.rb +28 -26
- data/spec/watirspec/elements/tbody_spec.rb +74 -72
- data/spec/watirspec/elements/tbodys_spec.rb +40 -38
- data/spec/watirspec/elements/td_spec.rb +66 -64
- data/spec/watirspec/elements/tds_spec.rb +41 -39
- data/spec/watirspec/elements/text_field_spec.rb +206 -204
- data/spec/watirspec/elements/text_fields_spec.rb +30 -28
- data/spec/watirspec/elements/textarea_spec.rb +20 -18
- data/spec/watirspec/elements/textareas_spec.rb +18 -16
- data/spec/watirspec/elements/tfoot_spec.rb +65 -63
- data/spec/watirspec/elements/tfoots_spec.rb +42 -40
- data/spec/watirspec/elements/thead_spec.rb +65 -63
- data/spec/watirspec/elements/theads_spec.rb +42 -40
- data/spec/watirspec/elements/tr_spec.rb +48 -46
- data/spec/watirspec/elements/trs_spec.rb +42 -40
- data/spec/watirspec/elements/ul_spec.rb +56 -54
- data/spec/watirspec/elements/uls_spec.rb +26 -24
- data/spec/watirspec/radio_set_spec.rb +269 -267
- data/spec/watirspec/screenshot_spec.rb +20 -18
- data/spec/watirspec/scroll_spec.rb +152 -148
- data/spec/watirspec/shadow_root_spec.rb +86 -83
- data/spec/watirspec/user_editable_spec.rb +200 -198
- data/spec/watirspec/wait_spec.rb +289 -295
- data/spec/watirspec/window_switching_spec.rb +422 -434
- data/spec/watirspec_helper.rb +1 -23
- data/watir.gemspec +5 -4
- metadata +44 -33
- data/spec/watirspec/attributes_spec.rb +0 -18
- data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
- data/spec/watirspec/special_chars_spec.rb +0 -23
|
@@ -2,533 +2,533 @@
|
|
|
2
2
|
|
|
3
3
|
require 'watirspec_helper'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
describe
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
35
|
+
describe '#closed?' do
|
|
36
|
+
it 'returns false if not closed' do
|
|
37
|
+
expect(browser).not_to be_closed
|
|
38
|
+
end
|
|
82
39
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
154
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
WatirSpec.
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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 '
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
-
|
|
200
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
210
|
-
|
|
162
|
+
before(:all) do
|
|
163
|
+
@original = WatirSpec.implementation.clone
|
|
211
164
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
end
|
|
172
|
+
before do
|
|
173
|
+
@opts = WatirSpec.implementation.browser_args.last
|
|
174
|
+
end
|
|
221
175
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
176
|
+
after do
|
|
177
|
+
@new_browser.close
|
|
178
|
+
WatirSpec.implementation = @original.clone
|
|
179
|
+
end
|
|
225
180
|
|
|
226
|
-
|
|
227
|
-
|
|
181
|
+
it 'uses remote client based on provided url' do
|
|
182
|
+
@opts[:url] = url
|
|
183
|
+
@new_browser = WatirSpec.new_browser
|
|
228
184
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
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
|
-
|
|
239
|
-
end
|
|
193
|
+
http = @new_browser.driver.instance_variable_get(:@bridge).http
|
|
240
194
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
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 '
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
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
|
|
262
|
-
@opts
|
|
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
|
-
|
|
267
|
-
expect(
|
|
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
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
279
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
|
|
286
|
+
service = Selenium::WebDriver::Service.send(browser_name, port: '2314', args: ['foo'])
|
|
291
287
|
|
|
292
|
-
|
|
293
|
-
|
|
288
|
+
@opts[:service] = service
|
|
289
|
+
@opts[:listener] = LocalConfig::SelectorListener.new
|
|
294
290
|
|
|
295
|
-
|
|
291
|
+
@new_browser = WatirSpec.new_browser
|
|
296
292
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
299
|
+
@new_browser.close
|
|
300
|
+
ensure
|
|
301
|
+
WatirSpec.implementation = @original.clone
|
|
302
|
+
end
|
|
307
303
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
315
|
-
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
|
|
361
|
+
describe '#refresh' do
|
|
362
|
+
it 'refreshes the page' do
|
|
363
|
+
browser.goto(WatirSpec.url_for('non_control_elements.html'))
|
|
367
364
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
378
|
-
|
|
374
|
+
describe '#execute_script' do
|
|
375
|
+
before { browser.goto(WatirSpec.url_for('non_control_elements.html')) }
|
|
379
376
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
-
|
|
405
|
-
|
|
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
|
-
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
|
|
431
|
-
|
|
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
|
-
|
|
434
|
-
|
|
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
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
browser.
|
|
468
|
-
|
|
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
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
-
|
|
488
|
-
|
|
484
|
+
expect { browser.dl(id: 'experience-list').id }.to raise_error(Watir::Exception::Error, 'browser was closed')
|
|
485
|
+
end
|
|
489
486
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
506
|
-
|
|
503
|
+
@opts[:options] = {page_load_strategy: :none}
|
|
504
|
+
browser = WatirSpec.new_browser
|
|
507
505
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
|
|
513
|
-
|
|
514
|
-
|
|
510
|
+
browser.wait(20)
|
|
511
|
+
expect(::Time.now - start_time).to be > 3
|
|
512
|
+
expect(browser.ready_state).to eq 'complete'
|
|
515
513
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
514
|
+
browser.close
|
|
515
|
+
ensure
|
|
516
|
+
WatirSpec.implementation = @original.clone
|
|
517
|
+
end
|
|
519
518
|
end
|
|
520
|
-
end
|
|
521
519
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|