Last active
August 29, 2015 14:06
-
-
Save TeresaP/44e405407141e3b7af4f to your computer and use it in GitHub Desktop.
swipe_screen
This file contains 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
# Swipes on the screen with given direction | |
# @param [String] query_string (Optional) The custom query for the object to swipe on | |
# @param [Symbol] direction - direction to swipe :left, :right, :up, :down | |
def self.swipe_screen(direction, query_string='view') | |
view = query(query_string).first | |
centerY = view['rect']['center_y'] | |
centerX = view['rect']['center_x'] | |
height = view['rect']['height'] | |
# Different deltas for different orientations | |
if landscape? | |
# NOTE: we may need to change this offsetX like we did below to avoid the AppleUI | |
offsetX = centerX - 1 | |
offsetY = 0 | |
height = view['rect']['width'] | |
else | |
offsetX = 0 | |
offsetY = centerY - 1 | |
# height is -20 to avoid Apple UI that gets pulled out when we swipe from off-screen | |
height = height - 20 | |
end | |
# special casing for up/down page swiping. needs a swipe delta for device | |
case direction.to_sym | |
when :up | |
swipe(:up, {:offset => {:x => centerX, :y => height}, :'swipe-delta' => {:vertical => {:dx=> 0, :dy => height}}}) | |
when :down | |
swipe(:down, {:offset => {:x => centerX, :y => 0}, :'swipe-delta' => {:vertical => {:dx=> 0, :dy => height}}}) | |
else | |
swipe(direction, {:query => query_string, :offset => {:x => offsetX, :y => offsetY}}) | |
end | |
sleep(STEP_PAUSE) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jmoody