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