Unable to Swipe

Hi guys,

I’m facing a problem when using Mobile.swipe() while testing my app in Android AVD emulator.In my app, i was trying to scroll down the side menu bar


, so i’m following the guideline code to as stated
However, after script has run completely, i did notice my sidebar has scrolling slightly downwards but the log shows i’m executed successfully.
Did anyone has this problem too?

Hi @Alan_Chan1,

Here are a few things you can try:

  1. The endY value might be calculated incorrectly. According to the documentation, it’s a relative position, so you might want to try some different numbers (including negative, if you’re trying to scroll down on the screen).

  2. Check out this blog post where someone creates their own method for scrolling using a Javascript function (it’s for iOS, but it looks like it would work on Android)

  3. Try this other forum post where someone used the TouchAction to create a scrolling effect: ***URGENT - Mobile.swipe does not execute (screen stays static) but passes in log [Updated]

  4. I have an open source library, katalon-mobile-util, which has some convenience methods for scrolling through a list of the same class of elements: https://github.com/detroit-labs/katalon-mobile-util#scrolling

    If you’re interested in using this library, here’s some Katalon documentation on using third party libraries: https://docs.katalon.com/katalon-studio/tutorials/import_java_library.html

    Katalon Studio allows users to import external Java .jar libraries either through Katalon project settings or copying .jar files to a designated folder.

    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

1 Like

Hi Chris_Treverthen,
I was going through multiple post about scrolling issue and I’ve seen how hard you work to have the issues resolved so I have humble request to guide me through my vertical scroll issue that I’m having with my application. I tried Scroll to Text but it scrolls left to right. I couldn’t do the swipe option because I am still confused on how to capture starting x, starting y, ending x and ending y coordination. I have a demo coming up and I would really appreciate a prompt response, thanks again.

Hi @rkarim,

Would you be able to share a screenshot of what the screen looks like that you’re trying to scroll? Could you also share what the captured object/test object is for the element you’re trying to scroll to?

I’ve found that the ScrollToText doesn’t work very well, like you saw.

As for getting the x and y coordinates, you can first try some guesses based on the screen size/specs of your device. There are some Katalon functions to get the actual height and width of the device:

https://docs.katalon.com/katalon-studio/docs/mobile-get-device-height.html#parameters-

https://docs.katalon.com/katalon-studio/docs/mobile-get-device-width.html#example

– Chris

Hi Chris,
I tried all your methods that you have shared in all of your posts but none of them are working. I even tried with Touch Action with custom keyword but none of them are scrolling down my screen what so ever. At best it is looking for text within another element drop down menu but it doesn’t navigate downward at all. Here are some screen shots and also check out the commented codes that I’ve used as well. I’ve run the get height and get width code and it returned device height as : 1289 and the width is : 720. I’m in a desperate need of your help the whole application is full of scrolling down screens and they all can be resolved once I figure this issue out, thanks.


Hi @rkarim,

Thanks for providing those screenshots - they’re very helpful in troubleshooting this issue!

If I understand correctly, you want to be able to fill out the Year, Make, Model, and Trim fields, then scroll down to the below field: Engine, Displacement, Induction, Fuel Type, etc.? If that’s the use case, then I think you can try this approach:

  • First, give the headings above each dropdown field the same resource-id (this will probably need to be done by a developer, unless you have access to the source project). This resource-id should be something more specific than android:id/text1, it should be something descriptive like android:id/categoryHeader. Giving all of the heading labels the same id will let us treat them as a group and more easily scroll through them.
  • Using the katalon-mobile-util Scroll package, you can scroll through all of the form field headers:
    // Make sure you import the Scroll class at the top of your test
    import com.detroitlabs.katalonmobileutil.touch.Scroll

    String headerResourceId = 'android:id/categoryHeader'
    String headerText = 'Displacement'
    int timeout = 5
    Scroll.scrollListToElementWithText(headerResourceId, headerText, timeout)

This should handle scrolling down the screen to the appropriate heading, then you can access the dropdown field like you normally would.

– Chris

Hey Chris,
Thank you so much for looking into this issue, so let me repeat what you have mentioned so I can understand it clearly so you want me to reach out to my mobile dev to change the resource-id for each drop down element of the screen and give their own unique resource-id? Or name all the resource-id for all the drop down elements with the same name like android:id/categoryHeader?

