I'm trying to check that a list of elements from a column on a webpage are in descending order. I come from a Java background so I'm still trying to figure out why this wont work. To my knowledge when it hits that final expect, isDescending should be properly set, but instead it never changes from what I initialize it as.
I've put print statements in the loop previously and everything is working fine in there.
I did some digging and it probably has to do with either it running the expect at the bottom before it finishes the loop, or isDescending is not actually getting set properly for some reason.
I tried a number of things like setTimeout and others but nothing fixed the issue.
Here is the below code, looking for any suggestions or link to pages where I can research more.
function checkIfDescending(){
// Will hold list of webelements that each have one account number
const accountNumbersDescending = pa_search.account_no_column_elements();
let previousDescendingValue = '';
let isDescending = true;
accountNumbersDescending.each((accountNumberElement) => {
accountNumberElement.getText().then((text) => {
if (previousDescendingValue !== '') {
if (!(text >= previousDescendingValue)) {
isDescending = false;
}
}
previousDescendingValue = text;
});
});
expect(isDescending).toBe(true);
}
As a final note, if I put the expect within the if statement, it properly works. Problem is that it then will run several times if there is a failure early on.