I have this code:
<table class="table" id="charges_failed">
<tr>
<th>Customer</th>
<th>Charge Amount</th>
<th>Date Failed</th>
<th colspan="3"></th>
</tr>
<% @charges_failed.each do |charge| %>
<tr bgcolor="#FF0000">
<td><%= charge.formatted_customer_name %></td>
<td><%= number_to_currency(charge.amount.to_s) %></td>
<td><%= charge.created_at.strftime("%d/%m/%Y") %></td>
</tr>
<% end %>
And I have this test:
it "check failed charges" do
visit root_path
expect(page).to have_selector('table#charges_failed tr', :count => 6)
end
Why he finds only the first row in the table. Total on page 6 of them. (error: expected to find css "table#charges_failed tr" 6 times, found 1 match: "Customer Charge Amount Date Failed")
I find the easiest method is to use xpaths.
Would be something like:
within('table#charges_failed') do
expect(page).to have_xpath(".//tr", :count => 6)
end
You could probably also drop the 'within' and define a full xpath like: ".//table[@id='charges_failed']//tr"
As far as I know have_selector just checks for the presence of something (css, xpath etc). I've never seen a count used with it before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With