-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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