? QA Design Gurus: Working with Tables using TTS

Sep 1, 2015

Working with Tables using TTS

Working with Tables using TTS

In most of the Web UI automation we will come across data shown in Tables.
Verifying Table content is not that straight forward because in most of the cases table data will be random and Table size will not be constant.

In this post let us see how we can automate tables using TTS.

1. Add a coded/Script step to the test
2. See if you can add the table to the Element Explorer with proper find Expression
3. If you are able to add you can directly apply find expressions logic on finding the data
4. Otherwise we need to identify the table also using find expressions.
5. Find corresponding data and performing operations on it.

Using Recorder
Adding Table to Element Repository           
1. Using Recorder, Highlight any of the element in Table and click on Locate in Dom. This shows the corresponding element in dom
2. Select the Table node in Dom and say 'Add to Element Repository'
3. This shows up a dialog on TTS/Visual Studio, Provide the friendly name and save it.
4. Now navigate to Elements section and see that element is added under corresponding Page.

Adding Column Count or Row Count Verifications using Recorder
1. Using Recorder, Highlight any of the element in Table and click on Locate in Dom. This shows the corresponding element in Dom
2. Select the Table node
3. Click on 'Verification' tab and choose Table
4. Observe that Rows Count is shown as in below screen shot. Select the drop down and change to 'Column Count' if you want to verify column count.
5. Just click on 'Add Step', verification step will be added to the test case.



Using Coded Steps
Assuming below html code for table
<html>
<body>
<table id=usr-table" class="table user-table" style="width:100%">
<tr>
   <th>First Name</th>
   <th>Lasst Name</th>
    <th>Email Address</th>
    <th>
 </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>      
    <td>jillsmith@test.com</td>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>      
    <td>evejackson@test.com</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>      
    <td>johndoe@test.com</td>
  </tr>
</table>

</body>
</html>
 

Finding Table
    ActiveBrowser.RefreshDomTree();
    HtmlTable tbl = Find.ByAttributes<HtmlTable>("id=usr-table", "class=table user-table");
    Log.WriteLine(tbl.InnerText);
   
Getting All Rows count in Table including Header, body and Footer rows
    Log.WriteLine(Pages.Users.UserTable.AllRows.Count.ToString());
        or
    IList<HtmlTableRow> rowData = Pages.Users.UserTable.Find.AllByExpression<HtmlTableRow>("tagname=tr");
    Log.WriteLine(rowData.Count.ToString());
   
Getting only Table body rows count
    Log.WriteLine(Pages.Users.UserTable.Rows.Count.ToString());
   
Finding Table row with some data. Here I am finding row using emailId
    HtmlTableRow rowData = Pages.UsersPage.UsersTable.Find.ByExpression<HtmlTableRow>("tagname=tr", "innertext=~" + emailId);
    Log.WriteLine(rowData.InnerText.ToString());
   
    Note: '~' is used when we want to find data using partial text. It is equivalent to 'contains'.
   
Asserting Row Count
    Pages.Users.UserTable.AssertTable().RowCount(ArtOfTest.Common.NumberCompareType.Equals, 1);
   
Getting Header Rows count, Footer Rows Count and Child Nodes count
    Log.WriteLine("Head Rows --- " +Pages.Users.UserTable.HeadRows.Count.ToString());
    Log.WriteLine("Foor Rows --- " + Pages.Users.UserTable.FootRows.Count.ToString());
    Log.WriteLine("Child Nodes --- " + Pages.Users.UserTable.ChildNodes.ToString());
   
Getting Table Column Count
    IList<HtmlTableCell> cols = Pages.HttpsEndpoint2MainInt.UsrTableTable.Find.AllByExpression<HtmlTableCell>("tagname=td");
    Log.WriteLine(cols.Count.ToString());
   
        or
    Log.WriteLine(Pages.Users.UserTable.ColumnCount.ToString());
   
Asserting Column count
    Pages.Users.UserTable.AssertTable().ColumnCount(ArtOfTest.Common.NumberCompareType.Equals, 3);
   

These functions helps us in automating tables efficiently.
           

No comments:

Post a Comment