watir 7.2.0 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/chrome.yml +1 -1
- data/.github/workflows/edge.yml +1 -1
- data/.github/workflows/firefox.yml +1 -1
- data/.github/workflows/ie.yml +1 -1
- data/.github/workflows/safari.yml +1 -1
- data/.github/workflows/unit.yml +1 -1
- data/.rubocop.yml +25 -12
- data/.rubocop_todo.yml +8 -1
- data/CHANGES.md +6 -1
- data/LICENSE +2 -2
- data/lib/watir/capabilities.rb +1 -1
- data/lib/watir/locators/anchor/selector_builder.rb +3 -0
- data/lib/watir/locators/element/matcher.rb +2 -1
- data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
- data/lib/watir/locators/text_field/matcher.rb +0 -4
- data/lib/watir/version.rb +1 -1
- data/spec/locator_spec_helper.rb +0 -8
- data/spec/unit/capabilities_spec.rb +553 -561
- data/spec/unit/element_locator_spec.rb +89 -78
- data/spec/unit/match_elements/button_spec.rb +69 -62
- data/spec/unit/match_elements/element_spec.rb +303 -309
- data/spec/unit/match_elements/text_field_spec.rb +76 -73
- data/spec/unit/selector_builder/anchor_spec.rb +39 -33
- data/spec/unit/selector_builder/button_spec.rb +209 -202
- data/spec/unit/selector_builder/cell_spec.rb +48 -42
- data/spec/unit/selector_builder/element_spec.rb +634 -627
- data/spec/unit/selector_builder/row_spec.rb +119 -113
- data/spec/unit/selector_builder/text_field_spec.rb +195 -188
- data/spec/unit/selector_builder/textarea_spec.rb +22 -14
- data/spec/unit/wait_spec.rb +85 -81
- data/spec/watirspec/adjacent_spec.rb +249 -247
- data/spec/watirspec/after_hooks_spec.rb +161 -159
- data/spec/watirspec/alert_spec.rb +61 -58
- data/spec/watirspec/browser_spec.rb +409 -409
- data/spec/watirspec/capabilities_spec.rb +89 -99
- data/spec/watirspec/cookies_spec.rb +120 -118
- data/spec/watirspec/drag_and_drop_spec.rb +26 -24
- data/spec/watirspec/element_hidden_spec.rb +66 -60
- data/spec/watirspec/elements/area_spec.rb +49 -47
- data/spec/watirspec/elements/areas_spec.rb +27 -25
- data/spec/watirspec/elements/button_spec.rb +253 -251
- data/spec/watirspec/elements/buttons_spec.rb +36 -34
- data/spec/watirspec/elements/checkbox_spec.rb +48 -36
- data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
- data/spec/watirspec/elements/collections_spec.rb +126 -119
- data/spec/watirspec/elements/date_field_spec.rb +185 -183
- data/spec/watirspec/elements/date_fields_spec.rb +29 -27
- data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
- data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
- data/spec/watirspec/elements/dd_spec.rb +87 -85
- data/spec/watirspec/elements/dds_spec.rb +27 -25
- data/spec/watirspec/elements/del_spec.rb +106 -104
- data/spec/watirspec/elements/dels_spec.rb +26 -24
- data/spec/watirspec/elements/div_spec.rb +225 -221
- data/spec/watirspec/elements/divs_spec.rb +37 -35
- data/spec/watirspec/elements/dl_spec.rb +110 -108
- data/spec/watirspec/elements/dls_spec.rb +28 -26
- data/spec/watirspec/elements/dt_spec.rb +86 -84
- data/spec/watirspec/elements/dts_spec.rb +27 -25
- data/spec/watirspec/elements/element_spec.rb +794 -775
- data/spec/watirspec/elements/elements_spec.rb +40 -38
- data/spec/watirspec/elements/em_spec.rb +62 -60
- data/spec/watirspec/elements/ems_spec.rb +28 -26
- data/spec/watirspec/elements/filefield_spec.rb +116 -114
- data/spec/watirspec/elements/filefields_spec.rb +28 -26
- data/spec/watirspec/elements/font_spec.rb +20 -18
- data/spec/watirspec/elements/form_spec.rb +51 -49
- data/spec/watirspec/elements/forms_spec.rb +29 -27
- data/spec/watirspec/elements/frame_spec.rb +89 -87
- data/spec/watirspec/elements/frames_spec.rb +27 -25
- data/spec/watirspec/elements/hidden_spec.rb +81 -79
- data/spec/watirspec/elements/hiddens_spec.rb +28 -26
- data/spec/watirspec/elements/hn_spec.rb +59 -57
- data/spec/watirspec/elements/hns_spec.rb +26 -24
- data/spec/watirspec/elements/iframe_spec.rb +195 -191
- data/spec/watirspec/elements/iframes_spec.rb +31 -29
- data/spec/watirspec/elements/image_spec.rb +148 -146
- data/spec/watirspec/elements/images_spec.rb +26 -24
- data/spec/watirspec/elements/input_spec.rb +9 -7
- data/spec/watirspec/elements/ins_spec.rb +106 -104
- data/spec/watirspec/elements/inses_spec.rb +26 -24
- data/spec/watirspec/elements/label_spec.rb +56 -54
- data/spec/watirspec/elements/labels_spec.rb +26 -24
- data/spec/watirspec/elements/li_spec.rb +76 -74
- data/spec/watirspec/elements/link_spec.rb +173 -177
- data/spec/watirspec/elements/links_spec.rb +45 -43
- data/spec/watirspec/elements/lis_spec.rb +27 -25
- data/spec/watirspec/elements/list_spec.rb +44 -42
- data/spec/watirspec/elements/map_spec.rb +57 -55
- data/spec/watirspec/elements/maps_spec.rb +27 -25
- data/spec/watirspec/elements/meta_spec.rb +16 -14
- data/spec/watirspec/elements/metas_spec.rb +26 -24
- data/spec/watirspec/elements/ol_spec.rb +56 -65
- data/spec/watirspec/elements/ols_spec.rb +26 -24
- data/spec/watirspec/elements/option_spec.rb +91 -89
- data/spec/watirspec/elements/p_spec.rb +81 -79
- data/spec/watirspec/elements/pre_spec.rb +77 -75
- data/spec/watirspec/elements/pres_spec.rb +26 -24
- data/spec/watirspec/elements/ps_spec.rb +26 -24
- data/spec/watirspec/elements/radio_spec.rb +251 -249
- data/spec/watirspec/elements/radios_spec.rb +28 -26
- data/spec/watirspec/elements/select_list_spec.rb +537 -526
- data/spec/watirspec/elements/select_lists_spec.rb +32 -30
- data/spec/watirspec/elements/span_spec.rb +112 -110
- data/spec/watirspec/elements/spans_spec.rb +26 -24
- data/spec/watirspec/elements/strong_spec.rb +58 -58
- data/spec/watirspec/elements/strongs_spec.rb +28 -26
- data/spec/watirspec/elements/table_spec.rb +192 -139
- data/spec/watirspec/elements/tables_spec.rb +28 -26
- data/spec/watirspec/elements/tbody_spec.rb +74 -72
- data/spec/watirspec/elements/tbodys_spec.rb +40 -38
- data/spec/watirspec/elements/td_spec.rb +66 -64
- data/spec/watirspec/elements/tds_spec.rb +41 -39
- data/spec/watirspec/elements/text_field_spec.rb +206 -204
- data/spec/watirspec/elements/text_fields_spec.rb +30 -28
- data/spec/watirspec/elements/textarea_spec.rb +20 -18
- data/spec/watirspec/elements/textareas_spec.rb +18 -16
- data/spec/watirspec/elements/tfoot_spec.rb +65 -63
- data/spec/watirspec/elements/tfoots_spec.rb +42 -40
- data/spec/watirspec/elements/thead_spec.rb +65 -63
- data/spec/watirspec/elements/theads_spec.rb +42 -40
- data/spec/watirspec/elements/tr_spec.rb +48 -46
- data/spec/watirspec/elements/trs_spec.rb +42 -40
- data/spec/watirspec/elements/ul_spec.rb +56 -54
- data/spec/watirspec/elements/uls_spec.rb +26 -24
- data/spec/watirspec/radio_set_spec.rb +269 -267
- data/spec/watirspec/screenshot_spec.rb +20 -18
- data/spec/watirspec/scroll_spec.rb +152 -148
- data/spec/watirspec/shadow_root_spec.rb +86 -83
- data/spec/watirspec/user_editable_spec.rb +200 -198
- data/spec/watirspec/wait_spec.rb +289 -295
- data/spec/watirspec/window_switching_spec.rb +422 -434
- data/spec/watirspec_helper.rb +1 -23
- data/watir.gemspec +5 -4
- metadata +44 -33
- data/spec/watirspec/attributes_spec.rb +0 -18
- data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
- data/spec/watirspec/special_chars_spec.rb +0 -23
|
@@ -2,156 +2,209 @@
|
|
|
2
2
|
|
|
3
3
|
require 'watirspec_helper'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
5
|
+
module Watir
|
|
6
|
+
describe Table do
|
|
7
|
+
before do
|
|
8
|
+
browser.goto(WatirSpec.url_for('tables.html'))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Exists
|
|
12
|
+
describe '#exists?' do
|
|
13
|
+
it 'returns true if the table exists' do
|
|
14
|
+
expect(browser.table(id: 'axis_example')).to exist
|
|
15
|
+
expect(browser.table(id: /axis_example/)).to exist
|
|
16
|
+
expect(browser.table(index: 0)).to exist
|
|
17
|
+
expect(browser.table(xpath: "//table[@id='axis_example']")).to exist
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'returns the first table if given no args' do
|
|
21
|
+
expect(browser.table).to exist
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'returns false if the table does not exist' do
|
|
25
|
+
expect(browser.table(id: 'no_such_id')).not_to exist
|
|
26
|
+
expect(browser.table(id: /no_such_id/)).not_to exist
|
|
27
|
+
expect(browser.table(index: 1337)).not_to exist
|
|
28
|
+
expect(browser.table(xpath: "//table[@id='no_such_id']")).not_to exist
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'checks the tag name when locating by xpath' do
|
|
32
|
+
expect(browser.table(xpath: '//table//td')).not_to exist
|
|
33
|
+
expect(browser.table(xpath: '//table')).to exist
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "raises TypeError when 'what' argument is invalid" do
|
|
37
|
+
expect { browser.table(id: 3.14).exists? }.to raise_error(TypeError)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Other
|
|
42
|
+
describe '#strings', except: {browser: :safari, reason: 'Safari does not strip text'} do
|
|
43
|
+
it 'returns a two-dimensional array representation of the table' do
|
|
44
|
+
expect(browser.table(id: 'inner').strings).to eq [
|
|
45
|
+
['Table 2, Row 1, Cell 1',
|
|
46
|
+
'Table 2, Row 1, Cell 2']
|
|
47
|
+
]
|
|
48
|
+
expect(browser.table(id: 'outer').strings).to eq [
|
|
49
|
+
['Table 1, Row 1, Cell 1', 'Table 1, Row 1, Cell 2'],
|
|
50
|
+
['Table 1, Row 2, Cell 1',
|
|
51
|
+
"Table 1, Row 2, Cell 2\nTable 2, Row 1, Cell 1 Table 2, Row 1, Cell 2"],
|
|
52
|
+
['Table 1, Row 3, Cell 1', 'Table 1, Row 3, Cell 2']
|
|
53
|
+
]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#headers' do
|
|
58
|
+
it 'returns the first row of a table as the header row' do
|
|
59
|
+
headers = browser.table(id: 'axis_example').headers
|
|
60
|
+
expect(headers).to be_a Watir::TableHeaderCellCollection
|
|
61
|
+
expect(headers.size).to eq 4
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#hashes' do
|
|
66
|
+
it 'returns an Array of Hashes for the common table usage' do
|
|
67
|
+
array = [
|
|
68
|
+
{'' => 'March 2008', 'Before income tax' => '', 'Income tax' => '', 'After income tax' => ''},
|
|
69
|
+
{'' => 'Gregory House', 'Before income tax' => '5 934', 'Income tax' => '1 347',
|
|
70
|
+
'After income tax' => '4 587'},
|
|
71
|
+
{'' => 'Hugh Laurie', 'Before income tax' => '6 300', 'Income tax' => '1 479', 'After income tax' => '4 821'},
|
|
72
|
+
{'' => 'April 2008', 'Before income tax' => '', 'Income tax' => '', 'After income tax' => ''},
|
|
73
|
+
{'' => 'Gregory House', 'Before income tax' => '5 863', 'Income tax' => '1 331',
|
|
74
|
+
'After income tax' => '4 532'},
|
|
75
|
+
{'' => 'Hugh Laurie', 'Before income tax' => '6 252', 'Income tax' => '1 420', 'After income tax' => '4 832'},
|
|
76
|
+
{'' => 'Sum', 'Before income tax' => '24 349', 'Income tax' => '5 577', 'After income tax' => '18 722'}
|
|
77
|
+
]
|
|
78
|
+
expect(browser.table(id: 'axis_example').hashes).to eq array
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'raises an error if the table could not be parsed' do
|
|
82
|
+
browser.goto(WatirSpec.url_for('uneven_table.html'))
|
|
83
|
+
|
|
84
|
+
expect {
|
|
85
|
+
browser.table.hashes
|
|
86
|
+
}.to raise_error('row at index 0 has 2 cells, while header row has 3')
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe '#click' do
|
|
91
|
+
it "fires the table's onclick event" do
|
|
92
|
+
browser.table(id: 'inner').click
|
|
93
|
+
expect(messages).to include('table')
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe '#[]' do
|
|
98
|
+
it 'returns the nth child row' do
|
|
99
|
+
expect(browser.table(id: 'outer')[0].id).to eq 'outer_first'
|
|
100
|
+
expect(browser.table(id: 'inner')[0].id).to eq 'inner_first'
|
|
101
|
+
expect(browser.table(id: 'outer')[2].id).to eq 'outer_last'
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe '#row' do
|
|
106
|
+
let(:table) { browser.table(id: 'outer') }
|
|
107
|
+
|
|
108
|
+
it 'finds rows belonging to this table' do
|
|
109
|
+
expect(table.row(id: 'outer_last')).to exist
|
|
110
|
+
expect(table.row(text: /Table 1, Row 1, Cell 1/)).to exist
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'does not find rows from a nested table' do
|
|
114
|
+
expect(table.row(id: 'inner_first')).not_to exist
|
|
115
|
+
expect(table.row(text: /\ATable 2, Row 1, Cell 1 Table 2, Row 1, Cell 2\z/)).not_to exist
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe '#rows' do
|
|
120
|
+
it 'finds the correct number of rows (excluding nested tables)' do
|
|
121
|
+
expect(browser.table(id: 'inner').rows.length).to eq 1
|
|
122
|
+
expect(browser.table(id: 'outer').rows.length).to eq 3
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it 'finds rows matching the selector' do
|
|
126
|
+
rows = browser.table(id: 'outer').rows(id: /first|last/)
|
|
127
|
+
|
|
128
|
+
expect(rows.first.id).to eq 'outer_first'
|
|
129
|
+
expect(rows.last.id).to eq 'outer_last'
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it 'does not find rows from a nested table' do
|
|
133
|
+
expect(browser.table(id: 'outer').rows(id: 't2_r1_c1').size).to eq 0
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
describe '#tbody' do
|
|
138
|
+
it 'returns the correct instance of TableSection' do
|
|
139
|
+
body = browser.table(index: 0).tbody(id: 'first')
|
|
140
|
+
expect(body).to be_instance_of(Watir::TableSection)
|
|
141
|
+
expect(body[0][0].text).to eq 'March 2008'
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe '#tbodys' do
|
|
146
|
+
it 'returns the correct instance of TableSection' do
|
|
147
|
+
bodies = browser.table(index: 0).tbodys
|
|
148
|
+
|
|
149
|
+
expect(bodies).to be_instance_of(Watir::TableSectionCollection)
|
|
150
|
+
|
|
151
|
+
expect(bodies[0].id).to eq 'first'
|
|
152
|
+
expect(bodies[1].id).to eq 'second'
|
|
153
|
+
end
|
|
83
154
|
end
|
|
84
|
-
end
|
|
85
155
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
end
|
|
91
|
-
end
|
|
156
|
+
describe '#each' do
|
|
157
|
+
it 'allows iterating over the rows in a table' do
|
|
158
|
+
expect(browser.table(id: 'inner').to_a).to all be_a Watir::Row
|
|
159
|
+
end
|
|
160
|
+
end
|
|
92
161
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
162
|
+
context 'when nested' do
|
|
163
|
+
before do
|
|
164
|
+
browser.goto(WatirSpec.url_for('nested_tables.html'))
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'returns the correct number of rows under a table element' do
|
|
168
|
+
tables = browser.div(id: 'table-rows-test').tables(id: /^tbl/)
|
|
169
|
+
expect(tables.length).to be > 0
|
|
100
170
|
|
|
101
|
-
|
|
102
|
-
|
|
171
|
+
tables.each do |table|
|
|
172
|
+
expected = Integer(table.data_row_count)
|
|
173
|
+
actual = table.rows.length
|
|
174
|
+
browser_count = Integer(table.data_browser_count)
|
|
103
175
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
176
|
+
msg = "expected #{expected} rows, got #{actual} for table id=#{table.id}, browser reported: #{browser_count}"
|
|
177
|
+
expect(actual).to eql(expected), msg
|
|
178
|
+
end
|
|
179
|
+
end
|
|
108
180
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
end
|
|
113
|
-
end
|
|
181
|
+
it 'returns the correct number of cells under a row' do
|
|
182
|
+
rows = browser.div(id: 'row-cells-test').trs(id: /^row/)
|
|
183
|
+
expect(rows.length).to be > 0
|
|
114
184
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
end
|
|
185
|
+
rows.each do |row|
|
|
186
|
+
expected = Integer(row.data_cell_count)
|
|
187
|
+
actual = row.cells.length
|
|
188
|
+
browser_count = Integer(row.data_browser_count)
|
|
120
189
|
|
|
121
|
-
|
|
122
|
-
|
|
190
|
+
msg = "expected #{expected} cells, got #{actual} for row id=#{row.id}, browser reported: #{browser_count}"
|
|
191
|
+
expect(actual).to eql(expected), msg
|
|
192
|
+
end
|
|
193
|
+
end
|
|
123
194
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
195
|
+
it 'returns the correct number of rows under a table section' do
|
|
196
|
+
tbodies = browser.table(id: 'tbody-rows-test').tbodys(id: /^body/)
|
|
197
|
+
expect(tbodies.length).to be > 0
|
|
127
198
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
describe '#tbody' do
|
|
134
|
-
it 'returns the correct instance of TableSection' do
|
|
135
|
-
body = browser.table(index: 0).tbody(id: 'first')
|
|
136
|
-
expect(body).to be_instance_of(Watir::TableSection)
|
|
137
|
-
expect(body[0][0].text).to eq 'March 2008'
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
describe '#tbodys' do
|
|
142
|
-
it 'returns the correct instance of TableSection' do
|
|
143
|
-
bodies = browser.table(index: 0).tbodys
|
|
144
|
-
|
|
145
|
-
expect(bodies).to be_instance_of(Watir::TableSectionCollection)
|
|
146
|
-
|
|
147
|
-
expect(bodies[0].id).to eq 'first'
|
|
148
|
-
expect(bodies[1].id).to eq 'second'
|
|
149
|
-
end
|
|
150
|
-
end
|
|
199
|
+
tbodies.each do |tbody|
|
|
200
|
+
expected = Integer(tbody.data_rows_count)
|
|
201
|
+
actual = tbody.rows.count
|
|
202
|
+
browser_count = Integer(tbody.data_browser_count)
|
|
151
203
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
204
|
+
msg = "expected #{expected} rows, got #{actual} for tbody id=#{tbody.id}, browser reported: #{browser_count}"
|
|
205
|
+
expect(actual).to eql(expected), msg
|
|
206
|
+
end
|
|
207
|
+
end
|
|
155
208
|
end
|
|
156
209
|
end
|
|
157
210
|
end
|
|
@@ -2,41 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
require 'watirspec_helper'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
module Watir
|
|
6
|
+
describe TableCollection do
|
|
7
|
+
before do
|
|
8
|
+
browser.goto(WatirSpec.url_for('tables.html'))
|
|
9
|
+
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
describe 'with selectors' do
|
|
12
|
+
it 'returns the matching elements' do
|
|
13
|
+
expect(browser.tables(rules: 'groups').to_a).to eq [browser.table(rules: 'groups')]
|
|
14
|
+
end
|
|
13
15
|
end
|
|
14
|
-
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
describe '#length' do
|
|
18
|
+
it 'returns the number of tables' do
|
|
19
|
+
expect(browser.tables.length).to eq 4
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
|
-
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
describe '#[]' do
|
|
24
|
+
it 'returns the p at the given index' do
|
|
25
|
+
expect(browser.tables[0].id).to eq 'axis_example'
|
|
26
|
+
expect(browser.tables[1].id).to eq 'outer'
|
|
27
|
+
expect(browser.tables[2].id).to eq 'inner'
|
|
28
|
+
end
|
|
27
29
|
end
|
|
28
|
-
end
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
describe '#each' do
|
|
32
|
+
it 'iterates through tables correctly' do
|
|
33
|
+
count = 0
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
browser.tables.each_with_index do |t, index|
|
|
36
|
+
expect(t.id).to eq browser.table(index: index).id
|
|
37
|
+
count += 1
|
|
38
|
+
end
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
expect(count).to be > 0
|
|
41
|
+
end
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
end
|
|
@@ -2,91 +2,93 @@
|
|
|
2
2
|
|
|
3
3
|
require 'watirspec_helper'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
describe '#exists?' do
|
|
11
|
-
it 'returns true if the table body exists (page context)' do
|
|
12
|
-
expect(browser.tbody(id: 'first')).to exist
|
|
13
|
-
expect(browser.tbody(id: /first/)).to exist
|
|
14
|
-
expect(browser.tbody(index: 0)).to exist
|
|
15
|
-
expect(browser.tbody(xpath: "//tbody[@id='first']")).to exist
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'returns true if the table body exists (table context)' do
|
|
19
|
-
expect(browser.table(index: 0).tbody(id: 'first')).to exist
|
|
20
|
-
expect(browser.table(index: 0).tbody(id: /first/)).to exist
|
|
21
|
-
expect(browser.table(index: 0).tbody(index: 1)).to exist
|
|
22
|
-
expect(browser.table(index: 0).tbody(xpath: "//tbody[@id='first']")).to exist
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it 'returns the first table body if given no args' do
|
|
26
|
-
expect(browser.table.tbody).to exist
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "returns false if the table body doesn't exist (page context)" do
|
|
30
|
-
expect(browser.tbody(id: 'no_such_id')).to_not exist
|
|
31
|
-
expect(browser.tbody(id: /no_such_id/)).to_not exist
|
|
32
|
-
expect(browser.tbody(index: 1337)).to_not exist
|
|
33
|
-
expect(browser.tbody(xpath: "//tbody[@id='no_such_id']")).to_not exist
|
|
5
|
+
module Watir
|
|
6
|
+
describe 'TableBody' do
|
|
7
|
+
before do
|
|
8
|
+
browser.goto(WatirSpec.url_for('tables.html'))
|
|
34
9
|
end
|
|
35
10
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
11
|
+
describe '#exists?' do
|
|
12
|
+
it 'returns true if the table body exists (page context)' do
|
|
13
|
+
expect(browser.tbody(id: 'first')).to exist
|
|
14
|
+
expect(browser.tbody(id: /first/)).to exist
|
|
15
|
+
expect(browser.tbody(index: 0)).to exist
|
|
16
|
+
expect(browser.tbody(xpath: "//tbody[@id='first']")).to exist
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'returns true if the table body exists (table context)' do
|
|
20
|
+
expect(browser.table(index: 0).tbody(id: 'first')).to exist
|
|
21
|
+
expect(browser.table(index: 0).tbody(id: /first/)).to exist
|
|
22
|
+
expect(browser.table(index: 0).tbody(index: 1)).to exist
|
|
23
|
+
expect(browser.table(index: 0).tbody(xpath: "//tbody[@id='first']")).to exist
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'returns the first table body if given no args' do
|
|
27
|
+
expect(browser.table.tbody).to exist
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "returns false if the table body doesn't exist (page context)" do
|
|
31
|
+
expect(browser.tbody(id: 'no_such_id')).not_to exist
|
|
32
|
+
expect(browser.tbody(id: /no_such_id/)).not_to exist
|
|
33
|
+
expect(browser.tbody(index: 1337)).not_to exist
|
|
34
|
+
expect(browser.tbody(xpath: "//tbody[@id='no_such_id']")).not_to exist
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "returns false if the table body doesn't exist (table context)" do
|
|
38
|
+
expect(browser.table(index: 0).tbody(id: 'no_such_id')).not_to exist
|
|
39
|
+
expect(browser.table(index: 0).tbody(id: /no_such_id/)).not_to exist
|
|
40
|
+
expect(browser.table(index: 0).tbody(index: 1337)).not_to exist
|
|
41
|
+
expect(browser.table(index: 0).tbody(xpath: "//tbody[@id='no_such_id']")).not_to exist
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "raises TypeError when 'what' argument is invalid" do
|
|
45
|
+
expect { browser.tbody(id: 3.14).exists? }.to raise_error(TypeError)
|
|
46
|
+
expect { browser.table(index: 0).tbody(id: 3.14).exists? }.to raise_error(TypeError)
|
|
47
|
+
end
|
|
41
48
|
end
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
describe '#[]', except: {browser: :safari, reason: 'Safari does not strip text'} do
|
|
51
|
+
it 'returns the row at the given index (page context)' do
|
|
52
|
+
expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008'
|
|
53
|
+
expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
|
54
|
+
expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'returns the row at the given index (table context)' do
|
|
58
|
+
expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008'
|
|
59
|
+
expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
|
60
|
+
expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
|
61
|
+
end
|
|
46
62
|
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe '#[]', except: {browser: :safari, reason: 'Safari does not strip text'} do
|
|
50
|
-
it 'returns the row at the given index (page context)' do
|
|
51
|
-
expect(browser.tbody(id: 'first')[0].text).to eq 'March 2008'
|
|
52
|
-
expect(browser.tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
|
53
|
-
expect(browser.tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it 'returns the row at the given index (table context)' do
|
|
57
|
-
expect(browser.table(index: 0).tbody(id: 'first')[0].text).to eq 'March 2008'
|
|
58
|
-
expect(browser.table(index: 0).tbody(id: 'first')[1][0].text).to eq 'Gregory House'
|
|
59
|
-
expect(browser.table(index: 0).tbody(id: 'first')[2][0].text).to eq 'Hugh Laurie'
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
describe '#row' do
|
|
65
|
+
it 'finds the first row matching the selector' do
|
|
66
|
+
row = browser.tbody(id: 'first').row(id: 'gregory')
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
expect(row.tag_name).to eq 'tr'
|
|
69
|
+
expect(row.id).to eq 'gregory'
|
|
70
|
+
end
|
|
69
71
|
end
|
|
70
|
-
end
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
describe '#rows' do
|
|
74
|
+
it 'finds rows matching the selector' do
|
|
75
|
+
rows = browser.tbody(id: 'first').rows(id: /h$/)
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
expect(rows.size).to eq 2
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
expect(rows.first.id).to eq 'march'
|
|
80
|
+
expect(rows.last.id).to eq 'hugh'
|
|
81
|
+
end
|
|
80
82
|
end
|
|
81
|
-
end
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
describe '#strings' do
|
|
85
|
+
it 'returns the text of child cells' do
|
|
86
|
+
expect(browser.tbody(id: 'first').strings).to eq [
|
|
87
|
+
['March 2008', '', '', ''],
|
|
88
|
+
['Gregory House', '5 934', '1 347', '4 587'],
|
|
89
|
+
['Hugh Laurie', '6 300', '1 479', '4 821']
|
|
90
|
+
]
|
|
91
|
+
end
|
|
90
92
|
end
|
|
91
93
|
end
|
|
92
94
|
end
|