watir 7.0.0.beta1 → 7.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +7 -3
- data/.rubocop.yml +2 -7
- data/CHANGES.md +16 -0
- data/lib/watir/browser.rb +18 -4
- data/lib/watir/capabilities.rb +1 -1
- data/lib/watir/elements/element.rb +32 -3
- data/lib/watir/elements/font.rb +1 -0
- data/lib/watir/elements/iframe.rb +0 -1
- data/lib/watir/elements/radio.rb +2 -2
- data/lib/watir/elements/select.rb +63 -40
- data/lib/watir/has_window.rb +2 -0
- data/lib/watir/locators.rb +4 -0
- data/lib/watir/locators/element/matcher.rb +1 -1
- data/lib/watir/locators/element/selector_builder.rb +0 -3
- data/lib/watir/locators/option/matcher.rb +24 -0
- data/lib/watir/locators/option/selector_builder.rb +8 -0
- data/lib/watir/locators/option/selector_builder/xpath.rb +37 -0
- data/lib/watir/logger.rb +3 -74
- data/lib/watir/radio_set.rb +1 -0
- data/lib/watir/screenshot.rb +2 -8
- data/lib/watir/user_editable.rb +10 -3
- data/lib/watir/version.rb +1 -1
- data/lib/watir/window.rb +15 -4
- data/lib/watir/window_collection.rb +9 -0
- data/lib/watirspec.rb +4 -2
- data/lib/watirspec/guards.rb +1 -1
- data/lib/watirspec/server.rb +1 -1
- data/spec/spec_helper.rb +0 -10
- data/spec/unit/capabilities_spec.rb +1 -1
- data/spec/unit/match_elements/element_spec.rb +11 -0
- data/spec/watirspec/after_hooks_spec.rb +22 -45
- data/spec/watirspec/browser_spec.rb +185 -206
- data/spec/watirspec/cookies_spec.rb +47 -52
- data/spec/watirspec/drag_and_drop_spec.rb +5 -7
- data/spec/watirspec/elements/area_spec.rb +1 -5
- data/spec/watirspec/elements/button_spec.rb +4 -8
- data/spec/watirspec/elements/checkbox_spec.rb +2 -4
- data/spec/watirspec/elements/date_field_spec.rb +13 -16
- data/spec/watirspec/elements/date_time_field_spec.rb +14 -13
- data/spec/watirspec/elements/dd_spec.rb +3 -4
- data/spec/watirspec/elements/del_spec.rb +10 -12
- data/spec/watirspec/elements/div_spec.rb +41 -50
- data/spec/watirspec/elements/dl_spec.rb +4 -12
- data/spec/watirspec/elements/element_spec.rb +155 -89
- data/spec/watirspec/elements/elements_spec.rb +8 -9
- data/spec/watirspec/elements/filefield_spec.rb +5 -7
- data/spec/watirspec/elements/form_spec.rb +1 -1
- data/spec/watirspec/elements/forms_spec.rb +3 -5
- data/spec/watirspec/elements/frame_spec.rb +17 -22
- data/spec/watirspec/elements/iframe_spec.rb +21 -27
- data/spec/watirspec/elements/ins_spec.rb +10 -12
- data/spec/watirspec/elements/link_spec.rb +24 -26
- data/spec/watirspec/elements/links_spec.rb +8 -9
- data/spec/watirspec/elements/radio_spec.rb +11 -14
- data/spec/watirspec/elements/select_list_spec.rb +248 -117
- data/spec/watirspec/elements/span_spec.rb +10 -12
- data/spec/watirspec/elements/table_nesting_spec.rb +31 -34
- data/spec/watirspec/elements/table_spec.rb +11 -13
- data/spec/watirspec/elements/tbody_spec.rb +10 -12
- data/spec/watirspec/elements/td_spec.rb +4 -6
- data/spec/watirspec/elements/text_field_spec.rb +10 -12
- data/spec/watirspec/elements/tr_spec.rb +5 -7
- data/spec/watirspec/user_editable_spec.rb +26 -28
- data/spec/watirspec/wait_spec.rb +255 -258
- data/spec/watirspec/window_switching_spec.rb +199 -200
- data/spec/watirspec_helper.rb +34 -31
- metadata +5 -6
- data/spec/implementation_spec.rb +0 -24
- data/spec/unit/logger_spec.rb +0 -81
@@ -100,18 +100,16 @@ describe 'Span' do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
# Other
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
expect { browser.span(title: 'no_such_title').click }.to raise_unknown_object_exception
|
114
|
-
end
|
103
|
+
describe '#click', except: {headless: true} do
|
104
|
+
it 'fires events' do
|
105
|
+
expect(browser.span(class: 'footer').text).to_not include('Javascript')
|
106
|
+
browser.span(class: 'footer').click
|
107
|
+
expect(browser.span(class: 'footer').text).to include('Javascript')
|
108
|
+
end
|
109
|
+
|
110
|
+
it "raises UnknownObjectException if the span doesn't exist" do
|
111
|
+
expect { browser.span(id: 'no_such_id').click }.to raise_unknown_object_exception
|
112
|
+
expect { browser.span(title: 'no_such_title').click }.to raise_unknown_object_exception
|
115
113
|
end
|
116
114
|
end
|
117
115
|
end
|
@@ -5,48 +5,45 @@ describe 'Table' do
|
|
5
5
|
browser.goto(WatirSpec.url_for('nested_tables.html'))
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
msg = "expected #{expected} rows, got #{actual} for table id=#{table.id}, browser reported: #{browser_count}"
|
20
|
-
expect(actual).to eql(expected), msg
|
21
|
-
end
|
8
|
+
it 'returns the correct number of rows under a table element' do
|
9
|
+
tables = browser.div(id: 'table-rows-test').tables(id: /^tbl/)
|
10
|
+
expect(tables.length).to be > 0
|
11
|
+
|
12
|
+
tables.each do |table|
|
13
|
+
expected = Integer(table.data_row_count)
|
14
|
+
actual = table.rows.length
|
15
|
+
browser_count = Integer(table.data_browser_count)
|
16
|
+
|
17
|
+
msg = "expected #{expected} rows, got #{actual} for table id=#{table.id}, browser reported: #{browser_count}"
|
18
|
+
expect(actual).to eql(expected), msg
|
22
19
|
end
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
it 'returns the correct number of cells under a row' do
|
23
|
+
rows = browser.div(id: 'row-cells-test').trs(id: /^row/)
|
24
|
+
expect(rows.length).to be > 0
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
rows.each do |row|
|
27
|
+
expected = Integer(row.data_cell_count)
|
28
|
+
actual = row.cells.length
|
29
|
+
browser_count = Integer(row.data_browser_count)
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
31
|
+
msg = "expected #{expected} cells, got #{actual} for row id=#{row.id}, browser reported: #{browser_count}"
|
32
|
+
expect(actual).to eql(expected), msg
|
36
33
|
end
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
it 'returns the correct number of rows under a table section' do
|
37
|
+
tbodies = browser.table(id: 'tbody-rows-test').tbodys(id: /^body/)
|
38
|
+
expect(tbodies.length).to be > 0
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
tbodies.each do |tbody|
|
41
|
+
expected = Integer(tbody.data_rows_count)
|
42
|
+
actual = tbody.rows.count
|
43
|
+
browser_count = Integer(tbody.data_browser_count)
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
45
|
+
msg = "expected #{expected} rows, got #{actual} for tbody id=#{tbody.id}, browser reported: #{browser_count}"
|
46
|
+
expect(actual).to eql(expected), msg
|
50
47
|
end
|
51
48
|
end
|
52
49
|
end
|
@@ -36,19 +36,17 @@ describe 'Table' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Other
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
]
|
51
|
-
end
|
39
|
+
describe '#strings', except: {browser: :safari, reason: 'Safari does not strip text'} do
|
40
|
+
it 'returns a two-dimensional array representation of the table' do
|
41
|
+
expect(browser.table(id: 'inner').strings).to eq [
|
42
|
+
['Table 2, Row 1, Cell 1',
|
43
|
+
'Table 2, Row 1, Cell 2']
|
44
|
+
]
|
45
|
+
expect(browser.table(id: 'outer').strings).to eq [
|
46
|
+
['Table 1, Row 1, Cell 1', 'Table 1, Row 1, Cell 2'],
|
47
|
+
['Table 1, Row 2, Cell 1', "Table 1, Row 2, Cell 2\nTable 2, Row 1, Cell 1 Table 2, Row 1, Cell 2"],
|
48
|
+
['Table 1, Row 3, Cell 1', 'Table 1, Row 3, Cell 2']
|
49
|
+
]
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
@@ -44,19 +44,17 @@ describe 'TableBody' do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
47
|
+
describe '#[]', except: {browser: :safari, reason: 'Safari does not strip text'} do
|
48
|
+
it 'returns the row at the given index (page context)' do
|
49
|
+
expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008'
|
50
|
+
expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
51
|
+
expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
54
|
+
it 'returns the row at the given index (table context)' do
|
55
|
+
expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008'
|
56
|
+
expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
57
|
+
expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -42,12 +42,10 @@ describe 'TableCell' do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Attribute methods
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
expect(browser.td(id: 't2_r1_c1').text).to eq 'Table 2, Row 1, Cell 1'
|
50
|
-
end
|
45
|
+
describe '#text', except: {browser: :safari, reason: 'Safari does not strip text'} do
|
46
|
+
it 'returns the text inside the table cell' do
|
47
|
+
expect(browser.td(id: 't1_r2_c1').text).to eq 'Table 1, Row 2, Cell 1'
|
48
|
+
expect(browser.td(id: 't2_r1_c1').text).to eq 'Table 2, Row 1, Cell 1'
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
@@ -26,18 +26,16 @@ describe 'TextField' do
|
|
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
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
expect(browser.text_field(visible_label: /With hidden text/)).not_to exist
|
40
|
-
end
|
29
|
+
expect(browser.text_field(label: /With hidden text/)).to exist
|
30
|
+
expect(browser.text_field(label: /With text/)).not_to exist
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns true in spite of hidden text',
|
34
|
+
except: {browser: :safari, reason: 'Safari is not filtering out hidden text'} do
|
35
|
+
expect(browser.text_field(visible_label: 'With hidden text')).not_to exist
|
36
|
+
expect(browser.text_field(visible_label: 'With text')).to exist
|
37
|
+
expect(browser.text_field(visible_label: /With text/)).to exist
|
38
|
+
expect(browser.text_field(visible_label: /With hidden text/)).not_to exist
|
41
39
|
end
|
42
40
|
|
43
41
|
it 'locates value of text_field using text locators' do
|
@@ -29,14 +29,12 @@ describe 'TableRow' do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
let(:table) { browser.table(id: 'outer') }
|
32
|
+
describe '#[]', except: {browser: :safari, reason: 'Safari does not strip text'} do
|
33
|
+
let(:table) { browser.table(id: 'outer') }
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
35
|
+
it 'returns the nth cell of the row' do
|
36
|
+
expect(table[0][0].text).to eq 'Table 1, Row 1, Cell 1'
|
37
|
+
expect(table[2][0].text).to eq 'Table 1, Row 3, Cell 1'
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
@@ -5,34 +5,32 @@ describe Watir::UserEditable do
|
|
5
5
|
browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
expect { browser.text_field(name: 'no_such_name').append('Append This') }.to raise_unknown_object_exception
|
35
|
-
end
|
8
|
+
describe '#append' do
|
9
|
+
it 'appends the text to the text field', except: {browser: :safari, reason: 'incorrectly clears first'} do
|
10
|
+
browser.text_field(name: 'new_user_occupation').append(' Append This')
|
11
|
+
expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer Append This'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'appends multi-byte characters', except: {browser: :safari, reason: 'incorrectly clears first'} do
|
15
|
+
browser.text_field(name: 'new_user_occupation').append(' ijij')
|
16
|
+
expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer ijij'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raises NotImplementedError if the object is content editable element' do
|
20
|
+
msg = '#append method is not supported with contenteditable element'
|
21
|
+
expect { browser.div(id: 'contenteditable').append('bar') }.to raise_exception(NotImplementedError, msg)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raises ObjectReadOnlyException if the object is read only' do
|
25
|
+
expect { browser.text_field(id: 'new_user_code').append('Append This') }.to raise_object_read_only_exception
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'raises ObjectDisabledException if the object is disabled' do
|
29
|
+
expect { browser.text_field(name: 'new_user_species').append('Append This') }.to raise_object_disabled_exception
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises UnknownObjectException if the object doesn't exist" do
|
33
|
+
expect { browser.text_field(name: 'no_such_name').append('Append This') }.to raise_unknown_object_exception
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
data/spec/watirspec/wait_spec.rb
CHANGED
@@ -1,352 +1,349 @@
|
|
1
1
|
require 'watirspec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
describe Watir do
|
4
|
+
before do
|
5
|
+
browser.goto WatirSpec.url_for('wait.html')
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
describe '#default_timeout' do
|
9
|
+
context 'when no timeout is specified' do
|
10
|
+
it 'is used by Wait#until' do
|
11
|
+
expect { Watir::Wait.until { false } }.to wait_and_raise_timeout_exception(timeout: 1)
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
it 'is used by Wait#while' do
|
15
|
+
expect { Watir::Wait.while { true } }.to wait_and_raise_timeout_exception(timeout: 1)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
18
|
+
it 'ensures all checks happen once even if time has expired' do
|
19
|
+
Watir.default_timeout = -1
|
20
|
+
expect { browser.link.click }.to_not raise_exception
|
21
|
+
ensure
|
22
|
+
Watir.default_timeout = 5
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Watir::Element do
|
29
|
+
before do
|
30
|
+
browser.goto WatirSpec.url_for('wait.html')
|
31
|
+
end
|
28
32
|
|
29
|
-
describe
|
30
|
-
|
31
|
-
browser.
|
33
|
+
describe '#wait_until' do
|
34
|
+
it 'returns element for additional actions' do
|
35
|
+
element = browser.div(id: 'foo')
|
36
|
+
expect(element.wait_until(&:exist?)).to eq element
|
32
37
|
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
it 'accepts self in block' do
|
40
|
+
element = browser.div(id: 'bar')
|
41
|
+
browser.a(id: 'show_bar').click
|
42
|
+
expect { element.wait_until { |el| el.text == 'bar' } }.to_not raise_exception
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'accepts any values in block' do
|
46
|
+
element = browser.div(id: 'bar')
|
47
|
+
expect { element.wait_until { true } }.to_not raise_exception
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'accepts just a timeout parameter' do
|
51
|
+
element = browser.div(id: 'bar')
|
52
|
+
expect { element.wait_until(timeout: 0) { true } }.to_not raise_exception
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'accepts just a message parameter' do
|
56
|
+
element = browser.div(id: 'bar')
|
57
|
+
expect { element.wait_until(message: 'no') { true } }.to_not raise_exception
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'accepts just an interval parameter' do
|
61
|
+
element = browser.div(id: 'bar')
|
62
|
+
expect { element.wait_until(interval: 0.1) { true } }.to_not raise_exception
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'accepts keywords instead of block' do
|
66
|
+
before { browser.refresh }
|
39
67
|
|
40
|
-
it 'accepts
|
68
|
+
it 'accepts text keyword' do
|
41
69
|
element = browser.div(id: 'bar')
|
42
70
|
browser.a(id: 'show_bar').click
|
43
|
-
expect { element.wait_until
|
71
|
+
expect { element.wait_until(text: 'bar') }.to_not raise_exception
|
44
72
|
end
|
45
73
|
|
46
|
-
it 'accepts
|
74
|
+
it 'accepts regular expression value' do
|
47
75
|
element = browser.div(id: 'bar')
|
48
|
-
|
76
|
+
browser.a(id: 'show_bar').click
|
77
|
+
expect { element.wait_until(style: /block/) }.to_not raise_exception
|
49
78
|
end
|
50
79
|
|
51
|
-
it 'accepts
|
80
|
+
it 'accepts multiple keywords' do
|
52
81
|
element = browser.div(id: 'bar')
|
53
|
-
|
82
|
+
browser.a(id: 'show_bar').click
|
83
|
+
expect { element.wait_until(text: 'bar', style: /block/) }.to_not raise_exception
|
54
84
|
end
|
55
85
|
|
56
|
-
it 'accepts
|
86
|
+
it 'accepts custom keyword' do
|
57
87
|
element = browser.div(id: 'bar')
|
58
|
-
|
88
|
+
browser.a(id: 'show_bar').click
|
89
|
+
expect { element.wait_until(custom: 'bar') }.to_not raise_exception
|
59
90
|
end
|
60
91
|
|
61
|
-
it '
|
92
|
+
it 'times out when single keyword not met' do
|
62
93
|
element = browser.div(id: 'bar')
|
63
|
-
expect { element.wait_until(
|
94
|
+
expect { element.wait_until(id: 'foo') }.to raise_timeout_exception
|
64
95
|
end
|
65
96
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
element = browser.div(id: 'bar')
|
71
|
-
browser.a(id: 'show_bar').click
|
72
|
-
expect { element.wait_until(text: 'bar') }.to_not raise_exception
|
73
|
-
end
|
97
|
+
it 'times out when one of multiple keywords not met' do
|
98
|
+
element = browser.div(id: 'bar')
|
99
|
+
expect { element.wait_until(id: 'bar', text: 'foo') }.to raise_timeout_exception
|
100
|
+
end
|
74
101
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
102
|
+
it 'times out when a custom keywords not met' do
|
103
|
+
element = browser.div(id: 'bar')
|
104
|
+
expect { element.wait_until(custom: 'foo') }.to raise_timeout_exception
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
80
108
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
109
|
+
describe '#wait_while' do
|
110
|
+
it 'returns element for additional actions' do
|
111
|
+
element = browser.div(id: 'foo')
|
112
|
+
browser.a(id: 'hide_foo').click
|
113
|
+
expect(element.wait_while(&:present?)).to eq element
|
114
|
+
end
|
86
115
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
116
|
+
it 'accepts any values in block' do
|
117
|
+
element = browser.div(id: 'foo')
|
118
|
+
expect { element.wait_while { false } }.to_not raise_exception
|
119
|
+
end
|
92
120
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
121
|
+
it 'accepts just a timeout parameter' do
|
122
|
+
element = browser.div(id: 'foo')
|
123
|
+
expect { element.wait_while(timeout: 0) { false } }.to_not raise_exception
|
124
|
+
end
|
97
125
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
126
|
+
it 'accepts just a message parameter' do
|
127
|
+
element = browser.div(id: 'foo')
|
128
|
+
expect { element.wait_while(message: 'no') { false } }.to_not raise_exception
|
129
|
+
end
|
102
130
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
131
|
+
it 'accepts just an interval parameter' do
|
132
|
+
element = browser.div(id: 'foo')
|
133
|
+
expect { element.wait_while(interval: 0.1) { false } }.to_not raise_exception
|
108
134
|
end
|
109
135
|
|
110
|
-
|
111
|
-
it '
|
136
|
+
context 'accepts keywords instead of block' do
|
137
|
+
it 'accepts text keyword', except: {browser: :safari,
|
138
|
+
reason: 'Safari does not recognize date type'} do
|
112
139
|
element = browser.div(id: 'foo')
|
113
140
|
browser.a(id: 'hide_foo').click
|
114
|
-
expect
|
141
|
+
expect { element.wait_while(text: 'foo') }.to_not raise_exception
|
115
142
|
end
|
116
143
|
|
117
|
-
it 'accepts
|
144
|
+
it 'accepts regular expression value' do
|
118
145
|
element = browser.div(id: 'foo')
|
119
|
-
|
146
|
+
browser.a(id: 'hide_foo').click
|
147
|
+
expect { element.wait_while(style: /block/) }.to_not raise_exception
|
120
148
|
end
|
121
149
|
|
122
|
-
it 'accepts
|
150
|
+
it 'accepts multiple keywords' do
|
123
151
|
element = browser.div(id: 'foo')
|
124
|
-
|
152
|
+
browser.a(id: 'hide_foo').click
|
153
|
+
expect { element.wait_while(text: 'foo', style: /block/) }.to_not raise_exception
|
125
154
|
end
|
126
155
|
|
127
|
-
it 'accepts
|
156
|
+
it 'accepts custom attributes' do
|
128
157
|
element = browser.div(id: 'foo')
|
129
|
-
|
158
|
+
browser.a(id: 'hide_foo').click
|
159
|
+
expect { element.wait_while(custom: '') }.to_not raise_exception
|
130
160
|
end
|
131
161
|
|
132
|
-
it 'accepts
|
162
|
+
it 'accepts keywords and block' do
|
133
163
|
element = browser.div(id: 'foo')
|
134
|
-
|
164
|
+
browser.a(id: 'hide_foo').click
|
165
|
+
expect { element.wait_while(custom: '', &:present?) }.to_not raise_exception
|
135
166
|
end
|
136
167
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
browser.a(id: 'hide_foo').click
|
142
|
-
expect { element.wait_while(text: 'foo') }.to_not raise_exception
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'accepts regular expression value' do
|
147
|
-
element = browser.div(id: 'foo')
|
148
|
-
browser.a(id: 'hide_foo').click
|
149
|
-
expect { element.wait_while(style: /block/) }.to_not raise_exception
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'accepts multiple keywords' do
|
153
|
-
element = browser.div(id: 'foo')
|
154
|
-
browser.a(id: 'hide_foo').click
|
155
|
-
expect { element.wait_while(text: 'foo', style: /block/) }.to_not raise_exception
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'accepts custom attributes' do
|
159
|
-
element = browser.div(id: 'foo')
|
160
|
-
browser.a(id: 'hide_foo').click
|
161
|
-
expect { element.wait_while(custom: '') }.to_not raise_exception
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'accepts keywords and block' do
|
165
|
-
element = browser.div(id: 'foo')
|
166
|
-
browser.a(id: 'hide_foo').click
|
167
|
-
expect { element.wait_while(custom: '', &:present?) }.to_not raise_exception
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'browser accepts keywords' do
|
171
|
-
expect { browser.wait_until(title: 'wait test') }.to_not raise_exception
|
172
|
-
expect { browser.wait_until(title: 'wrong') }.to raise_timeout_exception
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'alert accepts keywords' do
|
176
|
-
browser.goto WatirSpec.url_for('alerts.html')
|
168
|
+
it 'browser accepts keywords' do
|
169
|
+
expect { browser.wait_until(title: 'wait test') }.to_not raise_exception
|
170
|
+
expect { browser.wait_until(title: 'wrong') }.to raise_timeout_exception
|
171
|
+
end
|
177
172
|
|
178
|
-
|
179
|
-
|
180
|
-
expect { browser.alert.wait_until(text: 'ok') }.to_not raise_exception
|
181
|
-
expect { browser.alert.wait_until(text: 'not ok') }.to raise_timeout_exception
|
182
|
-
ensure
|
183
|
-
browser.alert.ok
|
184
|
-
end
|
185
|
-
end
|
173
|
+
it 'alert accepts keywords' do
|
174
|
+
browser.goto WatirSpec.url_for('alerts.html')
|
186
175
|
|
187
|
-
|
188
|
-
|
189
|
-
expect { browser.
|
176
|
+
begin
|
177
|
+
browser.button(id: 'alert').click
|
178
|
+
expect { browser.alert.wait_until(text: 'ok') }.to_not raise_exception
|
179
|
+
expect { browser.alert.wait_until(text: 'not ok') }.to raise_timeout_exception
|
180
|
+
ensure
|
181
|
+
browser.alert.ok
|
190
182
|
end
|
183
|
+
end
|
191
184
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
185
|
+
it 'window accepts keywords' do
|
186
|
+
expect { browser.window.wait_until(title: 'wait test') }.to_not raise_exception
|
187
|
+
expect { browser.window.wait_until(title: 'wrong') }.to raise_timeout_exception
|
188
|
+
end
|
196
189
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
end
|
190
|
+
it 'times out when single keyword not met' do
|
191
|
+
element = browser.div(id: 'foo')
|
192
|
+
expect { element.wait_while(id: 'foo') }.to raise_timeout_exception
|
193
|
+
end
|
202
194
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
195
|
+
it 'times out when one of multiple keywords not met' do
|
196
|
+
element = browser.div(id: 'foo')
|
197
|
+
browser.a(id: 'hide_foo').click
|
198
|
+
expect { element.wait_while(id: 'foo', style: /block/) }.to raise_timeout_exception
|
207
199
|
end
|
208
|
-
end
|
209
200
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
expect { element.click }.to wait_and_raise_unknown_object_exception
|
201
|
+
it 'times out when one of custom keywords not met' do
|
202
|
+
element = browser.div(id: 'foo')
|
203
|
+
expect { element.wait_while(custom: '') }.to raise_timeout_exception
|
214
204
|
end
|
215
205
|
end
|
206
|
+
end
|
216
207
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
208
|
+
context 'when acting on an element that is never present' do
|
209
|
+
it 'raises exception after timing out' do
|
210
|
+
element = browser.link(id: 'not_there')
|
211
|
+
expect { element.click }.to wait_and_raise_unknown_object_exception
|
221
212
|
end
|
213
|
+
end
|
222
214
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
}.to execute_when_satisfied(min: 1)
|
229
|
-
expect(browser.div(id: 'bar').text).to eq 'changed'
|
230
|
-
end
|
215
|
+
context 'when acting on an element that is already present' do
|
216
|
+
it 'does not wait' do
|
217
|
+
expect { browser.link.click }.to execute_when_satisfied(max: 1)
|
218
|
+
end
|
219
|
+
end
|
231
220
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
221
|
+
context 'when acting on an element that eventually becomes present' do
|
222
|
+
it 'waits until element is present and then takes action' do
|
223
|
+
expect {
|
224
|
+
browser.a(id: 'show_bar').click
|
225
|
+
browser.div(id: 'bar').click
|
226
|
+
}.to execute_when_satisfied(min: 1)
|
227
|
+
expect(browser.div(id: 'bar').text).to eq 'changed'
|
238
228
|
end
|
239
229
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
230
|
+
it 'waits until text field present and then takes action' do
|
231
|
+
expect {
|
232
|
+
browser.a(id: 'show_textfield').click
|
233
|
+
browser.text_field(id: 'textfield').set 'Foo'
|
234
|
+
}.to execute_when_satisfied(min: 1)
|
235
|
+
end
|
236
|
+
end
|
244
237
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
browser.text_field(id: 'writable').set 'foo'
|
249
|
-
}.to execute_when_satisfied(min: 1)
|
250
|
-
end
|
238
|
+
context 'when acting on a read only text field' do
|
239
|
+
it 'waits and raises read only exception if never becomes writable' do
|
240
|
+
expect { browser.text_field(id: 'writable').set 'foo' }.to wait_and_raise_object_read_only_exception
|
251
241
|
end
|
252
242
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
243
|
+
it 'waits until writable' do
|
244
|
+
expect {
|
245
|
+
browser.a(id: 'make-writable').click
|
246
|
+
browser.text_field(id: 'writable').set 'foo'
|
247
|
+
}.to execute_when_satisfied(min: 1)
|
248
|
+
end
|
249
|
+
end
|
257
250
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
browser.button(id: 'btn').click
|
262
|
-
}.to execute_when_satisfied(min: 1)
|
263
|
-
end
|
251
|
+
context 'when acting on a disabled button' do
|
252
|
+
it 'waits and raises exception if it never becomes enabled' do
|
253
|
+
expect { browser.button(id: 'btn').click }.to wait_and_raise_object_disabled_exception
|
264
254
|
end
|
265
255
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
256
|
+
it 'waits until enabled' do
|
257
|
+
expect {
|
258
|
+
browser.a(id: 'enable_btn').click
|
259
|
+
browser.button(id: 'btn').click
|
260
|
+
}.to execute_when_satisfied(min: 1)
|
261
|
+
end
|
262
|
+
end
|
271
263
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
264
|
+
context 'when acting on an element with a parent' do
|
265
|
+
it 'raises exception after timing out if parent never present' do
|
266
|
+
element = browser.link(id: 'not_there')
|
267
|
+
expect { element.element.click }.to wait_and_raise_unknown_object_exception
|
268
|
+
end
|
276
269
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
end
|
270
|
+
it 'raises exception after timing out when element from a collection whose parent is never present' do
|
271
|
+
element = browser.link(id: 'not_there')
|
272
|
+
expect { element.elements[2].click }.to wait_and_raise_unknown_object_exception
|
281
273
|
end
|
282
|
-
end
|
283
274
|
|
284
|
-
|
285
|
-
|
286
|
-
|
275
|
+
it 'does not wait for parent element to be present when querying child element' do
|
276
|
+
el = browser.element(id: 'not_there').element(id: 'doesnt_matter')
|
277
|
+
expect { el.present? }.to execute_when_satisfied(max: 1)
|
287
278
|
end
|
279
|
+
end
|
280
|
+
end
|
288
281
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
end
|
282
|
+
describe Watir::ElementCollection do
|
283
|
+
before do
|
284
|
+
browser.goto WatirSpec.url_for('wait.html')
|
285
|
+
end
|
294
286
|
|
295
|
-
|
296
|
-
|
297
|
-
|
287
|
+
describe '#wait_until' do
|
288
|
+
it 'returns collection' do
|
289
|
+
elements = browser.divs
|
290
|
+
expect(elements.wait_until(&:exist?)).to eq elements
|
291
|
+
end
|
298
292
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
browser.divs(id: 'foobar').wait_until(&:exists?)
|
303
|
-
}.to execute_when_satisfied(min: 1)
|
304
|
-
end
|
293
|
+
it 'times out when waiting for non-empty collection' do
|
294
|
+
expect { browser.divs.wait_until(&:empty?) }.to raise_timeout_exception
|
295
|
+
end
|
305
296
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
297
|
+
it 'provides matching collection when exists' do
|
298
|
+
expect {
|
299
|
+
browser.a(id: 'add_foobar').click
|
300
|
+
browser.divs(id: 'foobar').wait_until(&:exists?)
|
301
|
+
}.to execute_when_satisfied(min: 1)
|
302
|
+
end
|
312
303
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
end
|
304
|
+
it 'accepts self in block' do
|
305
|
+
expect {
|
306
|
+
browser.a(id: 'add_foobar').click
|
307
|
+
browser.divs.wait_until { |els| els.size == 7 }
|
308
|
+
}.to execute_when_satisfied(min: 1)
|
319
309
|
end
|
320
310
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
311
|
+
it 'accepts attributes to evaluate' do
|
312
|
+
expect {
|
313
|
+
browser.a(id: 'add_foobar').click
|
314
|
+
browser.divs.wait_until(size: 7)
|
315
|
+
}.to execute_when_satisfied(min: 1)
|
316
|
+
end
|
317
|
+
end
|
326
318
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
319
|
+
describe '#wait_while' do
|
320
|
+
it 'returns collection' do
|
321
|
+
elements = browser.divs
|
322
|
+
expect(elements.wait_while(&:empty?)).to eq elements
|
323
|
+
end
|
331
324
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
}.to execute_when_satisfied(min: 1)
|
337
|
-
end
|
325
|
+
it 'times out when waiting for non-empty collection' do
|
326
|
+
elements = browser.divs
|
327
|
+
expect { elements.wait_while(&:exists?) }.to raise_timeout_exception
|
328
|
+
end
|
338
329
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
end
|
330
|
+
it 'provides matching collection when exists' do
|
331
|
+
expect {
|
332
|
+
browser.a(id: 'remove_foo').click
|
333
|
+
browser.divs(id: 'foo').wait_while(&:exists?)
|
334
|
+
}.to execute_when_satisfied(min: 1)
|
345
335
|
end
|
346
336
|
|
347
|
-
it '
|
348
|
-
|
349
|
-
|
337
|
+
it 'accepts self in block' do
|
338
|
+
expect {
|
339
|
+
browser.a(id: 'add_foobar').click
|
340
|
+
browser.divs.wait_while { |els| els.size == 6 }
|
341
|
+
}.to execute_when_satisfied(min: 1)
|
350
342
|
end
|
351
343
|
end
|
344
|
+
|
345
|
+
it 'waits for parent element to be present before locating' do
|
346
|
+
els = browser.element(id: /not|there/).elements(id: 'doesnt_matter')
|
347
|
+
expect { els.to_a }.to wait_and_raise_unknown_object_exception
|
348
|
+
end
|
352
349
|
end
|