Unable to Scroll Up on Android. Unable to use scroll to text either


#1

Hi All,

  1. I am unable to use the scroll to text function. When executed the function merely scrolls down about 100 pixels and stops. It does not scroll to the specified text.

  2. I am therefore using the Swipe function to scroll down and using the following coordinates:

StartX: 1000
StartY: 0
EndX: 100
EndY: 100

Using the inverse of this does not work to scroll up e.g.

StartX: 1000
StartY: 100
EndX: 100
EndY: 0

Can you help me use the scroll to text function or explain what I am doing wrong with the swipe function.

Kid regards,

Patrick

Katalon 5.3.0
Windows 10
Testing on Android emulator BlueStacks


#2

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.android

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver

class 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.TextView")		
		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.TextView")			
		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:

CustomKeywords.'com.my.keywords.android.swiping.scrollListToElementWithText'('My Label')

#3

Hi chris, i’ve try that and i got this :

ERROR] - Negative array index [-1] too large for array size 0


#4

Hi Joko,

It’s likely then that the element classes in your list aren’t of type android.widget.CheckedTextView as in the example code above. The index error is indicating that there are no elements found in the listElement array, so something on the screen doesn’t match the code.

They could possibly be android.widget.TextView. Can you try changing the code you pulled from above to use android.widget.TextView instead (make sure you change both places in the code from above)?

Alternatively, I used the code sample above as a basis for an open source library that helps with several complicated tasks in Katalon Studio tests. For example, here is a section that should make scrolling easier:

If you’re interested in using this library, here’s some Katalon documentation on using third party libraries:

You can get the library jar file at:

https://github.com/detroit-labs/katalon-mobile-util/releases/download/1.9.0/katalon-mobile-util-1.9.0.jar

Hope this helps,

Chris


#5

Hi @Chris_Trevarthen,
I have tried using katalon-mobile-util library and I got this error:
Test Cases/Tc_Scroll2Bottom FAILED.
Reason:
com.detroitlabs.katalonmobileutil.exception.ListItemsNotFoundException:
Could not find any list elements matching xpath: //*[contains(@class, ‘TextView’)]
and that exactly one label has the text: ‘Album’
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollEntireList(Scroll.java:164)
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithXPath(Scroll.java:120)
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:73)
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:41)
at com.detroitlabs.katalonmobileutil.touch.Scroll$scrollListToElementWithText.call(Unknown Source)
at Tc_Scroll2Bottom.run(Tc_Scroll2Bottom:38)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1547242602394.run(TempTestCase1547242602394.groovy:22)

Any ideas?
Thanks


#6

Hi Yudi,

From the error, it looks like the library couldn’t find a TextView element with the text ‘Album’. This could be for a couple of reasons:

  1. The elements you’re trying to scroll through haven’t appeared on the screen yet
  2. The element types you’re trying to scroll don’t contain the class TextView
  3. There are other elements on the screen, like buttons, that are also detected as TextView, but they aren’t part of the scrolling list. If they’re static elements, like buttons, then the scroll action doesn’t work on them and the scrolling has no effect.

In any of these cases, some more info would be helpful for troubleshooting:

  • Can you provide a screenshot of the screen you’re trying to test with the scrolling? A picture of what the Katalon Mobile Spy shows would be helpful, so that I can see how the elements are detected.
  • Secondly, the katalon-mobile-util library has some built-in logging that can give a litle more info about how it’s working.

To do that, at the top of your test, import some of the Logging classes:

import com.detroitlabs.katalonmobileutil.logging.Logger
import com.detroitlabs.katalonmobileutil.logging.Logger.LogLevel

Logger.initialize('/tmp/mytest.log', LogLevel.DEBUG)

Now, if you open the file /tmp/mytest.log, you’ll see a running log of what katalon-mobile-util is doing, including the elements that it sees on the screen when doing scrolling. NOTE: You can change the log location to somewhere else that’s more convenient for you just by changing the first argument to Logger.initialize.

If you can provide the log and images from above, I think it will give me a better idea of why the scrolling isn’t working.

Thanks,

Chris


#7

Hi @Chris_Trevarthen,
Thanks for your reply.
Please find the screenshots attached.

Here are my scripts:
Logger.initialize(’/tmp/katalon.log’, LogLevel.DEBUG)
CustomKeywords.‘utils.Swiping.scrollListToElementWithText’(‘Album’)

I got an error as follows:

Blockquote
java.io.FileNotFoundException: \tmp\katalon.log (The system cannot find the path specified)
at com.detroitlabs.katalonmobileutil.logging.Logger.initialize(Logger.java:28)
at com.detroitlabs.katalonmobileutil.logging.Logger$initialize.call(Unknown Source)
at Verify that user can scroll to bottom of the screen.run(Verify that user can scroll to bottom of the screen:31)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1547435641312.run(TempTestCase1547435641312.groovy:22)

How can I get the log path for ‘/tmp/katalon.log’ ?

Thanks,
Yudi


#8

Hi Yudi,

Sorry, I assumed you were on a Mac. If you’re on Windows, you should be able to set the path for the log to something like: Logger.initialize('c:\mytest.log', LogLevel.DEBUG). Let me know if that works any better.

– Chris


#9

Hi @Chris_Trevarthen,
Thanks for prompt reply.
Please find the log file attached.
mytest.log (3.4 KB)

Cheers,
Yudi


#10

Hi Yudi,

Thanks for providing the log file and screenshots - they are very helpful. I think the issue is that the Scroll.scrollListToElementWithText function is made to scroll a list of similar elements, like a bunch of elements in a drop-down list. In your case, it looks like you want to scroll the entire screen until you find a certain element.

The katalon-mobile-util library doesn’t have anything for that (yet), but there should be ways to do it using the regular Katalon functions:

Documentation on the Mobile.swipe function:

A forum post on how to get swiping to work:

Hope this helps,

Chris


#11

Hi @Chris_Trevarthen,

Thank you so much for your help.
I will try it today.

Cheers,
Yudi