And another question is can I just change the resource-ID within the Object repository for Katalon to treat each dropdown as a group? Just tryin to find another way to resolve this issue without getting the dev involved you know? Even if I can just scroll down 10 pixels at a time I can just run the same command 10 or more times to get to the right destination, just trying to get it done on my own.
Just FYI for the swipe code I was running the following code line let me know if I did it correctly or not:
‘Swipe Vertical from top to bottom’
Mobile.swipe(360, 204, 360, 816)
height as : 1289 and the width is : 720
Following the methods below:
startX = 360 //screen width divided by 2

startY = 204//screen height multiplied by 0.2

endX = 360//screen width divided by 2

endY = 816 //screen height multiplied by 0.8

Hi @rkarim,

If you want to go with the solution I suggested for setting the resource-id, I would have your developer do it on all the blue headings, not the drop-downs themselves. I think it would be less complicated to scroll through the headings than rely on the drop-down lists. Unfortunately, just changing the resource-id in the Katalon Test Object repository won’t work - it has to be done in the app, too.

Alternatively, if you want to scroll the screen a few pixels at a time, you can try this:

Add these imports to the top of your test:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
import io.appium.java_client.AppiumDriver as AppiumDriver
import io.appium.java_client.TouchAction

and add this code for scrolling:

int startX = 360
int startY = 816
int endX = 360
int endY = 204 // scrolling down, so the ending point is ABOVE the starting point
TestObject categoryDropDown = findTestObject('Mnu_Configuration_Displacement')
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
while (	Mobile.waitForElementPresent(categoryDropDown, 2, FailureHandling.CONTINUE_ON_FAILURE) == false) {
	TouchAction ta = new TouchAction(driver);
	ta.press(startX, startY).waitAction().moveTo(endX, endY).release().perform();
}

– Chris

Hey Chris,
You are so freaking awesome I got my screen to scroll down for the first time in 3 days, however I am having an issue where the screen is now going on infinite scroll toward down direction and I tried playing around with it and couldn’t figure out how to stop this script from scrolling. To be honest with you if I can stop the script from scrolling after the first scroll that would be perfect because it is scrolling in a perfect coordination. If you can help me with this last bit of code that would be greatly appreciated.
NOTE: I had to make a little change with the code you provided me with since the findTestObject for the categoryDropDown needed the whole path for Mnu_Configuration_displacement’) hopefully I did it right because it didn’t recognize it before the step failed so I coded that line with
TestObject categoryDropDown = findTestObject (‘Object Repository/Manheim APK/Dashboard/Work_Order_Entry/Configuration Tab/Mnu_Configuration_Displacement’)

I have also attached the screenshot of the issue I’m facing. Thanks a lot Chris

Hi @rkarim,

Glad to hear it’s almost working! Setting the whole path for findObject sounds right. As for fixing the scrolling, I think we can do one of two things:

1. Just scroll once
If you know you’ll only have to scroll once, then you can remove some of the looping logic and only have:

int startX = 360
int startY = 816
int endX = 360
int endY = 204 // scrolling down, so the ending point is ABOVE the starting point

AppiumDriver<?> driver = MobileDriverFactory.getDriver()
TouchAction ta = new TouchAction(driver);
ta.press(startX, startY).waitAction().moveTo(endX, endY).release().perform();

2. Keeping the multi-scrolling logic,
Just in case your screen content gets longer and you need multiple scroll actions. I think the original code I gave was FailureHandling.OPTIONAL, which might not ever finish the scroll, like you saw. I think you can make a small change to FailureHandling.CONTINUE_ON_FAILURE to get it to stop scrolling as soon as it finds your desired element:

int startX = 360
int startY = 816
int endX = 360
int endY = 204 // scrolling down, so the ending point is ABOVE the starting point
TestObject categoryDropDown = findTestObject('Object Repository/Manheim APK/Dashboard/Work_Order_Entry/Configuration Tab/Mnu_Configuration_Displacement')
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
while (	Mobile.waitForElementPresent(categoryDropDown, 2, FailureHandling.CONTINUE_ON_FAILURE) == false) {
	TouchAction ta = new TouchAction(driver);
	ta.press(startX, startY).waitAction().moveTo(endX, endY).release().perform();
}

I think we’re almost there!

– Chris

Hey Chris,
I’m using your first option since on the second option the element is NOT recognized for some reason. But I would prefer the second option if I can get it to work, thanks for working with me every step of the way for this issue. So I’m running the first option I’ve noticed after using your code I added few more steps within the test cases to run some actions on the new screen but I’m running into these errors. And also can you please let me know how I can use the same code again to scroll down 1, 2 or 3 more time? thanks.

