In my Angular Protractor end-to-end (e2e) tests, I need to perform assertions on an HTML fragment similar to the following:
<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>
Is there a way to transform this into a JavaScript object in the following format?
[
{Name: 'Joe', Age: 23, Gender: 'M'},
{Name: 'Mary', Age: 25, Gender: 'W'},
...
]
I attempted the following approach, however, it only returns a 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();
});