How to use touch_button method in robotframework-androidlibrary

Best Python code snippet using robotframework-androidlibrary_python

start.py

Source:start.py Github

copy

Full Screen

...64 return touch_loc, max_loc, w, h65# In[13]:66# touch the template on the image with offsets67# 模拟点击指定的按钮,如有必要,可通过参数三、四指定偏移68def touch_button(template, img, x_offset=0, y_offset=0):69 touch_loc, _, w, h = get_button_location(template, img)70 t_x, t_y = ((touch_loc[0] + w / 2 + x_offset) / 2, (touch_loc[1] + h / 2 + y_offset) / 2)71 print("Touching {0}, {1}".format(t_x, t_y))72 s.tap(t_x, t_y)73# In[14]:74def recognize_and_process_page(specs): # in the form of image_name => (template, action)75 img = take_screenshot()76 print("===========================")77 # pick the highest applicable key78 # ss = max(specs, key=lambda s: get_similarity(s.imageTemplate, img, s))79 ss = None80 for spec in specs:81 match = get_similarity(spec.imageTemplate, img, spec) == 182 if match:83 ss = spec84 break85 if ss is None:86 print('unable recognize stage, wait for next time.')87 return88 # perform second filtering to filter by the actionButtonTemplate89 spec_name = ss.image_name90 filtered = [s for s in specs if s.image_name == ss.image_name]91 print("= = = = = = = = = = = = = =")92 # ss = max(filtered, key=lambda s: get_similarity(s.actionTemplate, img, s))93 ss = None94 for spec in filtered:95 match = get_similarity(spec.actionTemplate, img, spec) == 196 if match:97 ss = spec98 break99 if ss is None:100 print('stage', spec_name, 'unable recognize action feature, program would not tap any position.')101 else:102 print("Picked : " + ss.image_name + " ==> " + ss.action_button_name)103 ss.action(ss.actionTemplate, img)104# In[15]:105class Spec:106 # image_name : the image to scan to identify the scene107 # action : the action to execute upon match with image_name, receives (template, img), where108 # template is the cv2 rep of the action_button_name below, and the image is the 109 # current screen shot110 # action_button_name: sometimes we want different button to be clicked while not checking this button111 # the default value is the same as image_name112 def __init__(self, image_name, action, action_button_name=None):113 if action_button_name is None:114 action_button_name = image_name115 self.image_name = image_name116 self.action = action # action must receive (template, img) as the input variable117 self.action_button_name = action_button_name118 # load resources119 self.imageTemplate = cv2.imread(deviceVersion + image_name, 0)120 if self.imageTemplate is None:121 print("Error : ImageName is wrong")122 self.actionTemplate = cv2.imread(deviceVersion + action_button_name, 0)123 if self.actionTemplate is None:124 print("Error : ActionButtonName is wrong")125 print("\nProcessing Spec: \nImageName: {0}\nActionButtonName : {1}".format(126 image_name, action_button_name))127 # _ = cv2.imread(deviceVersion + image_name, 0)128 # _ = cv2.imread(deviceVersion + action_button_name, 0)129# In[16]:130def login_screen_spec():131 def f(template, img):132 touch_button(template, img, 200)133 return Spec("login_server_selection.png", f)134# In[17]:135def close_event_screen_spec():136 return Spec("event_overview.png", touch_button, "event_overview_close.png")137# In[18]:138def close_announcement_screen_spec():139 return Spec("system_announcement.png", touch_button, "cross_close_button.png")140# In[19]:141def start_battle_from_home_screen_spec():142 return Spec("start_battle_home_screen.png", touch_button)143# In[20]:144def choose_battle_level_spec():145 return Spec("battle_" + targetLevel + '.png', touch_button)146# In[21]:147def choose_battle_level_confirm_spec():148 return Spec("choose_level_go_now_button.png", touch_button)149# In[24]:150def map_move_spec_question_mark():151 def f(template, img):152 touch_button(template, img, 0, 50)153 return Spec("explore_map_question_mark.png", f, "explore_map_question_mark.png")154# In[25]:155def map_move_spec_boss():156 return Spec("boss_icon_detection.png", touch_button, "boss_icon_detection.png")157# In[26]:158def map_move_spec_ship1():159 return Spec("map_ship_type_1.png", touch_button)160def map_move_spec_ship2():161 return Spec("map_ship_type_2.png", touch_button)162def map_move_spec_ship3():163 return Spec("map_ship_type_3.png", touch_button)164def map_move_spec_ship4():165 return Spec("map_ship_type_4.png", touch_button)166# In[29]:167def map_move_ambush_encountered():168 return Spec("ambush_encountered_detection.png", touch_button, "map_move_evade_ambush.png")169# In[30]:170def map_battle_preview_spec():171 return Spec("battle_prepare.png", touch_button, "battle_preview_start_button.png")172# In[31]:173def battle_start_auto_fight_spec():174 return Spec("not_auto_fighting_detection.png", touch_button)175# In[32]:176def battle_start_auto_fight_confirmation_spec():177 return Spec("auto_battle_warning_detection.png", touch_button, "auto_battle_confirm_button.png")178# In[33]:179def battle_in_good_state():180 def f(template, img):181 print('waiting for battle to finish.')182 pass183 return Spec("stop_auto_battle_detection.png", f)184# In[34]:185def battle_post_continue_spec():186 return Spec("battle_post_view_s_level.png", touch_button)187def battle_post_items_drop_spec():188 return Spec("battle_post_view_get_items_detection.png", touch_button)189def battle_post_exp_spec():190 return Spec("battle_post_confirm_detection.png", touch_button, "battle_post_confirm_button.png")191# In[37]:192def battle_post_view_new_character_confirmation():193 def f(template, img):194 touch_button(template, img, 0, 200)195 return Spec("battle_post_new_character_detection.png", f)196# In[38]:197def battle_post_view_new_character_lock_confirmation():198 return Spec("whether_locking_this_ship_detection.png", touch_button, "ship_lock_yes_button.png")199# In[39]:200def dismiss_info_box_spec():201 return Spec("info_box_detection.png", touch_button, "cross_close_button.png")202# In[41]:203specs = [204 login_screen_spec, # 登陆界面205 close_announcement_screen_spec, # 关闭公告界面206 close_event_screen_spec, # 关闭活动总览界面207 start_battle_from_home_screen_spec, # 从主界面进入战斗界面208 choose_battle_level_spec, # 选择战斗关卡(请在顶部配置变量targetLevel,如3_4)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...46 connect()47@left_button.press48def on_left():49 connect()50@touch_button('Off', xy=(55,75), color='blue')51def on_touch():52 mqttc.publish('heating/radiators/target', payload='10.0', qos=1, retain=True)53@touch_button('On', xy=(160,75), color='blue')54def on_touch():55 mqttc.publish('heating/radiators/target', payload='21.0', qos=1, retain=True)56@touch_button('Boost', xy=(265,75), color='red')57def on_touch():58 mqttc.publish('heating/radiators/target', payload='22.5', qos=1, retain=True)59@touch_button('Off', xy=(55,190), color='blue')60def on_touch():61 mqttc.publish('heating/underfloor/target', payload='10.0', qos=1, retain=True)62@touch_button('On', xy=(160,190), color='blue')63def on_touch():64 mqttc.publish('heating/underfloor/target', payload='21.0', qos=1, retain=True)65@touch_button('Boost', xy=(265,190), color='red')66def on_touch():67 mqttc.publish('heating/underfloor/target', payload='22.5', qos=1, retain=True)68@every(seconds=1.0/15)69def mqtt_loop():70 mqttc.loop()71@every(seconds=1.0/30)72def loop():73 screen.fill(74 color=(80,80,80)75 )76 ## Status at top bar77 screen.rectangle(78 xy=(0,0), size=(320,25), color='black', align='topleft'79 )...

Full Screen

Full Screen

TouchEncoderElement.py

Source:TouchEncoderElement.py Github

copy

Full Screen

...16 self._trigger_undo_step = False17 self._undo_step_open = False18 self._undo_step_handler = undo_step_handler19 self._delete_handler = delete_handler20 self.set_touch_button(touch_button)21 self.set_observer(None)22 def is_pressed(self):23 return self.touch_button and self.touch_button.is_pressed()24 def set_touch_button(self, touch_button):25 self.touch_button = touch_button26 self._on_touch_button.subject = touch_button27 def set_observer(self, observer):28 if observer is None:29 observer = TouchEncoderObserver()30 self._observer = observer31 @subject_slot('value')32 def _on_touch_button(self, value):33 self._trigger_undo_step = value34 if value:35 param = self.mapped_parameter()36 if self._delete_handler and self._delete_handler.is_deleting and param:37 self._delete_handler.delete_clip_envelope(param)38 else:39 self.begin_gesture()40 self._begin_undo_step()41 self._observer.on_encoder_touch(self)42 self.notify_touch_value(value)43 else:44 self._end_undo_step()45 self._observer.on_encoder_touch(self)46 self.notify_touch_value(value)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-androidlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful