Appium : Mobile gesture longpress

 


Mobile applications come with different gestures such as click,drag,swipe, and log press and pinch. In this blog post I will discuss a small piece of code I learned while referring to a youtube video and the document from appium website. 

In this example the user first clicks on a menu option called 'Views' which will then load a second sub menu. From the second sub menu the user clicks on a menu item named 'Expandable List' which will load a third sub menu named 'Custom Adaptor'. Once the third sub menu is clicked, the app will show a menu item names 'People Names' when when we hold and press for some time opens a popup .

To use the long press we need to use the execute script method and then we pass in 2 arguments, the first argument is the action( the event) to be performed which is a longClickGesture and as the second argument we use ImmutableMap and pass a key value pair to indicate which element to be used for the long Click. Finally we give a timeout of X number to wait until the 'Sample menu' is popped up for the long click gesture.

The getId will retrieve the element id of the web element with the xpath where the longClick is to be performed

((JavascriptExecutor) driver).executeScript("mobile: longClickGesture", ImmutableMap.of("elementId",((RemoteWebElement)peopleNamesElement).getId(),"duration",5000));

Once the long click happens we then use TestNG assertions and assert for the text of the popped up menu when long click is performed.

       Note: The above code was written referring to the reference [1]

References:

[1]https://www.youtube.com/watch?v=vV1RZd9Tuug&list=PLN9RL2PyZc19aq95VjhXzeUmuU4-6N6Qf&index=14

[2]https://appium.io/docs/en/writing-running-appium/android/android-mobile-gestures/


Comments