In the app I am automating using appium+node.js, the screen with Offers has recycler view for offer list. Each cell is an image without any text on it.
I am getting the total count of offers through API call and want to assert that count by counting the total list entries.
Currently I am only able to get count of elements displayed on the screen(i.e 3 in this case).
How can I count each entry of this section and match that count with the total count of api result?
While scrolling the list How would I know when to stop as there are no last element to be identified specifically.
How to scroll till the end of the list.
So from there, you can get the total count by counting a number of times
you got index as 2. Scroll till the end of the screen and count the
occurrences of 2.
In this scenario, there is no unique content to differentiate each element. They are just images.
Is there any unique attribute I can get by using element.getAttribute() ?
The DEV has done the required changes and has added a unique id to the content-desc.
Now I am having issues in scrolling/swiping the list till the condition is satisfied.
Can you please look into the code i have posted and tell me what am I doing wrong:-
@shashikumarraja i am not nice js coder. for example do not get why in your while first action is RETURN.
mine code in java consist like (code has gramma errors. written from memory as is.):
int loopBreaker = 0;
String newText = null;
String oldText = null;
oldText = someElementList.get(0).getAttribute("content-descr");
int elementCounter = 0;
do {
//do swipe
newText = someElementList.get(0).getAttribute("content-descr");
if (newText.equals(oldText)) {
loopBraker++;
} else {
loopBraker = 0;
oldText = newText;
}
} while (newText.equals(oldText) && loopBraker > 1); // we do try 2 times swipe when we reach end for sure
// swipe end. now read last value of 'content-descr' of last element
elementCounter = Integer.parse(someElementList.get(someElementList.size()-1).getAttribute("content-descr"))
@Aleksei Thanks for your help. I was able to figure it out. The problem was indeed of RETURN.
Instead of while loop I chose the recursive implementation as while loop is not recommended for async function calls in javascript.
let swipeAndSaveElement = async function (driver, offersDisplayedInApp, offersCountFromApi) {
let els = await driver.elementsById(offersBanner);
if (els.length > 0) {
var repeatedIdCount = 0
for (let el of els) {
let offerId = await el.getAttribute('contentDescription');
if (offersDisplayedInApp.indexOf(offerId) === -1) {
offersDisplayedInApp.push(offerId);
} else {
repeatedIdCount++;
console.log('offerId already exists in the array'.green);
}
}
if (offersDisplayedInApp.length <= offersCountFromApi && repeatedIdCount < 3) {
await swipeNew(driver);
await swipeAndSaveElement(driver, offersDisplayedInApp, offersCountFromApi);
}
else if (offersDisplayedInApp.length === offersCountFromApi) {
console.log('OffersId count matched'.green);
return true;
} else {
throw "offersId count didn't match with the offersCountFromApi";
return false;
}
} else {
console.log('offerIds not found'.red);
return false;
}
}
Hope it can help every1, you just have to find the last element in list!
public static int index=0;
ArrayList<String> generalArray = new ArrayList<String>();
String a = "last element in the list";
while (!found_result) {
List<WebElement> ele = driver.findElementsByXPath("locator of your list");
int size = 0;
size = size + ele.size();
for (int i = 0; i < size; i++) {
String s = ele.get(i).getText();
if (s.equals(a)) {
found_result = true;
System.out.print("index = " + (index+1));
break;
} else {
if (!generalArray.contains(s)) {
index++;
generalArray.add(s);
}
}
}
if (!found_result) {
scrollEvent(); //this's my function, scroll to find invisible elements
Thread.sleep(1000);
}
}