Hi @rkarim,

The error you’re seeing is that you already defined variables with names startX, startY, etc, so you don’t need to repeat those lines again. - just set them once and you can reference them again further down in your test file.

If you want to scroll down some more in the same test, you can just use this line each time:

ta.press(startX, startY).waitAction().moveTo(endX, endY).release().perform();

– Chris

1 Like

Hi Chris,
I haven’t repeated the defined startX, StartY again, the definition you are seeing within the screen is the first time it is coded but when I try to run it it fails on the very first step and I can’t seem to figure what is going wrong with this set of code.

Never mind I did repeat the steps again I haven’t noticed that, thanks for in depth knowledge on this issue, I’m sure I’ll get back to you regarding other matters but you have been nothing but outstanding, thank you so much it really means a lot.

1 Like

Hi Chris,
I’m running into the swipe down action again with my script would you be able to help me through this again, this script worked couple of months ago but as I came back to it now its failing here is my code:

Just to give you a overview of exactly what I’m running right now:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import javax.swing.TimerQueue.DelayedTimer as DelayedTimer
import org.junit.After as After
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.sun.media.sound.SoftReverb.Delay as Delay
import internal.GlobalVariable as GlobalVariable
import io.appium.java_client.TouchAction as TouchAction
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
import io.appium.java_client.android.AndroidDriver as AndroidDriver
import io.appium.java_client.AppiumDriver as AppiumDriver
//import io.appium.java_client.android.AndroidKeyCode as AndroidKeyCode
import org.openqa.selenium.Keys as Keys

int startX = 360
int startY = 816
int endX = 360
int endY = 204 // scrolling down, so the ending point is ABOVE the starting point

AppiumDriver<?>driver = MobileDriverFactory.getDriver()
TouchAction ta = new TouchAction(driver)
ta.press(startX, startY).waitAction().moveTo(endX, endY).release().perform()

AND HERE IS THE ERROR I’M GETTING:

08-20-2019 03:56:54 PM Test Cases/Creating L1 Record/Configuration Tab

Elapsed time: 54.665s

Test Cases/Creating L1 Record/Configuration Tab FAILED.

Reason:

groovy.lang.MissingMethodException: No signature of method: io.appium.java_client.TouchAction.press() is applicable for argument types: (java.lang.Integer, java.lang.Integer) values: [360, 816]

Possible solutions: press(io.appium.java_client.touch.offset.PointOption), grep(), every(), perform(), print(java.io.PrintWriter), print(java.lang.Object)

at Configuration Tab.run(Configuration Tab:107)
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:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1566331012466.run(TempTestCase1566331012466.groovy:21)

Hi @rkarim,

I think the error you’re seeing is from a new version of an underlying Appium library, java_client which dropped support for the code you were using before (the same thing happened to me).

You’ll need to add this import to the top of your test:

import io.appium.java_client.touch.offset.PointOption

And then switch out the line of your code that uses ta.press with the following:

ta.longPress(PointOption.point(startX, startY)).moveTo(PointOption.point(endX, endY)).release().perform()

Hope this helps,

Chris

1 Like

Hi @Chris_Trevarthen,
thanks for prompt reply, I just tried out that code you just suggested and instead of just swiping down it it tapping on a menu 3 times here is the code that I’m using now:
int startX = 360

int startY = 816

int endX = 360

int endY = 204 // scrolling down, so the ending point is ABOVE the starting point

AppiumDriver<?> driver = MobileDriverFactory.getDriver()

TouchAction ta = new TouchAction(driver)

ta.longPress(PointOption.point(startX, startY)).moveTo(PointOption.point(endX, endY)).release().perform()

ta.longPress(PointOption.point(startX, startY)).moveTo(PointOption.point(endX, endY)).release().perform()

ta.longPress(PointOption.point(startX, startY)).moveTo(PointOption.point(endX, endY)).release().perform()

BTW I have used the import at the top of the script:
import io.appium.java_client.touch.offset.PointOption

Hi @rkarim,

Just to clarify, are you trying to scroll the list/screen 3 times? If so, you might want to try adding MobileBuiltInKeywords.delay(5) between the scroll steps to try to give it some time to do the scrolling.

– Chris

Hey Chris,
so my idea was to first swipe once but the steps passed without any swipe action so I thought if I use it three times I could pin point exactly what this code is doing. I’m really nervous about demoing this tomorrow