To check the sorting in any order,
- Click on the sortBy element to sort the element in order.
- Get the text of an element from columns displayed with sort order.
- Save each element text in an array later so that you can check the sorting later.
- The next step is to copy this unsorted array into a temporary array and sort the temporary array.
- , , , ,
expect.
Javascript sort() reverse() .
, . , -
var sorted = [] , unSorted = [];
var ele = element.all(by.css(tbody tr td:nth-of-type(1)));
ele.each(function(eachName){
eachName.getText().then(function(name){
unSorted[i] = name;
i++;
});
}).then(function(){
sorted = unSorted.slice();
sorted.sort();
expect(sorted).toEqual(unSorted);
});
RollNo . , , .
map() , , . . -
ele.map(function(eachName){
return eachName.getText().then(function(unSorted){
return unSorted;
});
}).then(function(unSorted){
var sorted = unSorted.slice();
sorted = sorted.sort();
expect(sorted).toEqual(unSorted);
});
, .