watir 6.16.2 → 6.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/actions/enable-safari/action.yml +11 -0
- data/.github/actions/install-chrome/action.yml +11 -0
- data/.github/workflows/linux.yml +61 -0
- data/.github/workflows/mac.yml +55 -0
- data/.github/workflows/unit.yml +31 -0
- data/.github/workflows/windows.yml +39 -0
- data/.rubocop.yml +32 -107
- data/.rubocop_todo.yml +36 -0
- data/CHANGES.md +42 -0
- data/Gemfile +3 -1
- data/LICENSE +2 -2
- data/README.md +9 -10
- data/Rakefile +4 -4
- data/lib/watir-webdriver.rb +1 -1
- data/lib/watir.rb +1 -1
- data/lib/watir/adjacent.rb +8 -10
- data/lib/watir/after_hooks.rb +4 -4
- data/lib/watir/alert.rb +1 -0
- data/lib/watir/attribute_helper.rb +2 -0
- data/lib/watir/browser.rb +7 -3
- data/lib/watir/capabilities.rb +9 -6
- data/lib/watir/cookies.rb +3 -1
- data/lib/watir/element_collection.rb +21 -6
- data/lib/watir/elements/element.rb +66 -53
- data/lib/watir/elements/file_field.rb +1 -0
- data/lib/watir/elements/html_elements.rb +0 -1
- data/lib/watir/elements/iframe.rb +4 -3
- data/lib/watir/elements/link.rb +0 -9
- data/lib/watir/elements/radio.rb +1 -1
- data/lib/watir/elements/select.rb +22 -7
- data/lib/watir/generator/base/spec_extractor.rb +4 -4
- data/lib/watir/generator/html/generator.rb +1 -1
- data/lib/watir/has_window.rb +17 -15
- data/lib/watir/js_execution.rb +3 -3
- data/lib/watir/js_snippets.rb +2 -2
- data/lib/watir/legacy_wait.rb +1 -1
- data/lib/watir/locators.rb +1 -3
- data/lib/watir/locators/element/locator.rb +22 -12
- data/lib/watir/locators/element/selector_builder.rb +12 -13
- data/lib/watir/locators/element/selector_builder/xpath.rb +40 -13
- data/lib/watir/locators/text_field/matcher.rb +1 -1
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +3 -1
- data/lib/watir/logger.rb +7 -20
- data/lib/watir/radio_set.rb +2 -2
- data/lib/watir/user_editable.rb +6 -2
- data/lib/watir/version.rb +1 -1
- data/lib/watir/wait.rb +2 -0
- data/lib/watir/wait/timer.rb +1 -1
- data/lib/watir/window.rb +8 -4
- data/lib/watir/window_collection.rb +105 -0
- data/lib/watirspec.rb +2 -1
- data/lib/watirspec/guards.rb +1 -1
- data/lib/watirspec/implementation.rb +3 -5
- data/lib/watirspec/rake_tasks.rb +2 -0
- data/lib/watirspec/runner.rb +5 -1
- data/lib/watirspec/server.rb +1 -1
- data/spec/spec_helper.rb +2 -7
- data/spec/unit/container_spec.rb +1 -1
- data/spec/unit/logger_spec.rb +5 -7
- data/spec/unit/match_elements/element_spec.rb +17 -15
- data/spec/unit/selector_builder/button_spec.rb +16 -15
- data/spec/unit/selector_builder/element_spec.rb +58 -9
- data/spec/unit/selector_builder/text_field_spec.rb +14 -14
- data/spec/unit/unit_helper.rb +2 -4
- data/spec/watirspec/after_hooks_spec.rb +58 -68
- data/spec/watirspec/alert_spec.rb +69 -79
- data/spec/watirspec/browser_spec.rb +51 -48
- data/spec/watirspec/cookies_spec.rb +52 -37
- data/spec/watirspec/drag_and_drop_spec.rb +14 -38
- data/spec/watirspec/elements/button_spec.rb +2 -0
- data/spec/watirspec/elements/buttons_spec.rb +1 -1
- data/spec/watirspec/elements/checkbox_spec.rb +8 -4
- data/spec/watirspec/elements/date_field_spec.rb +18 -9
- data/spec/watirspec/elements/date_time_field_spec.rb +3 -4
- data/spec/watirspec/elements/div_spec.rb +62 -54
- data/spec/watirspec/elements/element_spec.rb +73 -88
- data/spec/watirspec/elements/elements_spec.rb +12 -3
- data/spec/watirspec/elements/filefield_spec.rb +25 -50
- data/spec/watirspec/elements/form_spec.rb +6 -8
- data/spec/watirspec/elements/frame_spec.rb +10 -13
- data/spec/watirspec/elements/iframe_spec.rb +12 -9
- data/spec/watirspec/elements/iframes_spec.rb +2 -2
- data/spec/watirspec/elements/link_spec.rb +23 -12
- data/spec/watirspec/elements/links_spec.rb +11 -3
- data/spec/watirspec/elements/option_spec.rb +15 -17
- data/spec/watirspec/elements/select_list_spec.rb +222 -117
- data/spec/watirspec/elements/text_field_spec.rb +8 -4
- data/spec/watirspec/elements/tr_spec.rb +0 -9
- data/spec/watirspec/html/forms_with_input_elements.html +1 -0
- data/spec/watirspec/html/iframes.html +3 -0
- data/spec/watirspec/html/non_control_elements.html +4 -4
- data/spec/watirspec/html/right_click.html +12 -0
- data/spec/watirspec/html/wait.html +6 -6
- data/spec/watirspec/html/window_switching.html +10 -0
- data/spec/watirspec/legacy_wait_spec.rb +216 -0
- data/spec/watirspec/support/rspec_matchers.rb +17 -13
- data/spec/watirspec/user_editable_spec.rb +1 -1
- data/spec/watirspec/wait_spec.rb +257 -305
- data/spec/watirspec/window_switching_spec.rb +332 -211
- data/spec/watirspec_helper.rb +16 -19
- data/support/doctest_helper.rb +0 -2
- data/watir.gemspec +6 -7
- metadata +36 -26
- data/.travis.yml +0 -84
- data/appveyor.yml +0 -12
- data/lib/watir/elements/area.rb +0 -10
- data/spec/watirspec/relaxed_locate_spec.rb +0 -113
@@ -25,15 +25,19 @@ describe 'TextField' do
|
|
25
25
|
expect(browser.text_field(label: /Without for/)).to exist
|
26
26
|
expect(browser.text_field(label: 'With hidden text')).to exist
|
27
27
|
expect(browser.text_field(label: 'With text')).not_to exist
|
28
|
-
expect(browser.text_field(visible_label: 'With hidden text')).not_to exist
|
29
|
-
expect(browser.text_field(visible_label: 'With text')).to exist
|
30
28
|
|
31
29
|
# These will work after text is deprecated for visible_text
|
32
30
|
# expect(browser.text_field(label: /With hidden text/)).to exist
|
33
31
|
# expect(browser.text_field(label: /With text/)).not_to exist
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
bug 'Safari is not filtering out hidden text', :safari do
|
35
|
+
it 'returns true in spite of hidden text' do
|
36
|
+
expect(browser.text_field(visible_label: 'With hidden text')).not_to exist
|
37
|
+
expect(browser.text_field(visible_label: 'With text')).to exist
|
38
|
+
expect(browser.text_field(visible_label: /With text/)).to exist
|
39
|
+
expect(browser.text_field(visible_label: /With hidden text/)).not_to exist
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
it 'locates value of text_field using text locators' do
|
@@ -29,15 +29,6 @@ describe 'TableRow' do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe '#click' do
|
33
|
-
not_compliant_on :internet_explorer, :chrome, :firefox do
|
34
|
-
it "fires the row's onclick event" do
|
35
|
-
browser.tr(id: 'inner_first').click
|
36
|
-
expect(messages).to include('tr')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
32
|
bug 'Safari does not strip text', :safari do
|
42
33
|
describe '#[]' do
|
43
34
|
let(:table) { browser.table(id: 'outer') }
|
@@ -133,6 +133,7 @@
|
|
133
133
|
<input type="BuTTon" name="new_user_button_preview" id="new_user_button_preview" alt="Create a new user" value="Preview" data-locator="preview"/>
|
134
134
|
<button name="new_user_button_2" type="submit" value="button_2" data-locator="Benjamin">Button 2</button>
|
135
135
|
<button name="new_user_button_3" value="button_3" data-locator="No Type">Button 3</button>
|
136
|
+
<button name="new_user_button_4" value="button_4" data-locator="child text"> Button 4 <span> With Child Text </span> </button>
|
136
137
|
<input type="image" class="image" name="new_user_image" src="images/button.png" alt="Submittable button" data-locator="submittable button"/>
|
137
138
|
<input type="submit" name="new_user_submit_disabled" id="disabled_button" value="Disabled" disabled="disabled" data-locator="disabled" />
|
138
139
|
<input type="checkbox" name="new_user_submit_disabled" id="toggle_button_checkbox" onclick="var elem = document.getElementById('disabled_button'); elem.disabled = !elem.disabled" />
|
@@ -8,5 +8,8 @@
|
|
8
8
|
<h1>Iframes</h1>
|
9
9
|
<iframe src="iframe_1.html" id="iframe_1" name="iframe1" class="half"></iframe>
|
10
10
|
<iframe src="frame_2.html" id="iframe_2" name="iframe2" class="half"></iframe>
|
11
|
+
<div class="wrapper">
|
12
|
+
<iframe src="nested_elements.html" id="iframe_3" name="iframe3"></iframe>
|
13
|
+
</div>
|
11
14
|
</body>
|
12
15
|
</html>
|
@@ -132,9 +132,9 @@
|
|
132
132
|
</div>
|
133
133
|
<div custom-attribute=custom>Custom</div>
|
134
134
|
<div id="visible_text">
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
135
|
+
<a id="all_visible_text">all visible</a>
|
136
|
+
<a id="some_visible_text">some visible<span style="display:none;"> some hidden</span></a>
|
137
|
+
<a id="no_visible_text" style="display:none;">none visible</a>
|
138
|
+
</div>
|
139
139
|
</body>
|
140
140
|
</html>
|
@@ -3,9 +3,21 @@
|
|
3
3
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
4
4
|
<title>Right Click Test</title>
|
5
5
|
<script src="javascript/helpers.js" type="text/javascript" charset="utf-8"></script>
|
6
|
+
<script src="javascript/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
|
6
7
|
</head>
|
8
|
+
<script>
|
9
|
+
$(document).ready(function() {
|
10
|
+
$(document).on("contextmenu", "#click-logger", function(evt){
|
11
|
+
$("#log").append("<p>control=" + evt.ctrlKey + " alt=" + evt.altKey + "</p>");
|
12
|
+
return false;
|
13
|
+
});
|
14
|
+
});
|
15
|
+
</script>
|
7
16
|
<body>
|
8
17
|
<div id="messages"></div>
|
9
18
|
<div id="click" oncontextmenu='WatirSpec.addMessage("right-clicked"); return false'>Right click!</div>
|
19
|
+
<br />
|
20
|
+
<div id="click-logger">Right click with modifiers!</div>
|
21
|
+
<div id="log"></div>
|
10
22
|
</body>
|
11
23
|
</html>
|
@@ -58,14 +58,14 @@
|
|
58
58
|
<body>
|
59
59
|
<div id="foo" custom="" style="display:block;">foo</div>
|
60
60
|
<div id="bar" style="display:none;" onclick='this.innerHTML = "changed"'>bar</div>
|
61
|
-
<a id="show_bar" href="#" onclick="setTimeoutDisplay('bar', 'block',
|
62
|
-
<a id="hide_foo" href="#" onclick="setTimeoutDisplay('foo', 'none',
|
61
|
+
<a id="show_bar" href="#" onclick="setTimeoutDisplay('bar', 'block', 1000);">show bar</a>
|
62
|
+
<a id="hide_foo" href="#" onclick="setTimeoutDisplay('foo', 'none', 1000);">hide foo</a>
|
63
63
|
<a id="remove_foo" href="#" onclick="setTimeoutRemove('foo', 1000);">remove foo</a>
|
64
64
|
<a id="add_foobar" href="#" onclick="setTimeoutAddDisplay('foobar', 'bar', 1000);">add foobar</a>
|
65
65
|
<a id="readd_bar" href="#" onclick="setTimeoutRemove('bar', 500); setTimeoutAddDisplay('bar', 'foo', 1000);">re-add bar</a>
|
66
66
|
<div id="buttons">
|
67
|
-
<button id="btn" type="button" onclick="setDisabled('btn', true, 0)" disabled>Click To Disable!</button>
|
68
|
-
<a id="enable_btn" href="#" onclick="setDisabled('btn', false,
|
67
|
+
<button id="btn" type="button" onclick="setDisabled('btn', true, 0);" disabled>Click To Disable!</button>
|
68
|
+
<a id="enable_btn" href="#" onclick="setDisabled('btn', false, 1000);">enable btn</a>
|
69
69
|
<button id="btn2" style="display:none;" type="button" disabled>Hidden and Disabled</button>
|
70
70
|
<a id="show_and_enable_btn" href="#" onclick="setTimeoutDisplay('btn2', 'block', 500); setDisabled('btn2', false, 1000);">
|
71
71
|
show and enable btn
|
@@ -78,10 +78,10 @@
|
|
78
78
|
<form>
|
79
79
|
<label for="textfield">Not Displayed Yet</label>
|
80
80
|
<input type="textfield" title="Text Displayed" name="textfield" id="textfield" style="display:none;" /> <br />
|
81
|
-
<a id="show_textfield" href="#" onclick="setTimeoutDisplay('textfield', 'block',
|
81
|
+
<a id="show_textfield" href="#" onclick="setTimeoutDisplay('textfield', 'block', 1000);">show textfield</a>
|
82
82
|
<label for="writable">Not Writable</label>
|
83
83
|
<input type="text" title="Not Writable" name="writable" id="writable" readonly/> <br />
|
84
|
-
<a id="make-writable" onclick="makeWritable('writable',
|
84
|
+
<a id="make-writable" onclick="makeWritable('writable', 1000);">Make Writable</a>
|
85
85
|
<fieldset>
|
86
86
|
<select name="languages" id="languages", style="display: none">
|
87
87
|
<option id="danish" value="1">Danish</option>
|
@@ -2,11 +2,21 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>window switching</title>
|
5
|
+
<script>
|
6
|
+
function windowOpenDelayed(timeout) {
|
7
|
+
setTimeout(function() {
|
8
|
+
window.open("closeable.html");
|
9
|
+
}, timeout);
|
10
|
+
}
|
11
|
+
</script>
|
5
12
|
</head>
|
6
13
|
|
7
14
|
<body>
|
8
15
|
<p>
|
9
16
|
Click <a id="open" href="#" onclick='window.open("closeable.html")'>here</a> to open a new window.
|
10
17
|
</p>
|
18
|
+
<p>
|
19
|
+
Click <a id="delayed" href="#" onclick=windowOpenDelayed(1000)>here</a> to open a new window after a delay.
|
20
|
+
</p>
|
11
21
|
</body>
|
12
22
|
</html>
|
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'watirspec_helper'
|
2
|
+
|
3
|
+
describe Watir::Element do
|
4
|
+
before do
|
5
|
+
browser.goto WatirSpec.url_for('wait.html')
|
6
|
+
end
|
7
|
+
|
8
|
+
compliant_on :relaxed_locate do
|
9
|
+
describe '#wait_until_present' do
|
10
|
+
it 'waits until the element appears' do
|
11
|
+
browser.a(id: 'show_bar').click
|
12
|
+
expect {
|
13
|
+
expect { browser.div(id: 'bar').wait_until_present(timeout: 5) }.to_not raise_exception
|
14
|
+
}.to have_deprecated_wait_until_present
|
15
|
+
end
|
16
|
+
|
17
|
+
bug 'Safari does not recognize date type', :safari do
|
18
|
+
it 'waits until the element re-appears' do
|
19
|
+
browser.link(id: 'readd_bar').click
|
20
|
+
expect {
|
21
|
+
expect { browser.div(id: 'bar').wait_until_present }.to_not raise_exception
|
22
|
+
}.to have_deprecated_wait_until_present
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "times out if the element doesn't appear" do
|
27
|
+
inspected = '#<Watir::Div: located: true; {:id=>"bar", :tag_name=>"div"}>'
|
28
|
+
error = Watir::Wait::TimeoutError
|
29
|
+
message = "timed out after 1 seconds, waiting for #{inspected} to become present"
|
30
|
+
|
31
|
+
expect {
|
32
|
+
expect { browser.div(id: 'bar').wait_until_present(timeout: 1) }.to raise_error(error, message)
|
33
|
+
}.to have_deprecated_wait_until_present
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'uses provided interval' do
|
37
|
+
element = browser.div(id: 'bar')
|
38
|
+
expect(element).to receive(:present?).twice
|
39
|
+
|
40
|
+
expect {
|
41
|
+
expect { element.wait_until_present(timeout: 0.4, interval: 0.2) }.to raise_timeout_exception
|
42
|
+
}.to have_deprecated_wait_until_present
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#wait_while_present' do
|
47
|
+
it 'waits until the element disappears' do
|
48
|
+
browser.a(id: 'hide_foo').click
|
49
|
+
expect {
|
50
|
+
expect { browser.div(id: 'foo').wait_while_present(timeout: 2) }.to_not raise_exception
|
51
|
+
}.to have_deprecated_wait_while_present
|
52
|
+
end
|
53
|
+
|
54
|
+
it "times out if the element doesn't disappear" do
|
55
|
+
error = Watir::Wait::TimeoutError
|
56
|
+
inspected = '#<Watir::Div: located: true; {:id=>"foo", :tag_name=>"div"}>'
|
57
|
+
message = "timed out after 1 seconds, waiting for #{inspected} not to be present"
|
58
|
+
expect {
|
59
|
+
expect { browser.div(id: 'foo').wait_while_present(timeout: 1) }.to raise_error(error, message)
|
60
|
+
}.to have_deprecated_wait_while_present
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'uses provided interval' do
|
64
|
+
error = Watir::Wait::TimeoutError
|
65
|
+
element = browser.div(id: 'foo')
|
66
|
+
expect(element).to receive(:present?).and_return(true).twice
|
67
|
+
|
68
|
+
expect {
|
69
|
+
expect { element.wait_while_present(timeout: 0.4, interval: 0.2) }.to raise_error(error)
|
70
|
+
}.to have_deprecated_wait_while_present
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not error when element goes stale' do
|
74
|
+
element = browser.div(id: 'foo').locate
|
75
|
+
|
76
|
+
allow(element).to receive(:stale?).and_return(false, true)
|
77
|
+
|
78
|
+
browser.a(id: 'hide_foo').click
|
79
|
+
expect {
|
80
|
+
expect { element.wait_while_present(timeout: 2) }.to_not raise_exception
|
81
|
+
}.to have_deprecated_wait_while_present
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'waits until the selector no longer matches' do
|
85
|
+
element = browser.link(name: 'add_select').wait_until(&:exists?)
|
86
|
+
browser.link(id: 'change_select').click
|
87
|
+
expect {
|
88
|
+
expect { element.wait_while_present }.not_to raise_error
|
89
|
+
}.to have_deprecated_wait_while_present
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
not_compliant_on :relaxed_locate do
|
95
|
+
describe '#when_present' do
|
96
|
+
it 'invokes subsequent method calls when the element becomes present' do
|
97
|
+
browser.a(id: 'show_bar').click
|
98
|
+
|
99
|
+
bar = browser.div(id: 'bar')
|
100
|
+
bar.when_present(2).click
|
101
|
+
expect(bar.text).to eq 'changed'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'times out when given a block' do
|
105
|
+
expect { browser.div(id: 'bar').when_present(1) {} }.to raise_error(Watir::Wait::TimeoutError)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'times out when not given a block' do
|
109
|
+
locator = '(\{:id=>"bar", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"bar"\})'
|
110
|
+
msg = /^timed out after 1 seconds, waiting for #{locator} to become present$/
|
111
|
+
expect { browser.div(id: 'bar').when_present(1).click }.to raise_error(Watir::Wait::TimeoutError, msg)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'responds to Element methods' do
|
115
|
+
decorator = browser.div.when_present
|
116
|
+
|
117
|
+
expect(decorator).to respond_to(:exist?)
|
118
|
+
expect(decorator).to respond_to(:present?)
|
119
|
+
expect(decorator).to respond_to(:click)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'delegates present? to element' do
|
123
|
+
Object.class_eval do
|
124
|
+
def present?
|
125
|
+
false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
element = browser.a(id: 'show_bar').when_present(1)
|
129
|
+
expect(element).to be_present
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'processes before calling present?' do
|
133
|
+
browser.a(id: 'show_bar').click
|
134
|
+
expect(browser.div(id: 'bar').when_present.present?).to be true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '#wait_until &:enabled?' do
|
139
|
+
it 'invokes subsequent method calls when the element becomes enabled' do
|
140
|
+
browser.a(id: 'enable_btn').click
|
141
|
+
|
142
|
+
btn = browser.button(id: 'btn')
|
143
|
+
btn.wait_until(timeout: 2, &:enabled?).click
|
144
|
+
Watir::Wait.while { btn.enabled? }
|
145
|
+
expect(btn.disabled?).to be true
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'times out' do
|
149
|
+
error = Watir::Wait::TimeoutError
|
150
|
+
inspected = '#<Watir::Button: located: true; {:id=>"btn", :tag_name=>"button"}>'
|
151
|
+
message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
|
152
|
+
element = browser.button(id: 'btn')
|
153
|
+
expect { element.wait_until(timeout: 1, &:enabled?).click }.to raise_error(error, message)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'responds to Element methods' do
|
157
|
+
element = browser.button.wait_until { true }
|
158
|
+
|
159
|
+
expect(element).to respond_to(:exist?)
|
160
|
+
expect(element).to respond_to(:present?)
|
161
|
+
expect(element).to respond_to(:click)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'can be chained with #wait_until &:present?' do
|
165
|
+
browser.a(id: 'show_and_enable_btn').click
|
166
|
+
browser.button(id: 'btn2').wait_until(&:present?).wait_until(&:enabled?).click
|
167
|
+
|
168
|
+
expect(browser.button(id: 'btn2')).to exist
|
169
|
+
expect(browser.button(id: 'btn2')).to be_enabled
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'when acting on an element that is never present' do
|
174
|
+
it 'raises exception immediately' do
|
175
|
+
element = browser.link(id: 'not_there')
|
176
|
+
start_time = ::Time.now
|
177
|
+
expect { element.click }.to raise_exception(Watir::Exception::UnknownObjectException)
|
178
|
+
expect(::Time.now - start_time).to be < 1
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when acting on an element that eventually becomes present' do
|
183
|
+
it 'raises exception immediately' do
|
184
|
+
start_time = ::Time.now
|
185
|
+
browser.a(id: 'show_bar').click
|
186
|
+
|
187
|
+
expect { browser.div(id: 'bar').click }.to raise_unknown_object_exception
|
188
|
+
|
189
|
+
expect(::Time.now - start_time).to be < 1
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe Watir::Window do
|
196
|
+
not_compliant_on :relaxed_locate do
|
197
|
+
describe '#wait_until &:present?' do
|
198
|
+
before do
|
199
|
+
browser.goto WatirSpec.url_for('window_switching.html')
|
200
|
+
browser.a(id: 'open').click
|
201
|
+
Watir::Wait.until { browser.windows.size == 2 }
|
202
|
+
end
|
203
|
+
|
204
|
+
after do
|
205
|
+
browser.original_window.use
|
206
|
+
browser.windows.reject(&:current?).each(&:close)
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'times out waiting for a non-present window' do
|
210
|
+
expect {
|
211
|
+
browser.window(title: 'noop').wait_until(timeout: 0.5, &:present?)
|
212
|
+
}.to raise_error(Watir::Wait::TimeoutError)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -8,13 +8,16 @@ if defined?(RSpec)
|
|
8
8
|
visible_text
|
9
9
|
link_text
|
10
10
|
text_regexp
|
11
|
+
scroll_into_view
|
11
12
|
stale_exists
|
12
13
|
stale_visible
|
13
14
|
stale_present
|
15
|
+
select_all
|
14
16
|
select_by
|
15
17
|
value_button
|
16
18
|
wait_until_present
|
17
|
-
wait_while_present
|
19
|
+
wait_while_present
|
20
|
+
window_index].freeze
|
18
21
|
|
19
22
|
DEPRECATION_WARNINGS.each do |deprecation|
|
20
23
|
RSpec::Matchers.define "have_deprecated_#{deprecation}" do
|
@@ -62,10 +65,10 @@ if defined?(RSpec)
|
|
62
65
|
begin
|
63
66
|
actual.call
|
64
67
|
false
|
65
|
-
rescue exception =>
|
66
|
-
return true if message.nil? ||
|
68
|
+
rescue exception => e
|
69
|
+
return true if message.nil? || e.message.match(message)
|
67
70
|
|
68
|
-
raise exception, "expected '#{message}' to be included in: '#{
|
71
|
+
raise exception, "expected '#{message}' to be included in: '#{e.message}'"
|
69
72
|
ensure
|
70
73
|
Watir.default_timeout = original_timeout
|
71
74
|
end
|
@@ -88,10 +91,10 @@ if defined?(RSpec)
|
|
88
91
|
start_time = ::Time.now
|
89
92
|
actual.call
|
90
93
|
false
|
91
|
-
rescue exception =>
|
94
|
+
rescue exception => e
|
92
95
|
finish_time = ::Time.now
|
93
|
-
unless message.nil? ||
|
94
|
-
raise exception, "expected '#{message}' to be included in: '#{
|
96
|
+
unless message.nil? || e.message.match(message)
|
97
|
+
raise exception, "expected '#{message}' to be included in: '#{e.message}'"
|
95
98
|
end
|
96
99
|
|
97
100
|
@time_difference = finish_time - start_time
|
@@ -116,27 +119,28 @@ if defined?(RSpec)
|
|
116
119
|
end
|
117
120
|
end
|
118
121
|
|
119
|
-
RSpec::Matchers.define :
|
122
|
+
RSpec::Matchers.define :execute_when_satisfied do |min: 0, max: nil|
|
123
|
+
max ||= min + 1
|
120
124
|
match do |actual|
|
121
125
|
original_timeout = Watir.default_timeout
|
122
|
-
Watir.default_timeout =
|
126
|
+
Watir.default_timeout = max
|
123
127
|
begin
|
124
128
|
start_time = ::Time.now
|
125
129
|
actual.call
|
126
130
|
@time_difference = ::Time.now - start_time
|
127
|
-
@time_difference <
|
131
|
+
@time_difference > min && @time_difference < max
|
128
132
|
ensure
|
129
133
|
Watir.default_timeout = original_timeout
|
130
134
|
end
|
131
135
|
end
|
132
136
|
|
133
137
|
failure_message_when_negated do
|
134
|
-
"expected action to take
|
138
|
+
"expected action to take less than #{min} seconds or more than #{max} seconds, " \
|
135
139
|
"instead it took #{@time_difference} seconds"
|
136
140
|
end
|
137
141
|
|
138
142
|
failure_message do
|
139
|
-
"expected action to take
|
143
|
+
"expected action to take more than #{min} seconds and less than #{max} seconds, " \
|
140
144
|
"instead it took #{@time_difference} seconds"
|
141
145
|
end
|
142
146
|
|
@@ -147,7 +151,7 @@ if defined?(RSpec)
|
|
147
151
|
|
148
152
|
RSpec::Matchers.define :exist do |*args|
|
149
153
|
match do |actual|
|
150
|
-
actual.
|
154
|
+
actual.exist?(*args)
|
151
155
|
end
|
152
156
|
|
153
157
|
failure_message do |obj|
|