Skip to content

Instantly share code, notes, and snippets.

@Ebrahim-Mostafa
Forked from Alona-T/swipe.rb
Created June 2, 2020 22:04
Show Gist options
  • Save Ebrahim-Mostafa/5243f47e15ac11337436a0d41f9b4435 to your computer and use it in GitHub Desktop.
Save Ebrahim-Mostafa/5243f47e15ac11337436a0d41f9b4435 to your computer and use it in GitHub Desktop.
Swipe methods that can be used regardless mobile device model and screen size. Using element's coordinates in the method helps to archive it
#swipe to top
def swipe_to_top(element, duration)
elem = element
x = elem.location.x
y = elem.location.y
Appium::TouchAction.swipe(start_x: x, start_y: y, duration: duration)
end
#when you need to just horizontally swipe carousel of elements or similar (when 2 elements are present)
def swipe_horizontally(element_s, element_e, duration)
element_start = element_s
x_start = element_start.location.x
y_start = element_start.location.y
element_end = element_e
x_end = element_end.location.x
y_end = element_end.location.y
Appium::TouchAction.swipe(start_x: x_end, start_y: y_end, end_x: x_start, end_y: y_start, duration: duration)
end
#when there is only 1 element and you need to press it and swipe to right
def swipe_horizontally_new(element_s, width)
dimension = element_s.size
x_start = element_s.location.x
y_start = element_s.location.y
element_end = dimension.width * width
Appium::TouchAction.new.press(x: x_start, y: y_start).wait(2000).move_to(x: element_end, y: y_start).release.perform
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment