I found that Mobile.scrollToText(‘My Label’) didn’t work well on Android when the drop down list was longer than one screen. It would scroll a bit, then stop, never finding my required item.
To get around this, I had to extend Katalon by creating a Custom Keyword to handle scrolling - this relies on the AppiumDriver library (thanks to Nhi Dinh for the sample code):
Create a new keyword file:
package com.my.keywords.androidimport com.kms.katalon.core.annotation.Keywordimport com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactoryimport io.appium.java_client.AppiumDriverimport io.appium.java_client.TouchActionclass swiping { AppiumDriver driver; swiping() { this.driver = MobileDriverFactory.getDriver() } private scrollEntireList() { // very specific to android and the type of element that makes up your dropdowns ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView") TouchAction touchAction = new TouchAction(driver) def bottomElement = listElement[listElement.size() - 1] def topElement = listElement[0] // Press and scroll from the last element in the list all the way to the top touchAction.press(bottomElement).moveTo(topElement).release().perform(); } @Keyword def boolean scrollListToElementWithText(String elementText) { boolean isElementFound = false; while (isElementFound == false) { // very specific to android and the type of element that makes up your dropdowns ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView") for (int i = 0; i<listElement.size(); i++) { String textItem = listElement[i].getText() if (textItem == elementText) { isElementFound = true; return true; } } scrollEntireList() } }}
Then in your test, you can use the Custom Keyword like:
While running test - Console says, that scroll is “Passed”
but Android Studio emulator don’t scrolling (Tried Android 7.0 and 8.0 Nexus 6p and Pixel 2l)
3.1 Version of Katalon studio
I have same problem now,
I’ve create and run my test script and run well before
then I re-execute my test script, and katalon can’t scroll page but console says is passed
is no change on app and my test script
I found that Mobile.scrollToText(‘My Label’) didn’t work well on Android when the drop down list was longer than one screen. It would scroll a bit, then stop, never finding my required item.
To get around this, I had to extend Katalon by creating a Custom Keyword to handle scrolling - this relies on the AppiumDriver library (thanks to Nhi Dinh for the sample code):
Create a new keyword file:
package com.my.keywords.androidimport com.kms.katalon.core.annotation.Keywordimport com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactoryimport io.appium.java_client.AppiumDriverimport io.appium.java_client.TouchActionclass swiping { AppiumDriver driver; swiping() { this.driver = MobileDriverFactory.getDriver() } private scrollEntireList() { // very specific to android and the type of element that makes up your dropdowns ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView") TouchAction touchAction = new TouchAction(driver) def bottomElement = listElement[listElement.size() - 1] def topElement = listElement[0] // Press and scroll from the last element in the list all the way to the top touchAction.press(bottomElement).moveTo(topElement).release().perform(); } @Keyword def boolean scrollListToElementWithText(String elementText) { boolean isElementFound = false; while (isElementFound == false) { // very specific to android and the type of element that makes up your dropdowns ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView") for (int i = 0; i<listElement.size(); i++) { String textItem = listElement[i].getText() if (textItem == elementText) { isElementFound = true; return true; } } scrollEntireList() } }}
Then in your test, you can use the Custom Keyword like:
In the above code, I don’t think there is any validation that the scrolling occurred, so if it doesn’t scroll, the test continues. If you were to verify that the element is visible (or try to tap on it) after you do the scrolling, the test should fail. Something like:
Mobile.verifyElementVisible(findTestObject('Object Repository/My Test Object'), 20)
I had trouble with getting scrolling to work as well when I first started using Katalon Studio. There seem to be a lot of tricks based on the platform you’re using. If you don’t mind adding an external library .jar to your test project, this open source library I have been working on might help: