watir 6.5.0 → 6.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +58 -21
- data/CHANGES.md +11 -0
- data/Rakefile +3 -5
- data/lib/watir.rb +14 -2
- data/lib/watir/adjacent.rb +20 -27
- data/lib/watir/alert.rb +1 -1
- data/lib/watir/attribute_helper.rb +1 -1
- data/lib/watir/browser.rb +6 -3
- data/lib/watir/capabilities.rb +95 -0
- data/lib/watir/cookies.rb +5 -6
- data/lib/watir/element_collection.rb +17 -0
- data/lib/watir/elements/element.rb +12 -15
- data/lib/watir/elements/iframe.rb +1 -1
- data/lib/watir/elements/option.rb +5 -6
- data/lib/watir/elements/select.rb +52 -36
- data/lib/watir/legacy_wait.rb +2 -2
- data/lib/watir/locators/button/selector_builder.rb +10 -7
- data/lib/watir/locators/element/locator.rb +2 -2
- data/lib/watir/locators/element/selector_builder.rb +10 -4
- data/lib/watir/locators/element/selector_builder/xpath.rb +22 -3
- data/lib/watir/logger.rb +109 -0
- data/lib/watir/wait.rb +6 -6
- data/lib/watirspec.rb +1 -1
- data/lib/watirspec/guards.rb +4 -4
- data/lib/watirspec/implementation.rb +13 -5
- data/lib/watirspec/remote_server.rb +38 -0
- data/lib/watirspec/runner.rb +2 -2
- data/lib/watirspec/server.rb +1 -1
- data/spec/browser_spec.rb +101 -17
- data/spec/element_locator_spec.rb +1 -1
- data/spec/element_spec.rb +1 -1
- data/spec/logger_spec.rb +46 -0
- data/spec/watirspec/adjacent_spec.rb +45 -0
- data/spec/watirspec/after_hooks_spec.rb +45 -40
- data/spec/watirspec/alert_spec.rb +20 -14
- data/spec/watirspec/browser_spec.rb +71 -77
- data/spec/watirspec/cookies_spec.rb +13 -16
- data/spec/watirspec/drag_and_drop_spec.rb +6 -6
- data/spec/watirspec/elements/button_spec.rb +14 -7
- data/spec/watirspec/elements/collections_spec.rb +18 -1
- data/spec/watirspec/elements/dd_spec.rb +4 -2
- data/spec/watirspec/elements/del_spec.rb +12 -10
- data/spec/watirspec/elements/div_spec.rb +17 -13
- data/spec/watirspec/elements/dl_spec.rb +4 -2
- data/spec/watirspec/elements/form_spec.rb +8 -6
- data/spec/watirspec/elements/frame_spec.rb +27 -19
- data/spec/watirspec/elements/iframe_spec.rb +28 -17
- data/spec/watirspec/elements/ins_spec.rb +12 -10
- data/spec/watirspec/elements/option_spec.rb +17 -33
- data/spec/watirspec/elements/select_list_spec.rb +111 -97
- data/spec/watirspec/elements/span_spec.rb +12 -10
- data/spec/watirspec/elements/table_spec.rb +13 -11
- data/spec/watirspec/elements/tbody_spec.rb +13 -11
- data/spec/watirspec/elements/td_spec.rb +6 -4
- data/spec/watirspec/elements/text_field_spec.rb +19 -17
- data/spec/watirspec/elements/tr_spec.rb +12 -8
- data/spec/watirspec/html/javascript/helpers.js +2 -2
- data/spec/watirspec/html/nested_elements.html +5 -5
- data/spec/watirspec/relaxed_locate_spec.rb +13 -19
- data/spec/watirspec/wait_spec.rb +279 -301
- data/spec/watirspec/window_switching_spec.rb +190 -174
- data/spec/watirspec_helper.rb +64 -122
- data/support/doctest_helper.rb +4 -0
- data/watir.gemspec +2 -2
- metadata +15 -4
@@ -113,16 +113,18 @@ describe "Span" do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
# Other
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
116
|
+
not_compliant_on :headless do
|
117
|
+
describe "#click" do
|
118
|
+
it "fires events" do
|
119
|
+
expect(browser.span(class: 'footer').text).to_not include('Javascript')
|
120
|
+
browser.span(class: 'footer').click
|
121
|
+
expect(browser.span(class: 'footer').text).to include('Javascript')
|
122
|
+
end
|
123
|
+
|
124
|
+
it "raises UnknownObjectException if the span doesn't exist" do
|
125
|
+
expect { browser.span(id: "no_such_id").click }.to raise_unknown_object_exception
|
126
|
+
expect { browser.span(title: "no_such_title").click }.to raise_unknown_object_exception
|
127
|
+
end
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
@@ -41,17 +41,19 @@ describe "Table" do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# Other
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
bug "Safari does not strip text", :safari do
|
45
|
+
describe "#strings" do
|
46
|
+
it "returns a two-dimensional array representation of the table" do
|
47
|
+
expect(browser.table(id: 'inner').strings).to eq [
|
48
|
+
["Table 2, Row 1, Cell 1",
|
49
|
+
"Table 2, Row 1, Cell 2"]
|
50
|
+
]
|
51
|
+
expect(browser.table(id: 'outer').strings).to eq [
|
52
|
+
["Table 1, Row 1, Cell 1", "Table 1, Row 1, Cell 2"],
|
53
|
+
["Table 1, Row 2, Cell 1", "Table 1, Row 2, Cell 2\nTable 2, Row 1, Cell 1 Table 2, Row 1, Cell 2"],
|
54
|
+
["Table 1, Row 3, Cell 1", "Table 1, Row 3, Cell 2"]
|
55
|
+
]
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -50,17 +50,19 @@ describe "TableBody" do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
53
|
+
bug "Safari does not strip text", :safari do
|
54
|
+
describe "#[]" do
|
55
|
+
it "returns the row at the given index (page context)" do
|
56
|
+
expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008'
|
57
|
+
expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
58
|
+
expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns the row at the given index (table context)" do
|
62
|
+
expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008'
|
63
|
+
expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
64
|
+
expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
65
|
+
end
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
@@ -47,10 +47,12 @@ describe "TableCell" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# Attribute methods
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
bug "Safari does not strip text", :safari do
|
51
|
+
describe "#text" do
|
52
|
+
it "returns the text inside the table cell" do
|
53
|
+
expect(browser.td(id: 't1_r2_c1').text).to eq 'Table 1, Row 2, Cell 1'
|
54
|
+
expect(browser.td(id: 't2_r1_c1').text).to eq 'Table 2, Row 1, Cell 1'
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
@@ -204,27 +204,29 @@ describe "TextField" do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
# Manipulation methods
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
207
|
+
not_compliant_on :safari do
|
208
|
+
describe "#append" do
|
209
|
+
it "appends the text to the text field" do
|
210
|
+
browser.text_field(name: "new_user_occupation").append(" Append This")
|
211
|
+
expect(browser.text_field(name: "new_user_occupation").value).to eq "Developer Append This"
|
212
|
+
end
|
212
213
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
214
|
+
it "appends multi-byte characters" do
|
215
|
+
browser.text_field(name: "new_user_occupation").append(" ijij")
|
216
|
+
expect(browser.text_field(name: "new_user_occupation").value).to eq "Developer ijij"
|
217
|
+
end
|
217
218
|
|
218
|
-
|
219
|
-
|
220
|
-
|
219
|
+
it "raises ObjectReadOnlyException if the object is read only" do
|
220
|
+
expect { browser.text_field(id: "new_user_code").append("Append This") }.to raise_object_read_only_exception
|
221
|
+
end
|
221
222
|
|
222
|
-
|
223
|
-
|
224
|
-
|
223
|
+
it "raises ObjectDisabledException if the object is disabled" do
|
224
|
+
expect { browser.text_field(name: "new_user_species").append("Append This") }.to raise_object_disabled_exception
|
225
|
+
end
|
225
226
|
|
226
|
-
|
227
|
-
|
227
|
+
it "raises UnknownObjectException if the object doesn't exist" do
|
228
|
+
expect { browser.text_field(name: "no_such_name").append("Append This") }.to raise_unknown_object_exception
|
229
|
+
end
|
228
230
|
end
|
229
231
|
end
|
230
232
|
|
@@ -36,19 +36,23 @@ describe "TableRow" do
|
|
36
36
|
|
37
37
|
describe "#click" do
|
38
38
|
bug "http://github.com/watir/watir/issues/issue/32", :internet_explorer, :chrome do
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
not_compliant_on :firefox do
|
40
|
+
it "fires the row's onclick event" do
|
41
|
+
browser.tr(id: 'inner_first').click
|
42
|
+
expect(messages).to include('tr')
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
bug "Safari does not strip text", :safari do
|
49
|
+
describe "#[]" do
|
50
|
+
let(:table) { browser.table(id: 'outer') }
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
it "returns the nth cell of the row" do
|
53
|
+
expect(table[0][0].text).to eq "Table 1, Row 1, Cell 1"
|
54
|
+
expect(table[2][0].text).to eq "Table 1, Row 3, Cell 1"
|
55
|
+
end
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
@@ -2,11 +2,11 @@ var WatirSpec = function() {
|
|
2
2
|
|
3
3
|
return {
|
4
4
|
addMessage: function(string) {
|
5
|
-
var text = document.createTextNode(string)
|
5
|
+
var text = document.createTextNode(string);
|
6
6
|
var message = document.createElement('div');
|
7
7
|
var messages = document.getElementById('messages');
|
8
8
|
|
9
|
-
message.appendChild(text)
|
9
|
+
message.appendChild(text);
|
10
10
|
messages.appendChild(message);
|
11
11
|
}
|
12
12
|
};
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<body>
|
9
9
|
<span id="grandparent_span">
|
10
10
|
<div id="grandparent">
|
11
|
-
<span id="parent_span">
|
11
|
+
<span class="parent" id="parent_span">
|
12
12
|
<div id="parent">
|
13
13
|
<div id="first_sibling">
|
14
14
|
<span id="child_span">
|
@@ -22,10 +22,10 @@
|
|
22
22
|
<div id="youngest_child"></div>
|
23
23
|
</span>
|
24
24
|
</div>
|
25
|
-
<span id="between_siblings1"></span>
|
26
|
-
<div id="second_sibling"></div>
|
27
|
-
<span id="between_siblings2"></span>
|
28
|
-
<div id="third_sibling"
|
25
|
+
<span class="a" id="between_siblings1"></span>
|
26
|
+
<div class="b" id="second_sibling"></div>
|
27
|
+
<span class="a" id="between_siblings2"></span>
|
28
|
+
<div class="a b" id="third_sibling">text</div>
|
29
29
|
</div>
|
30
30
|
</span>
|
31
31
|
</div>
|
@@ -26,10 +26,10 @@ describe 'Watir#relaxed_locate?' do
|
|
26
26
|
context 'when acting on an element that is already present' do
|
27
27
|
it 'does not wait' do
|
28
28
|
begin
|
29
|
-
Watir.default_timeout =
|
29
|
+
Watir.default_timeout = 5
|
30
30
|
start_time = ::Time.now
|
31
31
|
expect { browser.link.click }.to_not raise_exception
|
32
|
-
expect(::Time.now - start_time).to be <
|
32
|
+
expect(::Time.now - start_time).to be < 5
|
33
33
|
ensure
|
34
34
|
Watir.default_timeout = 30
|
35
35
|
end
|
@@ -37,15 +37,17 @@ describe 'Watir#relaxed_locate?' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'when acting on an element that eventually becomes present' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
bug "https://github.com/SeleniumHQ/selenium/issues/4380", %i{remote firefox} do
|
41
|
+
it 'waits until present and then takes action' do
|
42
|
+
begin
|
43
|
+
Watir.default_timeout = 3
|
44
|
+
start_time = ::Time.now
|
45
|
+
browser.a(id: 'show_bar').click
|
46
|
+
expect { browser.div(id: 'bar').click }.to_not raise_exception
|
47
|
+
expect(::Time.now - start_time).to be < 3
|
48
|
+
ensure
|
49
|
+
Watir.default_timeout = 30
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -92,14 +94,6 @@ describe 'Watir#relaxed_locate?' do
|
|
92
94
|
expect(::Time.now - start_time).to be < 1
|
93
95
|
end
|
94
96
|
end
|
95
|
-
|
96
|
-
it 'receives a warning for using #when_present' do
|
97
|
-
message = /#when_present has been deprecated and is unlikely to be needed; replace this with #wait_until_present if a wait is still needed/
|
98
|
-
browser.a(id: 'show_bar').click
|
99
|
-
expect do
|
100
|
-
browser.div(id: 'bar').when_present.click
|
101
|
-
end.to output(message).to_stderr
|
102
|
-
end
|
103
97
|
end
|
104
98
|
end
|
105
99
|
end
|
data/spec/watirspec/wait_spec.rb
CHANGED
@@ -1,398 +1,376 @@
|
|
1
1
|
require "watirspec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
describe Watir::Wait do
|
4
|
+
describe "#until" do
|
5
|
+
it "waits until the block returns true" do
|
6
|
+
Watir::Wait.until(timeout: 0.5) { @result = true }
|
7
|
+
expect(@result).to be true
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
it "executes block if timeout is zero" do
|
11
|
+
Watir::Wait.until(timeout: 0) { @result = true }
|
12
|
+
expect(@result).to be true
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
it "times out" do
|
16
|
+
expect { Watir::Wait.until(timeout: 0.5) { false } }.to raise_error(Watir::Wait::TimeoutError)
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
it "times out with a custom message" do
|
20
|
+
expect {
|
21
|
+
Watir::Wait.until(timeout: 0.5, message: "oops") { false }
|
22
|
+
}.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
rescue Watir::Wait::TimeoutError
|
25
|
+
it "uses provided interval" do
|
26
|
+
begin
|
27
|
+
Watir::Wait.until(timeout: 0.4, interval: 0.2) do
|
28
|
+
@result = @result.nil? ? 1 : @result + 1
|
29
|
+
false
|
33
30
|
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
it "uses timer for waiting" do
|
38
|
-
timer = Watir::Wait.timer
|
39
|
-
expect(timer).to receive(:wait).with(0.5).and_call_original
|
40
|
-
Watir::Wait.until(timeout: 0.5) { true }
|
31
|
+
rescue Watir::Wait::TimeoutError
|
41
32
|
end
|
33
|
+
expect(@result).to eq 2
|
34
|
+
end
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
it "uses timer for waiting" do
|
37
|
+
timer = Watir::Wait.timer
|
38
|
+
expect(timer).to receive(:wait).with(0.5).and_call_original
|
39
|
+
Watir::Wait.until(timeout: 0.5) { true }
|
47
40
|
end
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
describe "#while" do
|
44
|
+
it "waits while the block returns true" do
|
45
|
+
expect(Watir::Wait.while(timeout: 0.5) { false }).to be_nil
|
46
|
+
end
|
53
47
|
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
it "executes block if timeout is zero" do
|
49
|
+
expect(Watir::Wait.while(timeout: 0) { false }).to be_nil
|
50
|
+
end
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
|
52
|
+
it "times out" do
|
53
|
+
expect { Watir::Wait.while(timeout: 0.5) { true } }.to raise_error(Watir::Wait::TimeoutError)
|
54
|
+
end
|
61
55
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
it "times out with a custom message" do
|
57
|
+
expect {
|
58
|
+
Watir::Wait.while(timeout: 0.5, message: "oops") { true }
|
59
|
+
}.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
|
60
|
+
end
|
67
61
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
rescue Watir::Wait::TimeoutError
|
62
|
+
it "uses provided interval" do
|
63
|
+
begin
|
64
|
+
Watir::Wait.while(timeout: 0.4, interval: 0.2) do
|
65
|
+
@result = @result.nil? ? 1 : @result + 1
|
66
|
+
true
|
75
67
|
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
it "uses timer for waiting" do
|
80
|
-
timer = Watir::Wait.timer
|
81
|
-
expect(timer).to receive(:wait).with(0.5).and_call_original
|
82
|
-
Watir::Wait.while(timeout: 0.5) { false }
|
68
|
+
rescue Watir::Wait::TimeoutError
|
83
69
|
end
|
70
|
+
expect(@result).to eq 2
|
71
|
+
end
|
84
72
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
73
|
+
it "uses timer for waiting" do
|
74
|
+
timer = Watir::Wait.timer
|
75
|
+
expect(timer).to receive(:wait).with(0.5).and_call_original
|
76
|
+
Watir::Wait.while(timeout: 0.5) { false }
|
89
77
|
end
|
78
|
+
end
|
90
79
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
80
|
+
describe "#timer" do
|
81
|
+
it "returns default timer" do
|
82
|
+
expect(Watir::Wait.timer).to be_a(Watir::Wait::Timer)
|
95
83
|
end
|
84
|
+
end
|
96
85
|
|
97
|
-
|
98
|
-
|
86
|
+
describe "#timer=" do
|
87
|
+
after { Watir::Wait.timer = nil }
|
99
88
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
89
|
+
it "changes default timer" do
|
90
|
+
timer = Class.new
|
91
|
+
Watir::Wait.timer = timer
|
92
|
+
expect(Watir::Wait.timer).to eq(timer)
|
105
93
|
end
|
106
94
|
end
|
95
|
+
end
|
107
96
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
97
|
+
describe Watir::Element do
|
98
|
+
before do
|
99
|
+
browser.goto WatirSpec.url_for("wait.html")
|
100
|
+
end
|
112
101
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
102
|
+
# TODO: This is deprecated; remove in future version
|
103
|
+
not_compliant_on :relaxed_locate do
|
104
|
+
describe "#when_present" do
|
105
|
+
it "invokes subsequent method calls when the element becomes present" do
|
106
|
+
browser.a(id: 'show_bar').click
|
118
107
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
108
|
+
bar = browser.div(id: 'bar')
|
109
|
+
bar.when_present(2).click
|
110
|
+
expect(bar.text).to eq "changed"
|
111
|
+
end
|
123
112
|
|
124
|
-
|
125
|
-
|
126
|
-
|
113
|
+
it "times out when given a block" do
|
114
|
+
expect { browser.div(id: 'bar').when_present(1) {} }.to raise_error(Watir::Wait::TimeoutError)
|
115
|
+
end
|
127
116
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
117
|
+
it "times out when not given a block" do
|
118
|
+
message = /^timed out after 1 seconds, waiting for (\{:id=>"bar", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"bar"\}) to become present$/
|
119
|
+
expect { browser.div(id: 'bar').when_present(1).click }.to raise_error(Watir::Wait::TimeoutError, message)
|
120
|
+
end
|
132
121
|
|
133
|
-
|
134
|
-
|
122
|
+
it "responds to Element methods" do
|
123
|
+
decorator = browser.div.when_present
|
135
124
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
125
|
+
expect(decorator).to respond_to(:exist?)
|
126
|
+
expect(decorator).to respond_to(:present?)
|
127
|
+
expect(decorator).to respond_to(:click)
|
128
|
+
end
|
140
129
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
130
|
+
it "delegates present? to element" do
|
131
|
+
Object.class_eval do
|
132
|
+
def present?
|
133
|
+
false
|
146
134
|
end
|
147
|
-
element = browser.a(id: "show_bar").when_present(1)
|
148
|
-
expect(element).to be_present
|
149
135
|
end
|
136
|
+
element = browser.a(id: "show_bar").when_present(1)
|
137
|
+
expect(element).to be_present
|
138
|
+
end
|
150
139
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
140
|
+
it "processes before calling present?" do
|
141
|
+
browser.a(id: 'show_bar').click
|
142
|
+
expect(browser.div(id: 'bar').when_present.present?).to be true
|
155
143
|
end
|
156
144
|
end
|
145
|
+
end
|
157
146
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
147
|
+
not_compliant_on :relaxed_locate do
|
148
|
+
describe "#wait_until &:enabled?" do
|
149
|
+
it "invokes subsequent method calls when the element becomes enabled" do
|
150
|
+
browser.a(id: 'enable_btn').click
|
162
151
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
152
|
+
btn = browser.button(id: 'btn')
|
153
|
+
btn.wait_until(timeout: 2, &:enabled?).click
|
154
|
+
Watir::Wait.while { btn.enabled? }
|
155
|
+
expect(btn.disabled?).to be true
|
156
|
+
end
|
168
157
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
158
|
+
it "times out" do
|
159
|
+
error = Watir::Wait::TimeoutError
|
160
|
+
inspected = '#<Watir::Button: located: false; {:id=>"btn", :tag_name=>"button"}>'
|
161
|
+
message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
|
162
|
+
element = browser.button(id: 'btn')
|
163
|
+
expect { element.wait_until(timeout: 1, &:enabled?).click }.to raise_error(error, message)
|
164
|
+
end
|
176
165
|
|
177
|
-
|
178
|
-
|
166
|
+
it "responds to Element methods" do
|
167
|
+
element = browser.button.wait_until { true }
|
179
168
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
169
|
+
expect(element).to respond_to(:exist?)
|
170
|
+
expect(element).to respond_to(:present?)
|
171
|
+
expect(element).to respond_to(:click)
|
172
|
+
end
|
184
173
|
|
185
|
-
|
186
|
-
|
187
|
-
|
174
|
+
it "can be chained with #wait_until &:present?" do
|
175
|
+
browser.a(id: 'show_and_enable_btn').click
|
176
|
+
browser.button(id: 'btn2').wait_until(&:present?).wait_until(&:enabled?).click
|
188
177
|
|
189
|
-
|
190
|
-
|
191
|
-
end
|
178
|
+
expect(browser.button(id: 'btn2')).to exist
|
179
|
+
expect(browser.button(id: 'btn2')).to be_enabled
|
192
180
|
end
|
193
181
|
end
|
182
|
+
end
|
194
183
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
it "times out if the element doesn't appear" do
|
202
|
-
inspected = '#<Watir::Div: located: false; {:id=>"bar", :tag_name=>"div"}>'
|
203
|
-
error = Watir::Wait::TimeoutError
|
204
|
-
message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
|
205
|
-
|
206
|
-
expect { browser.div(id: 'bar').wait_until_present(timeout: 1) }.to raise_error(error, message)
|
207
|
-
end
|
184
|
+
describe "#wait_until_present" do
|
185
|
+
it "waits until the element appears" do
|
186
|
+
browser.a(id: 'show_bar').click
|
187
|
+
expect { browser.div(id: 'bar').wait_until_present(timeout: 5) }.to_not raise_exception
|
188
|
+
end
|
208
189
|
|
209
|
-
|
210
|
-
|
211
|
-
|
190
|
+
it "times out if the element doesn't appear" do
|
191
|
+
inspected = '#<Watir::Div: located: false; {:id=>"bar", :tag_name=>"div"}>'
|
192
|
+
error = Watir::Wait::TimeoutError
|
193
|
+
message = "timed out after 1 seconds, waiting for true condition on #{inspected}"
|
212
194
|
|
213
|
-
|
214
|
-
|
215
|
-
rescue Watir::Wait::TimeoutError
|
216
|
-
end
|
217
|
-
end
|
195
|
+
expect { browser.div(id: 'bar').wait_until_present(timeout: 1) }.to raise_error(error, message)
|
196
|
+
end
|
218
197
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
expect { browser.div(id: 'bar').wait_until_present(5) }.to output(message).to_stderr
|
223
|
-
end
|
198
|
+
it "uses provided interval" do
|
199
|
+
element = browser.div(id: 'bar')
|
200
|
+
expect(element).to receive(:present?).twice
|
224
201
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
Watir.default_timeout = 1
|
229
|
-
begin
|
230
|
-
start_time = ::Time.now
|
231
|
-
expect { select_list.select('No') }.to raise_error Watir::Exception::NoValueFoundException
|
232
|
-
expect(::Time.now - start_time).to be > 1
|
233
|
-
ensure
|
234
|
-
Watir.default_timeout = 30
|
235
|
-
end
|
202
|
+
begin
|
203
|
+
element.wait_until_present(timeout: 0.4, interval: 0.2)
|
204
|
+
rescue Watir::Wait::TimeoutError
|
236
205
|
end
|
237
206
|
end
|
238
207
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
208
|
+
it 'waits to select an option' do
|
209
|
+
browser.a(id: 'add_select').click
|
210
|
+
select_list = browser.select_list(id: 'languages')
|
211
|
+
Watir.default_timeout = 1
|
212
|
+
begin
|
213
|
+
start_time = ::Time.now
|
214
|
+
expect { select_list.select('No') }.to raise_error Watir::Exception::NoValueFoundException
|
215
|
+
expect(::Time.now - start_time).to be > 1
|
216
|
+
ensure
|
217
|
+
Watir.default_timeout = 30
|
243
218
|
end
|
219
|
+
end
|
220
|
+
end
|
244
221
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
end
|
222
|
+
describe "#wait_while_present" do
|
223
|
+
it "waits until the element disappears" do
|
224
|
+
browser.a(id: 'hide_foo').click
|
225
|
+
expect { browser.div(id: 'foo').wait_while_present(timeout: 2) }.to_not raise_exception
|
226
|
+
end
|
251
227
|
|
252
|
-
|
253
|
-
|
254
|
-
|
228
|
+
it "times out if the element doesn't disappear" do
|
229
|
+
error = Watir::Wait::TimeoutError
|
230
|
+
inspected = '#<Watir::Div: located: false; {:id=>"foo", :tag_name=>"div"}>'
|
231
|
+
message = "timed out after 1 seconds, waiting for false condition on #{inspected}"
|
232
|
+
expect { browser.div(id: 'foo').wait_while_present(timeout: 1) }.to raise_error(error, message)
|
233
|
+
end
|
255
234
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
260
|
-
end
|
235
|
+
it "uses provided interval" do
|
236
|
+
element = browser.div(id: 'foo')
|
237
|
+
expect(element).to receive(:present?).twice
|
261
238
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
expect { browser.div(id: 'foo').wait_while_present(5) }.to output(message).to_stderr
|
239
|
+
begin
|
240
|
+
element.wait_until_present(timeout: 0.4, interval: 0.2)
|
241
|
+
rescue Watir::Wait::TimeoutError
|
266
242
|
end
|
243
|
+
end
|
267
244
|
|
268
|
-
|
269
|
-
|
245
|
+
it "does not error when element goes stale" do
|
246
|
+
element = browser.div(id: 'foo')
|
270
247
|
|
271
|
-
|
272
|
-
|
248
|
+
allow(element).to receive(:stale?).and_return(false, true)
|
249
|
+
allow(element.wd).to receive(:displayed?).and_raise(Selenium::WebDriver::Error::StaleElementReferenceError)
|
273
250
|
|
274
|
-
|
275
|
-
|
276
|
-
|
251
|
+
browser.a(id: 'hide_foo').click
|
252
|
+
expect { element.wait_while_present(timeout: 1) }.to_not raise_exception
|
253
|
+
end
|
277
254
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
end
|
255
|
+
it "waits until the selector no longer matches" do
|
256
|
+
Watir.default_timeout = 1
|
257
|
+
element = browser.link(name: 'add_select').wait_until(&:exists?)
|
258
|
+
begin
|
259
|
+
start_time = ::Time.now
|
260
|
+
browser.link(id: 'change_select').click
|
261
|
+
expect { element.wait_while_present }.not_to raise_error
|
262
|
+
ensure
|
263
|
+
Watir.default_timeout = 30
|
288
264
|
end
|
289
265
|
end
|
266
|
+
end
|
290
267
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
268
|
+
describe "#wait_until" do
|
269
|
+
it "returns element for additional actions" do
|
270
|
+
element = browser.div(id: 'foo')
|
271
|
+
expect(element.wait_until(&:exist?)).to eq element
|
272
|
+
end
|
296
273
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
274
|
+
it "accepts self in block" do
|
275
|
+
element = browser.div(id: 'bar')
|
276
|
+
browser.a(id: 'show_bar').click
|
277
|
+
expect { element.wait_until { |el| el.text == 'bar' } }.to_not raise_exception
|
278
|
+
end
|
302
279
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
280
|
+
it "accepts any values in block" do
|
281
|
+
element = browser.div(id: 'bar')
|
282
|
+
expect { element.wait_until { true } }.to_not raise_exception
|
283
|
+
end
|
307
284
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
285
|
+
it "accepts just a timeout parameter" do
|
286
|
+
element = browser.div(id: 'bar')
|
287
|
+
expect { element.wait_until(timeout: 0) { true } }.to_not raise_exception
|
288
|
+
end
|
312
289
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
290
|
+
it "accepts just a message parameter" do
|
291
|
+
element = browser.div(id: 'bar')
|
292
|
+
expect { element.wait_until(message: 'no') { true } }.to_not raise_exception
|
293
|
+
end
|
317
294
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
end
|
295
|
+
it "accepts just an interval parameter" do
|
296
|
+
element = browser.div(id: 'bar')
|
297
|
+
expect { element.wait_until(interval: 0.1) { true } }.to_not raise_exception
|
322
298
|
end
|
299
|
+
end
|
323
300
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
301
|
+
describe "#wait_while" do
|
302
|
+
it "returns element for additional actions" do
|
303
|
+
element = browser.div(id: 'foo')
|
304
|
+
browser.a(id: 'hide_foo').click
|
305
|
+
expect(element.wait_while(&:present?)).to eq element
|
306
|
+
end
|
330
307
|
|
308
|
+
not_compliant_on :safari do
|
331
309
|
it "accepts self in block" do
|
332
310
|
element = browser.div(id: 'foo')
|
333
311
|
browser.a(id: 'hide_foo').click
|
334
312
|
expect { element.wait_while { |el| el.text == 'foo' } }.to_not raise_exception
|
335
313
|
end
|
314
|
+
end
|
336
315
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
316
|
+
it "accepts any values in block" do
|
317
|
+
element = browser.div(id: 'foo')
|
318
|
+
expect { element.wait_while { false } }.to_not raise_exception
|
319
|
+
end
|
341
320
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
321
|
+
it "accepts just a timeout parameter" do
|
322
|
+
element = browser.div(id: 'foo')
|
323
|
+
expect { element.wait_while(timeout: 0) { false } }.to_not raise_exception
|
324
|
+
end
|
346
325
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
326
|
+
it "accepts just a message parameter" do
|
327
|
+
element = browser.div(id: 'foo')
|
328
|
+
expect { element.wait_while(message: 'no') { false } }.to_not raise_exception
|
329
|
+
end
|
351
330
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
end
|
331
|
+
it "accepts just an interval parameter" do
|
332
|
+
element = browser.div(id: 'foo')
|
333
|
+
expect { element.wait_while(interval: 0.1) { false } }.to_not raise_exception
|
356
334
|
end
|
357
335
|
end
|
336
|
+
end
|
358
337
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
338
|
+
describe Watir do
|
339
|
+
describe "#default_timeout" do
|
340
|
+
before do
|
341
|
+
Watir.default_timeout = 1
|
363
342
|
|
364
|
-
|
365
|
-
|
343
|
+
browser.goto WatirSpec.url_for("wait.html")
|
344
|
+
end
|
366
345
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
346
|
+
after do
|
347
|
+
# Reset the default timeout
|
348
|
+
Watir.default_timeout = 30
|
349
|
+
end
|
371
350
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
351
|
+
context "when no timeout is specified" do
|
352
|
+
it "is used by Wait#until" do
|
353
|
+
expect {
|
354
|
+
Watir::Wait.until { false }
|
355
|
+
}.to raise_error(Watir::Wait::TimeoutError)
|
356
|
+
end
|
378
357
|
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
358
|
+
it "is used by Wait#while" do
|
359
|
+
expect {
|
360
|
+
Watir::Wait.while { true }
|
361
|
+
}.to raise_error(Watir::Wait::TimeoutError)
|
362
|
+
end
|
384
363
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
364
|
+
it "is used by Element#wait_until_present" do
|
365
|
+
expect {
|
366
|
+
browser.div(id: 'bar').wait_until_present
|
367
|
+
}.to raise_error(Watir::Wait::TimeoutError)
|
368
|
+
end
|
390
369
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
end
|
370
|
+
it "is used by Element#wait_while_present" do
|
371
|
+
expect {
|
372
|
+
browser.div(id: 'foo').wait_while_present
|
373
|
+
}.to raise_error(Watir::Wait::TimeoutError)
|
396
374
|
end
|
397
375
|
end
|
398
376
|
end
|