<s> import copy <EOL> from appium . webdriver . mobilecommand import MobileCommand as Command <EOL> class TouchAction ( object ) : <EOL> def __init__ ( self , driver = None ) : <EOL> self . _driver = driver <EOL> self . _actions = [ ] <EOL> def tap ( self , element = None , x = None , y = None , count = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> opts = self . _get_opts ( element , x , y ) <EOL> opts [ '<STR_LIT:count>' ] = count <EOL> self . _add_action ( '<STR_LIT>' , opts ) <EOL> return self <EOL> def press ( self , el = None , x = None , y = None ) : <EOL> """<STR_LIT>""" <EOL> self . _add_action ( '<STR_LIT>' , self . _get_opts ( el , x , y ) ) <EOL> return self <EOL> def long_press ( self , el = None , x = None , y = None , duration = <NUM_LIT:1000> ) : <EOL> """<STR_LIT>""" <EOL> self . _add_action ( '<STR_LIT>' , self . _get_opts ( el , x , y , duration ) ) <EOL> return self <EOL> def wait ( self , ms = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if ms is None : <EOL> ms = <NUM_LIT:0> <EOL> opts = { '<STR_LIT>' : ms } <EOL> self . _add_action ( '<STR_LIT>' , opts ) <EOL> return self <EOL> def move_to ( self , el = None , x = None , y = None ) : <EOL> """<STR_LIT>""" <EOL> self . _add_action ( '<STR_LIT>' , self . _get_opts ( el , x , y ) ) <EOL> return self <EOL> def release ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _add_action ( '<STR_LIT>' , { } ) <EOL> return self <EOL> def perform ( self ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : self . _actions } <EOL> self . _driver . execute ( Command . TOUCH_ACTION , params ) <EOL> self . _actions = [ ] <EOL> return self <EOL> @ property <EOL> def json_wire_gestures ( self ) : <EOL> gestures = [ ] <EOL> for action in self . _actions : <EOL> gestures . append ( copy . deepcopy ( action ) ) <EOL> return gestures <EOL> def _add_action ( self , action , options ) : <EOL> gesture = { <EOL> '<STR_LIT:action>' : action , <EOL> '<STR_LIT>' : options , <EOL> } <EOL> self . _actions . append ( gesture ) <EOL> def _get_opts ( self , element , x , y , duration = None ) : <EOL> opts = { } <EOL> if element is not None : <EOL> opts [ '<STR_LIT>' ] = element . id <EOL> if x is None or y is None : <EOL> x , y = None , None <EOL> opts [ '<STR_LIT:x>' ] = x <EOL> opts [ '<STR_LIT:y>' ] = y <EOL> if duration is not None : <EOL> opts [ '<STR_LIT>' ] = duration <EOL> return opts </s>
