I am trying to implement a sorting method on a transporter ElementArrayFinder. As you know, all protractor methods return promises. Therefore, my sorting method has a condition depending on the resolution of promises. I use the node plugin for async/awaitto make it compatible with node.js versions below 6. (Here the plugin: https://www.npmjs.com/package/asyncawait )
Here is my code where this- ArrayElementFinder:
var asyncCompare = async(function(a, b) {
let x = await (a.getText());
let y = await (b.getText());
console.log(x.localeCompare(y));
return x.localeCompare(y);
});
var sortTheArray = async(function(arrayOfElementFinders) {
return await (arrayOfElementFinders.sort(asyncCompare));
});
this.then((elements) => {
let arrayOfElementFinders = [elements[0], elements[1], elements[2]];
let sortedArray = sortTheArray(arrayOfElementFinders);
console.log('array sorted');
});
Unfortunately, the timing is not the one I expect. Printing: array sortedoccurs earlier than comparison prints x.localeCompare(y). Any idea what I'm doing wrong? And any idea how to achieve my goal?
Thanks so much for any help