Skip to content

Instantly share code, notes, and snippets.

@TeresaP
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeresaP/44e405407141e3b7af4f to your computer and use it in GitHub Desktop.
Save TeresaP/44e405407141e3b7af4f to your computer and use it in GitHub Desktop.
swipe_screen
# 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
@TeresaP
Copy link
Author

TeresaP commented Sep 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment