1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Update History and fix with_cols when no vertical table headers

This commit is contained in:
Thomas Walpole 2019-03-16 19:44:31 -07:00
parent 94beb19baa
commit 8fdb380133
3 changed files with 34 additions and 2 deletions

View file

@ -4,6 +4,7 @@ Release date: unreleased
### Added
* `attach_file` now supports a block mode on JS capable drivers to more accurately test user behavior when file inputs are hidden (beta)
* :table selector now supports `with_rows` and `with_cols` filters
### Fixed

View file

@ -468,14 +468,14 @@ Capybara.add_selector(:table, locator_type: [String, Symbol]) do
table_ancestor = XPath.ancestor(:table)[1]
xp = XPath::Expression.new(:join, table_ancestor, xp)
cell_xp[XPath.string.n.is(cell) & XPath.position.equals(xp.preceding_sibling.count)]
cell_xp[XPath.string.n.is(cell) & XPath.position.equals(xp.preceding_sibling(:td).count.plus(1))]
end
else
cells_xp = col.reduce(nil) do |xp, cell|
cell_conditions = [XPath.string.n.is(cell)]
if xp
prev_row_xp = XPath::Expression.new(:join, XPath.ancestor(:tr)[1].preceding_sibling(:tr), xp)
cell_conditions << XPath.position.equals(prev_row_xp.preceding_sibling.count)
cell_conditions << XPath.position.equals(prev_row_xp.preceding_sibling(:td).count.plus(1))
end
XPath.descendant(:td)[cell_conditions.reduce :&]
end

View file

@ -42,6 +42,27 @@ RSpec.describe Capybara do
<table>
<tr><td></td></tr>
</table>
<table id="rows">
<tr>
<td>A</td><td>B</td><td>C</td>
</tr>
<tr>
<td>D</td><td>E</td><td>F</td>
</tr>
</table>
<table id="cols">
<tbody>
<tr>
<td>A</td><td>D</td>
</tr>
<tr>
<td>B</td><td>E</td>
</tr>
<tr>
<td>C</td><td>F</td>
</tr>
</tbody>
</table>
</body>
</html>
STRING
@ -467,6 +488,16 @@ RSpec.describe Capybara do
end
end
end
describe ':table selector' do
it 'finds by rows' do
expect(string.find(:table, with_rows: [%w[D E F]])[:id]).to eq 'rows'
end
it 'finds by columns' do
expect(string.find(:table, with_cols: [%w[A B C]])[:id]).to eq 'cols'
end
end
end
end
end