Best Python code snippet using AutoItDriverServer_python
driver_macaca.py
Source:driver_macaca.py
...101 :param y:102 :return:103 """104 try:105 width = Var.instance.get_window_size()['width']106 height = Var.instance.get_window_size()['height']107 if x <= 1.0:108 x = x * width109 if y <= 1.0:110 y = y * height111 Var.instance.touch('tap', {'x': x, 'y': y})112 except Exception as e:113 raise e114115 @staticmethod116 def double_tap(x, y):117 """118 :param x:119 :param y:120 :return:121 """122 try:123 width = Var.instance.get_window_size()['width']124 height = Var.instance.get_window_size()['height']125 if x <= 1.0:126 x = x * width127 if y <= 1.0:128 y = y * height129 Var.instance.touch('doubleTap', {'x': x, 'y': y})130 except Exception as e:131 raise e132133 @staticmethod134 def press(x, y, duration=2):135 """136 :param x:137 :param y:138 :param duration:139 :return:140 """141 try:142 width = Var.instance.get_window_size()['width']143 height = Var.instance.get_window_size()['height']144 if x <= 1.0:145 x = x * width146 if y <= 1.0:147 y = y * height148 Var.instance.touch('press', {'x': x, 'y': y, 'duration': duration})149 except Exception as e:150 raise e151152 @staticmethod153 def press(element, duration=2):154 """155 :param element:156 :param duration:157 :return:158 """159 try:160 element.touch('press', {'duration': duration})161 except Exception as e:162 raise e163164 @staticmethod165 def swipe_up(duration=2):166 """167 :param duration:168 :return:169 """170 try:171 width = Var.instance.get_window_size()['width']172 height = Var.instance.get_window_size()['height']173 AndroidDriver.swipe(width / 2, height * 0.65, width / 2, height / 4, duration)174 except Exception as e:175 raise e176177 @staticmethod178 def swipe_down(duration=2):179 """180 :param duration:181 :return:182 """183 try:184 width = Var.instance.get_window_size()['width']185 height = Var.instance.get_window_size()['height']186 AndroidDriver.swipe(width / 2, height / 4, width / 2, height * 3 / 4, duration)187 except Exception as e:188 raise e189190 @staticmethod191 def swipe_left(duration=2):192 """193 :param duration:194 :return:195 """196 try:197 width = Var.instance.get_window_size()['width']198 height = Var.instance.get_window_size()['height']199 AndroidDriver.swipe(width * 3 / 4, height / 2, width / 4, height / 2, duration)200 except Exception as e:201 raise e202203 @staticmethod204 def swipe_right(duration=2):205 """206 :param duration:207 :return:208 """209 try:210 width = Var.instance.get_window_size()['width']211 height = Var.instance.get_window_size()['height']212 AndroidDriver.swipe(width / 4, height / 2, width * 3 / 4, height / 2, duration)213 except Exception as e:214 raise e215216 @staticmethod217 def swipe(from_x, from_y, to_x, to_y, duration=2):218 """219 :param from_x:220 :param from_y:221 :param to_x:222 :param to_y:223 :param duration:224 :return:225 """226 try:227 width = Var.instance.get_window_size()['width']228 height = Var.instance.get_window_size()['height']229 if from_x <= 1.0:230 from_x = from_x * width231 if from_y <= 1.0:232 from_y = from_y * height233 if to_x <= 1.0:234 to_x = to_x * width235 if to_y <= 1.0:236 to_y = to_y * height237 AndroidDriver.adb_shell(238 'shell input swipe {} {} {} {} {}'.format(from_x, from_y, to_x, to_y,239 duration * 100))240 except Exception as e:241 raise e242243 @staticmethod244 def input(element, text, clear=True, hide_keyboard=True):245 """246 :param element:247 :param text:248 :param clear:249 :param hide_keyboard:250 :return:251 """252 try:253 # if clear:254 # AndroidDriver.clear()255 # if hide_keyboard:256 # AndroidDriver.hide_keyboard()257 # element.click()258 element.send_keys(text)259 except Exception as e:260 raise e261262 @staticmethod263 def get_text(element):264 """265 :param element:266 :return:267 """268 try:269 text = element.text270 return text271 except Exception as e:272 raise e273274 @staticmethod275 def clear():276 """277 :return:278 """279 try:280 Var.instance.clear()281 except:282 traceback.print_exc()283284 @staticmethod285 def hide_keyboard():286 """287 :return:288 """289 try:290 AndroidDriver.adb_shell('shell input keyevent 111')291 except:292 traceback.print_exc()293294 @staticmethod295 def wait_for_elements_by_id(id, timeout=10, interval=1):296 """297 :param id:298 :return:299 """300 try:301 elements = Var.instance.wait_for_elements_by_id(id, int(timeout) * 1000,302 int(interval) * 1000)303 return elements304 except:305 return None306307 @staticmethod308 def wait_for_elements_by_name(name, timeout=10, interval=1):309 """310 :param name:311 :return:me312 """313 try:314 elements = Var.instance.wait_for_elements_by_name(name, int(timeout) * 1000,315 int(interval) * 1000)316 return elements317 except:318 return None319320 @staticmethod321 def wait_for_elements_by_xpath(xpath, timeout=10, interval=1):322 """323 :param xpath:324 :return:325 """326 try:327 elements = Var.instance.wait_for_elements_by_xpath(xpath, int(timeout) * 1000,328 int(interval) * 1000)329 return elements330 except:331 return None332333 @staticmethod334 def wait_for_elements_by_classname(classname, timeout=10, interval=1):335 """336 :param classname:337 :return:338 """339 try:340 elements = Var.instance.wait_for_elements_by_class_name(classname, int(timeout) * 1000,341 int(interval) * 1000)342 return elements343 except:344 return None345346347class iOSDriver(object):348349 @staticmethod350 def install_app(app_path):351 """352 install app353 :param app_path:354 :return:355 """356 try:357 os.system('ideviceinstaller -u {} -i {}'.format(Var.desired_caps.udid, app_path))358 except Exception as e:359 raise e360361 @staticmethod362 def uninstall_app(package_info):363 """364 uninstall app365 :param package_info: Android(package) or iOS(bundleId)366 :return:367 """368 try:369 os.system('ideviceinstaller -u {} -U {}'.format(Var.desired_caps.udid, package_info))370 except Exception as e:371 raise e372373 @staticmethod374 def launch_app(package_info):375 """376 launch app377 :param package_info: Android(package/activity) or iOS(bundleId)378 :return:379 """380 try:381 pass # todo å¾
å®ç°382 except Exception as e:383 raise e384385 @staticmethod386 def close_app(package_info):387 """388 close app389 :param package_info: Android(package) or iOS(bundleId)390 :return:391 """392 try:393 pass # todo å¾
å®ç°394 except Exception as e:395 raise e396397 @staticmethod398 def tap(x, y):399 """400 :param x:401 :param y:402 :return:403 """404 try:405 width = Var.instance.get_window_size()['width']406 height = Var.instance.get_window_size()['height']407 if x <= 1.0:408 x = x * width409 if y <= 1.0:410 y = y * height411 Var.instance.touch('tap', {'x': x, 'y': y})412 except Exception as e:413 raise e414415 @staticmethod416 def double_tap(x, y):417 """418 :param x:419 :param y:420 :return:421 """422 try:423 width = Var.instance.get_window_size()['width']424 height = Var.instance.get_window_size()['height']425 if x <= 1.0:426 x = x * width427 if y <= 1.0:428 y = y * height429 Var.instance.touch('doubleTap', {'x': x, 'y': y})430 except Exception as e:431 raise e432433 @staticmethod434 def press(x, y, duration=2):435 """436 :param x:437 :param y:438 :param duration:439 :return:440 """441 try:442 width = Var.instance.get_window_size()['width']443 height = Var.instance.get_window_size()['height']444 if x <= 1.0:445 x = x * width446 if y <= 1.0:447 y = y * height448 Var.instance.touch('press', {'x': x, 'y': y, 'duration': duration})449 except Exception as e:450 raise e451452 @staticmethod453 def press(element, duration=2):454 """455 :param element:456 :param duration:457 :return:458 """459 try:460 element.touch('press', {'duration': duration})461 except Exception as e:462 raise e463464 @staticmethod465 def swipe_up(duration=0):466 """467 :param duration:468 :return:469 """470 try:471 width = Var.instance.get_window_size()['width']472 height = Var.instance.get_window_size()['height']473 iOSDriver.swipe(width / 2, height * 0.65, width / 2, height / 4, duration)474 except Exception as e:475 raise e476477 @staticmethod478 def swipe_down(duration=2):479 """480 :param duration:481 :return:482 """483 try:484 width = Var.instance.get_window_size()['width']485 height = Var.instance.get_window_size()['height']486 iOSDriver.swipe(width / 2, height / 4, width / 2, height * 3 / 4, duration)487 except Exception as e:488 raise e489490 @staticmethod491 def swipe_left(duration=2):492 """493 :param duration:494 :return:495 """496 try:497 width = Var.instance.get_window_size()['width']498 height = Var.instance.get_window_size()['height']499 iOSDriver.swipe(width * 3 / 4, height / 2, width / 4, height / 2, duration)500 except Exception as e:501 raise e502503 @staticmethod504 def swipe_right(duration=2):505 """506 :param duration:507 :return:508 """509 try:510 width = Var.instance.get_window_size()['width']511 height = Var.instance.get_window_size()['height']512 iOSDriver.swipe(width / 4, height / 2, width * 3 / 4, height / 2, duration)513 except Exception as e:514 raise e515516 @staticmethod517 def swipe(from_x, from_y, to_x, to_y, duration=2):518 """519 :param from_x:520 :param from_y:521 :param to_x:522 :param to_y:523 :param duration:524 :return:525 """526 try:527 width = Var.instance.get_window_size()['width']528 height = Var.instance.get_window_size()['height']529 if from_x <= 1.0:530 from_x = from_x * width531 if from_y <= 1.0:532 from_y = from_y * height533 if to_x <= 1.0:534 to_x = to_x * width535 if to_y <= 1.0:536 to_y = to_y * height537 Var.instance.touch('drag', {'fromX': from_x, 'fromY': from_y, 'toX': to_x, 'toY': to_y,538 'duration': duration})539 except Exception as e:540 raise e541542 @staticmethod
...
client.py
Source:client.py
...53 win.fill((0,0,0))#set window colour54 if not (game.are_players_connected()):55 font=pygame.font.SysFont("arial", 90)56 text=font.render("Waiting for Player...", 1, (255,255,255))57 win.blit(text,( (pygame.display.get_window_size()[0])/2- text.get_width()/2, (pygame.display.get_window_size()[1])/2-text.get_height()/2))58 59 else: #if both players connected60 61 62 font=pygame.font.SysFont("arial", 45)63 64 text=font.render("Your Move", 1, (255,255,255))65 win.blit(text, ( ((pygame.display.get_window_size()[0])//3)-(text.get_width()/2) , ((pygame.display.get_window_size()[1])//4)-(text.get_height()/2) ) )66 67 text=font.render("Opponent's Move", 1, (255,255,255))68 win.blit(text, ( (2*((pygame.display.get_window_size()[0])//3))-(text.get_width()/2) , ((pygame.display.get_window_size()[1])//4)-(text.get_height()/2) ) )69 70 717273 player_1_move=game.get_player_move(0)74 player_2_move=game.get_player_move(1)75 if game.have_both_players_been():76 player_1_move_text=font.render(player_1_move, 1, (255,255,255))77 player_2_move_text=font.render(player_2_move, 1, (255,255,255))78 else:79 if player_num==0 and game.p1_went:80 player_1_move_text=font.render(player_1_move, 1, (255,255,255))81 elif game.p1_went: #and player_num==1 is implied82 player_1_move_text=font.render("Selected Move", 1, (255,255,255))83 else: #player_num==1 and not p1_went84 player_1_move_text=font.render("Selecting...", 1, (255,255,255))8586 if player_num==1 and game.p2_went:87 player_2_move_text=font.render(player_2_move, 1, (255,255,255))88 elif game.p2_went: #and player_num==0 is implied89 player_2_move_text=font.render("Selected Move", 1, (255,255,255))90 else: #player_num==0 and not p2_went91 player_2_move_text=font.render("Selecting...", 1, (255,255,255))9293 94 if player_num==0:95 win.blit(player_1_move_text, ( ((pygame.display.get_window_size()[0])//3)-(player_1_move_text.get_width()/2) , (2*((pygame.display.get_window_size()[1])//4))-(player_1_move_text.get_height()/2) ))96 win.blit(player_2_move_text, ( (2*((pygame.display.get_window_size()[0])//3))-(player_2_move_text.get_width()/2) , (2*((pygame.display.get_window_size()[1])//4))-(player_2_move_text.get_height()/2) ) )9798 else:99 win.blit(player_2_move_text, ( ((pygame.display.get_window_size()[0])//3)-(player_2_move_text.get_width()/2) , (2*((pygame.display.get_window_size()[1])//4))-(player_2_move_text.get_height()/2) ))100 win.blit(player_1_move_text, ( (2*((pygame.display.get_window_size()[0])//3))-(player_1_move_text.get_width()/2) , (2*((pygame.display.get_window_size()[1])//4))-(player_1_move_text.get_height()/2) ) )101 102 for button in buttons:103 button.x_coor=((buttons.index(button)+1)*((pygame.display.get_window_size()[0])//4))-(button_width//2)104 button.y_coor=(3*((pygame.display.get_window_size()[1])//4))-(button_height//2)105 button.width=pygame.display.get_window_size()[0]/6106 button.draw_button(win)107 108109 font=pygame.font.SysFont("arial", 15)110 111 win_count_text="Won: "+str(player_wins)+" rounds"112 lost_count_text="Lost: "+str(player_loss)+" rounds"113 114 win_text=font.render(win_count_text, 1, (255,255,255))115 lost_text=font.render(lost_count_text, 1, (255,255,255))116 117 win.blit(win_text, ( (pygame.display.get_window_size()[0])-(win_text.get_width()), ((win_text.get_height() ) ) ) )118 win.blit(lost_text, ( (pygame.display.get_window_size()[0])-(lost_text.get_width()), (2*(lost_text.get_height() ) ) ) ) 119120 pygame.display.update()121122123 124125126button_width=150127button_height=100128129rock_button=Button("Rock", ((pygame.display.get_window_size()[0])//4)-(button_width//2), (3*((pygame.display.get_window_size()[1])//4))-(button_height//2), button_width, button_height, (255,0,0) )130paper_button=Button("Paper", (2*((pygame.display.get_window_size()[0])//4))-(button_width//2), (3*((pygame.display.get_window_size()[1])//4))-(button_height//2), button_width, button_height, (0,255,0) )131scissors_button=Button("Scissors", (3*((pygame.display.get_window_size()[0])//4))-(button_width//2), (3*((pygame.display.get_window_size()[1])//4))-(button_height//2), button_width, button_height, (0,0,255) )132133buttons=[rock_button, paper_button, scissors_button]134135136p2_is_user_button=Button("Play Against User", ((pygame.display.get_window_size()[0])//2)-(button_width//2), ((2*(pygame.display.get_window_size()[1])//5))-(button_height//2), button_width, button_height, (0,255,0) )137p2_is_comp_button=Button("Play Against Computer", ((pygame.display.get_window_size()[0])//2)-(button_width//2), ((3*(pygame.display.get_window_size()[1])//5))-(button_height//2), button_width, button_height, (0,255,0) )138exit_button=Button("Exit", ((pygame.display.get_window_size()[0])//2)-(button_width//2), (4*((pygame.display.get_window_size()[1])/4))-(button_height//5), button_width, button_height, (255,0,0) )139140menu_buttons=(p2_is_user_button, p2_is_comp_button, exit_button)141142143144145def main(buttons):146 run=True147 clock=pygame.time.Clock()148 network=Network()149 player_num=int(network.get_player_num())150 print("You are player", player_num)151 player_wins=0152 player_loss=0153 while run:154155 clock.tick(60)156 try:157 game=network.send_data_to_server("get") #sends request to server to get game object158 except:159 run=False160 print("Could not get game")161 break162 if game.have_both_players_been():163 redraw_win(win, game, player_num, buttons, player_wins, player_loss)164 pygame.time.delay(500)165 try:166 game=network.send_data_to_server("reset")167 except:168 run=False169 print("Could not get game")170 break171 font=pygame.font.SysFont("arial", 90)172 if int(game.winner()) == int(player_num):173 player_wins+=1174 text= font.render("You Won!", 1, (255,255,255) )175 elif int(game.winner()) == -1:176 text= font.render("Tie Game!", 1, (255,255,255) )177 else:178 player_loss+=1179 text= font.render("You Lost!", 1, (255,255,255) )180 181 win.blit(text, ((pygame.display.get_window_size()[0])/2- text.get_width()/2, (3*(pygame.display.get_window_size()[1])/5)-text.get_height()/2))182 pygame.display.update()183 pygame.time.delay(2000)184 185 for event in pygame.event.get():186 if event.type==pygame.QUIT:187 run=False188 pygame.quit()189 if event.type==pygame.MOUSEBUTTONDOWN:190 191 mouse_pos=pygame.mouse.get_pos()192 193194 for button in buttons:195 196 button.x_coor=((buttons.index(button)+1)*((pygame.display.get_window_size()[0])//4))-(button_width//2)197 button.y_coor=(3*((pygame.display.get_window_size()[1])//4))-(button_height//2)198 button.width=pygame.display.get_window_size()[0]/6199 200 if button.was_clicked(mouse_pos) and game.game_ready:201 202 if player_num==0:203 if not game.p1_went:204 205 network.send_data_to_server(button.text)206207 else: #if not player 0, must be player 1208 if not game.p2_went:209 210 network.send_data_to_server(button.text)211 212 redraw_win(win, game, player_num, buttons, player_wins, player_loss)213214215216217def menu_screen(menu_buttons, buttons):218 p2_is_user_button, p2_is_comp_button, exit_button=menu_buttons219 run=True220 clock=pygame.time.Clock()221 while run:222 clock.tick(60)223 win.fill((0,0,0))224 font=pygame.font.SysFont("arial", 80)225 text=font.render("Main Menu",1,(255,255,255))226 win.blit(text, ( ((pygame.display.get_window_size()[0])//2)-(text.get_width()/2) , (((pygame.display.get_window_size()[1])//8))-(text.get_height()/2) ))227228 font=pygame.font.SysFont("arial", 40)229 text=font.render("Please select an option",1,(255,255,255))230 win.blit(text, ( ((pygame.display.get_window_size()[0])//2)-(text.get_width()/2) , ((2*(pygame.display.get_window_size()[1])//8))-(text.get_height()/2) ))231232 for button in menu_buttons:233 button.x_coor=((pygame.display.get_window_size()[0])//3)-(button_width//2)234 button.y_coor=((menu_buttons.index(button)+2)*(pygame.display.get_window_size()[1])//5)-(button_height//2)235 button.width=pygame.display.get_window_size()[0]/2236 button.draw_button(win)237 238 pygame.display.update()239240 for event in pygame.event.get():241 if event.type==pygame.QUIT:242 run=False243 pygame.quit()244 245 if event.type==pygame.MOUSEBUTTONDOWN:246 mouse_pos=pygame.mouse.get_pos()247248 for button in menu_buttons:249 button.x_coor=((pygame.display.get_window_size()[0])//3)-(button_width//2)250 button.y_coor=((menu_buttons.index(button)+2)*(pygame.display.get_window_size()[1])//5)-(button_height//2)251 button.width=pygame.display.get_window_size()[0]/2252253 if exit_button.was_clicked(mouse_pos):254 run=False255 pygame.quit()256 257 elif p2_is_user_button.was_clicked(mouse_pos):258 run=False259 main(buttons)260261 elif p2_is_comp_button.was_clicked(mouse_pos):262 run=False263 play_as_computer(buttons, 0, 0)264265266 267268269def play_as_computer(buttons, player_wins, player_loss):270 run=True271 clock=pygame.time.Clock()272 moves=["Rock", "Paper", "Scissors"]273 comp_move=moves[randrange(0,3)]274275 player_num=0276 player_been=False277 player_move=None278 while run:279 clock.tick(60)280 for event in pygame.event.get():281 if event.type==pygame.QUIT:282 run=False283 pygame.quit()284 if event.type==pygame.MOUSEBUTTONDOWN:285 286 mouse_pos=pygame.mouse.get_pos()287 288289 for button in buttons:290 291 button.x_coor=((buttons.index(button)+1)*((pygame.display.get_window_size()[0])//4))-(button_width//2)292 button.y_coor=(3*((pygame.display.get_window_size()[1])//4))-(button_height//2)293 button.width=pygame.display.get_window_size()[0]/6294 295 if button.was_clicked(mouse_pos) and not(player_been):296 player_been=True297 player_move=button.text298 299 redraw_win_for_comp_game(win, player_been, player_wins, player_loss, player_move, comp_move)300 301 if player_been:302 player_wins, player_loss=display_winner(comp_move, player_move, player_wins, player_loss)303 304 play_as_computer(buttons, player_wins, player_loss)305306307308309def redraw_win_for_comp_game(win, player_been, player_wins, player_loss, player_move, comp_move):310 win.fill((0,0,0))311 font=pygame.font.SysFont("arial", 45)312 313 text=font.render("Your Move", 1, (255,255,255))314 win.blit(text, ( ((pygame.display.get_window_size()[0])//3)-(text.get_width()/2) , ((pygame.display.get_window_size()[1])//4)-(text.get_height()/2) ) )315 316 text=font.render("Computer's Move", 1, (255,255,255))317 win.blit(text, ( (2*((pygame.display.get_window_size()[0])//3))-(text.get_width()/2) , ((pygame.display.get_window_size()[1])//4)-(text.get_height()/2) ) )318 319 if player_been:320 player_1_move_text=font.render(player_move, 1, (255,255,255))321 comp_move_text=font.render(comp_move, 1, (255,255,255))322 else:323 player_1_move_text=font.render("Selecting", 1, (255,255,255))324 comp_move_text=font.render("Selected Move", 1, (255,255,255))325 win.blit(player_1_move_text, ( ((pygame.display.get_window_size()[0])//3)-(player_1_move_text.get_width()/2) , (2*((pygame.display.get_window_size()[1])//4))-(player_1_move_text.get_height()/2) ))326 win.blit(comp_move_text, ( (2*((pygame.display.get_window_size()[0])//3))-(comp_move_text.get_width()/2) , (2*((pygame.display.get_window_size()[1])//4))-(comp_move_text.get_height()/2) ) )327328 for button in buttons:329 button.x_coor=((buttons.index(button)+1)*((pygame.display.get_window_size()[0])//4))-(button_width//2)330 button.y_coor=(3*((pygame.display.get_window_size()[1])//4))-(button_height//2)331 button.width=pygame.display.get_window_size()[0]/6332 button.draw_button(win)333334 font=pygame.font.SysFont("arial", 15)335 336 win_count_text="Won: "+str(player_wins)+" rounds"337 lost_count_text="Lost: "+str(player_loss)+" rounds"338 339 win_text=font.render(win_count_text, 1, (255,255,255))340 lost_text=font.render(lost_count_text, 1, (255,255,255))341 342 win.blit(win_text, ( (pygame.display.get_window_size()[0])-(win_text.get_width()), ((win_text.get_height() ) ) ) )343 win.blit(lost_text, ( (pygame.display.get_window_size()[0])-(lost_text.get_width()), (2*(lost_text.get_height() ) ) ) ) 344345 pygame.display.update()346 347def display_winner(comp_move, player_move, player_wins, player_loss):348 349 font=pygame.font.SysFont("arial", 90)350 if player_move.upper()[0]+comp_move.upper()[0] in ["RS", "SP", "PR"]:351 player_wins+=1352 text= font.render("You Won!", 1, (255,255,255) )353 elif player_move==comp_move:354 text= font.render("Tie Game!", 1, (255,255,255) )355 else:356 player_loss+=1357 text= font.render("You Lost!", 1, (255,255,255) )358 359 win.blit(text, ((pygame.display.get_window_size()[0])/2- text.get_width()/2, (3*(pygame.display.get_window_size()[1])/5)-text.get_height()/2))360 pygame.display.update()361 pygame.time.delay(2000)362 363 return (player_wins, player_loss)364365 366367368369370while True:
...
apppage.py
Source:apppage.py
...73 sleep()74 def swipe_left(self):75 """å·¦æ»"""76 log.info("å±å¹å·¦æ»")77 x = self.driver.get_window_size()['width']78 y = self.driver.get_window_size()['height']79 self.driver.swipe(x*3/4,y/4,x/4,y/4)80 def swipe_right(self):81 """å³æ»"""82 log.info("å±å¹å³æ»")83 x = self.driver.get_window_size()['width']84 y = self.driver.get_window_size()['height']85 self.driver.swipe(x/4,y/4,x*3/4,y/4)86 def swipe_down(self):87 """ä¸æ»"""88 log.info("å±å¹ä¸æ»")89 x = self.driver.get_window_size()['width']90 y = self.driver.get_window_size()['height']91 self.driver.swipe(x/2,y/4,x/2,y*3/4,self.dt)92 def swipe_up(self):93 """ä¸æ»"""94 log.info("å±å¹ä¸æ»")95 x = self.driver.get_window_size()['width']96 y = self.driver.get_window_size()['height']97 self.driver.swipe(x/2,y*3/4,x/2,y/4,self.dt)98 def touch_location(self, x1, y1):99 """100 :param101 x1:xåæ çç¸å¯¹å¼ï¼ç»å¯¹å¼/å辨çï¼eg:ç»å¯¹ä½ç½®æ¯200ï¼å辨çæ¯720ï¼åä¼ å
¥200/720102 y1:yåæ çç¸å¯¹å¼103 """104 log.info("éè¿åæ ç¹å»å
ç´ ")105 x = self.driver.get_window_size()['width']106 y= self.driver.get_window_size()['height']107 log.info("å
ç´ åæ ï¼x={0},y={1}".format(x1*x, y1*y))108 TouchAction(self.driver).press(x=x1*x, y=y1*y).release().perform()109 def element_exist(self, locator):110 """å¤æå
ç´ æ¯å¦åå¨"""111 try:112 log.info("æ¥æ¾å
ç´ :{}".format(locator))113 self.driver.find_element(by=locator[0], value=locator[1])114 except NoSuchElementException:115 log.info("å
ç´ ï¼{0}ä¸åå¨".format(locator))116 return False...
guesture.py
Source:guesture.py
1from lib2to3.pgen2 import driver2class guesture():3 def swipe_up(self,driver):4 #åä¸æ»å¨5 x = driver.get_window_size()['width']6 y = driver.get_window_size()['height']7 driver.swipe(x/2,y/4,x/2,y*3/4)8 def swipe_down(self,driver):9 #åä¸æ»å¨10 x = driver.get_window_size()['width']11 y = driver.get_window_size()['height']12 driver.swipe(x/2,y*3/4,x/2,y/4)13 def swipe_left(self,driver):14 #åå·¦æ»å¨15 x = driver.get_window_size()['width']16 y = driver.get_window_size()['height']17 driver.swipe(x*3/4,y/4,x/4,y/4)18 def swipe_right(self,driver):19 #åå³æ»å¨20 x = driver.get_window_size()['width']21 y = driver.get_window_size()['height']...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!