Home > Mobile >  List only records populated with Capybara
List only records populated with Capybara

Time:04-20

Friends helped me with a solution that validates if there are [active/inactive] records in the list. When I list the records using pp capybara also returns blank lines. How do I disregard empty records?

def validate_active_inactive_records
  expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/) 
 
  # ***listing records***
  page.all('.tvGrid tr > td:nth-child(5)').each do |td|
    puts td.text
  end
end
<table width="100%" >
  <tbody>
  <tr>
    <th colspan="1" >Id</th>
    <th colspan="1" >Code</th>
    <th colspan="1" >Description</th>
    <th colspan="1" >Operational Center</th>
    <th colspan="1" >Status</th>
  </tr>
  <tr >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
   </tr>
  </tbody>
</table>

CodePudding user response:

Are you asking how to remove the rows with the class tvRowEmpty from your search results? If so, you can use the :not operator in your finder:

def validate_active_inactive_records
  expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/) 
 
  # ***listing records***
  page.all('.tvGrid tr:not(.tvRowEmpty) > td:nth-child(5)').each do |td|
    puts td.text
  end
end

If you want to exclude any td that just contains &nbsp; you could use the following finder with a regex that filters tags containing only whitespace characters:

page.all('.tvGrid tr > td:nth-child(5)', text: /[\s]^*/).each 
  • Related