How to drag or swipe a button on a screen using calabash-android

3,209 views
Skip to first unread message

Preeti Jindal

unread,
Aug 19, 2014, 9:20:59 AM8/19/14
to calabash...@googlegroups.com

I have to swipe a button on screen. That is dragging a button from one position to another (Swipe buttons as in iPhone)

1. I am using calabash-android version 0.4.21
2. I have used following code to swipe a button:

performAction('drag_coordinates',30,90,80,80,10)                   //  numbers reflect the percentage and not exact coordinates

I have also tried exact coordinates of the button on screen:

performAction('drag_coordinates',300,450,1035,1035,10)       //  numbers reflect the exact coordinates

3.  performAction('swipe', 'right') 

This would not work as t will swipe the entire screen and I have to swipe a particular button.

Can anybody help me out because I am not finding anything on this online.
I really need help here!!!!

Thanks in advance.





Sanjay Kumar

unread,
Aug 19, 2014, 11:44:10 AM8/19/14
to calabash...@googlegroups.com
Try this : perform_action('drag', from_x, to_x, from_y, to_y, steps)


--
You received this message because you are subscribed to the Google Groups "calabash-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email to calabash-andro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tobias....@xamarin.com

unread,
Aug 27, 2014, 11:33:33 AM8/27/14
to calabash...@googlegroups.com
With the release of generic multi touch gestures (calabash-android 0.5.2), you could do something like this:

# At the top of your features file
include
Calabash::Android::Gestures
#...


Given(/^.....$/) do
  gesture
= Gesture.tap(time: 0.5, release: false).merge(Gesture.tap(wait: 0.5))
  gesture
.gestures.first.touches.first.query_string = "* id:'first_element*"
  gesture
.gestures.first.touches[1].query_string = "* id:'second_element'"
  execute_gesture
(gesture)
end

If you want to swipe from a certain point to a certain point in the same element you can simple do

pan("* id:'element'", :right)

or set your own coordinates using

pan("button", :right, from: {x: 0, y: 50}, to: {x: 100, y:50}) # Swipe from absolute center left to absolute center right

Tejasvi Manmatha

unread,
Jan 22, 2015, 9:20:04 AM1/22/15
to calabash...@googlegroups.com
Thanks so much pan functionality was very useful

Praveen Reddy

unread,
Jan 22, 2015, 10:18:38 AM1/22/15
to calabash...@googlegroups.com

Hi,

How can you swipe a button? Find out the view and the class of that object using calabash-android console or uiautomatorviewer, then you can perform the gesture.

Thanks,
PV

Reply all
Reply to author
Forward
0 new messages