1
votes

I am doing e2e testing using protractor for my Angular application. This is my code

<input type="button" value='Add New Record'/>
<table class="table table-striped s10 ng-scope">
    <tbody>
        <tr>
            <th>Name</th>
            <th>Age</th>
            <th>Appt Time</th>
            <th>Tag</th>
        </tr>
        <tr>
            <td>Bob</td>
            <td>2</td>
            <td>12:30AM</td>
            <td><input type="button" value='Add Tag'/></td>
        </tr>
         <tr>
            <td>Alice</td>
            <td>2</td>
            <td>10:10AM</td>
             <td><input type="button" value='Add Tag'/></td>
        </tr>
    </tbody>
</table>

My question is , if I click on 'Add New Record' it will appens a new record to the table. Here I want to test the Name of newly created record and 'Add Tag' button. I tried below code

it('Testing Add New Record', function(){  
    var tbl = element( by.css('.table'));
     var tblrow = tbl.all( by.css('tr')).get(0);
     var tbldata = tblrow.all(by.css('td')).get(0);
          expect(tbldata.getText()).toEqual('Alice');
     var tbldata = tblrow.all(by.css('td')).get(2);
     tbldata.click();
       });

It is working. But if I add one more record, we have to change the code each time. So I want to find the text of newly created record and 'Add Tag' button dynamically.

1

1 Answers

1
votes

If I understand correctly, you need to verify that after creating a new record it appears as the last row in the table. In this case, instead of getting it by index, use last():

element.all(by.css('table.s10 tr')).last();