Home Ask Login Register

Developers Planet

Your answer is one click away!

thegunner February 2016

identifying that table header values are what they should be

I'm trying to prove that in a table we have the following table labels. Date, amount, comment.

<table class="grid-table-body">
<thead>
    <tr>
        <th>Date</th>
        <th>Amount (£)</th>
        <th>Description</th>
    </tr>
</thead>
<tbody>

    .....
    .....
    .....

</tbody>
</table>

I've got as far as proving the table is present!

   var myTable = element(by.css('.grid-table-body'));
   expect(myTable.isPresent()).toBeTruthy();

How can I loop through each <th> and get the text. If I was just to put them into an array I could prove they are what they should be. i.e.

expect(data.get(0).getText()).toBe("Date");

Would be enough (I think)

Answers


alecxe February 2016

First locate the elements, then you can call getText():

var headers = $$(".grid-table-body thead th");
expect(headers.getText()).toEqual(["Date", "Amount (£)", "Description"]);

To check that all of the headers are visible, you can either use:

expect(headers.isDisplayed()).toEqual([true, true, true]);

Or, check if there is no false in the array:

expect(headers.isDisplayed()).not.toContain(false);

You can also map()/reduce() it to a single boolean value.

Post Status

Asked in February 2016
Viewed 1,720 times
Voted 4
Answered 1 times

Search




Leave an answer


Quote of the day: live life