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