I am writing examples of swipe and drag on mobile devices with calabash today. Some methods that you can use to test, these drags have the same action as the swipe. (If for some reason the swipe don’t work)
ANDROID:
def swipe_page_to_left performAction('swipe', 'left') end
def swipe_page_to_right performAction('swipe', 'right') end
def scroll_to_right performAction('drag', 90, 0, 50, 50, 50) end
def scroll_to_left performAction('drag', 0, 90, 50, 50, 50) end
def scroll_to_up performAction('drag', 88, 80, 90, 90, 5) end
def scroll_to_down performAction('drag', 70, 10, 80, 0, 3) end
IOS
Change to down, left or right:
swipe(:up)
If you have some question or suggest just write below !
Full Stack SDET with +16 years Experience in QA, +14 years Experience in Test Automation and +8 years in Leadership, Delivering and Releasing Softwares in different platforms (Mobile, Desktop, Web)
Became a STEM Ambassador and a STEM Women Member in 2020 making an impact and bringing more people to the STEM area. Contribute to TestProject and instructor of Test Automation University.
View all posts by Rafaela Azevedo
Published
9 thoughts on “Swipe and Drag – Calabash iOS and Android”
how would you scroll over a specific element for android?
I used to use drag. But you need to know the position on the screen to use the same x and y.
Example:
performAction(‘drag’, 90, 0, 50, 50, 50)
or
performAction(‘swipe’, ‘left’)
For IOS you can use:
scroll(“element_query“, :right)
or
swipe :left, {:’swipe-delta’ => {:horizontal => {:dx => 375, :dy => 0}}}
and change the x, y and the direction that you want swipe.
how would you scroll over a specific element for android?
Hi Aman,
I used to use drag. But you need to know the position on the screen to use the same x and y.
Example:
performAction(‘drag’, 90, 0, 50, 50, 50)
or
performAction(‘swipe’, ‘left’)
For IOS you can use:
scroll(“element_query“, :right)
or
swipe :left, {:’swipe-delta’ => {:horizontal => {:dx => 375, :dy => 0}}}
and change the x, y and the direction that you want swipe.
Let me know if it worked.
Scrolling down with drag isn’t working for me. I need to pull down the application screen by more than half length of the device.
Hi Kapil, did you try drag with a huge percentage of the page ? I know that swipe it won’t work for you either, should work with drag only.
Hi Rafaela, do you know the syntax to select a strong swipe? Sometimes the default swipe is not enough.
Thanks
for iOS
Already found the way. I leave an example:
swipe(:left,:query => “SPWebView”,:force => :strong)
Thanks for your tips!
Hi Rodrigo thanks for posting the answer once you found it ! Really appreciated that 🙂 Thank you !