In my angular protractor e2e tests, I want to do assertions on a html fragment like this:
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
<tr>
<td>Joe</td>
<td>23</td>
<td>M</td>
</tr>
<tr>
<td>Mary</td>
<td>26</td>
<td>W</td>
</tr>
...
</tbody>
</table>
How can I convert that into a JavaScript object like this?
[
{Name: 'Joe', Age: 23, Gender: 'M'},
{Name: 'Mary', Age: 25, Gender: 'W'},
...
]
I tried this, but it gives me one dimensional array:
const row = element.all(by.css('tr'));
const cells = row.all(by.tagName('td'));
return cells.map(function (elm) {
return elm.getText();
});