Best Python code snippet using ATX
click.py
Source:click.py
...304 if success != None:305 d.screenshot("yuhunjieshu_success_snapshot.png")306 if fail != None:307 d.screenshot("yuhunjieshu_fail_snapshot.png")308 d.free_screen()309 if (success != None) | (fail != None):310 print "find attack end flag, try to clear all end flag"311 time.sleep(4)312 while (success != None) | (fail != None):313 success = click_image("yuhunjieshu_4.750x1334.png")314 fail = click_image("shibai_jixu.750x1334.png")315 print "attack did end ~~~ "316 return317 318 319def switch_zidong_shoudong():320 click(58, 62)321def tupoUserPositions():322 d.screenshot('screen.1920x1080.png') # Save screenshot as file323 t = find_all_image_position("screen.1920x1080.png", "tupo_user_flag.750x1334.png", 0.8)324 print "find users %d" %(len(t))325 return t326def douji():327 return328def stopyuhunjiacheng():329 pass330def stopJiacheng():331 backHome()332 # è¿å
¥å æ页é¢333 wait_image("jiacheng_entrance_home.750x1334.png")334 #å
³éææå æ335 time.sleep(2)336 d.screenshot('screen.1920x1080.png') # Save screenshot as file337 print "stop jiacheng"338 runnings = find_all_image_position("screen.1920x1080.png", "jiacheng_running.750x1334.png")339 print runnings340 for run in runnings:341 click(run[0], run[1], False)342 time.sleep(1)343 # éåºå æ页é¢344 wait_image("jiacheng_entrance_home.750x1334.png")345def startJiacheng(image, confidence=0.7):346 # è¿å
¥å æ页é¢347 wait_image("jiacheng_entrance_2.750x1334.png")348 #å
³éææå æ349 time.sleep(2)350 d.screenshot('screen.1920x1080.png') # Save screenshot as file351 runnings = find_all_image_position("screen.1920x1080.png", "jiacheng_running.750x1334.png")352 for run in runnings:353 print "stop jiacheng"354 click(run[0], run[1], False)355 time.sleep(1)356 print "start kaiqi jiacheng"357 #æ¥æ¾å æå¼å
³358 d.screenshot('screen.1920x1080.png') # Save screenshot as file359 t_btns = find_all_image_position("screen.1920x1080.png", "jiacheng_pauseing.750x1334.png")360 print t_btns361 icons = find_all_image_position("screen.1920x1080.png", image, confidence)362 print("find jiacheng %d"%(len(icons)))363 if len(icons):364 for icon in icons:365 print icon366 target = None367 dis = 9999368 for btn in t_btns:369 print btn370 tDis = abs(btn[0] - icon[0])371 print("tDis=",tDis,"dis=",dis, "btn =", btn)372 if tDis < dis:373 dis = tDis374 target = btn375 print(target,"= btn")376 print(target,"= btn")377 print("target = ", target)378 time.sleep(1)379 click(target[0], target[1], False)380 # éåºå æ页é¢381 wait_image("jiacheng_entrance_2.750x1334.png")382def quick_click_image(image):383 d.keep_screen()384 pos = click_image(image)385 d.free_screen()386 return pos387def click_guild():388 d.keep_screen()389 FindPoint = click_image("hand_guild.750x1334.png")390 d.free_screen()391 dis = d.display392 y = dis.height - (FindPoint.pos[0] + 50)393 x = FindPoint.pos[1] - 50394 d.click(x, y)395def lianxiaohao():396 while 1:397 click_image("diandiandian.750x1334.png")398 click_image("diandiandian_2.750x1334.png")399 d.keep_screen()400 click_image("daxiaoguai_1.750x1334.png")401 click_image("juqing_yanjing.750x1334.png")402 click_image("juqing_wenhao.750x1334.png")403 click_image("skip.750x1334.png")404 click_image("zhunbei.750x1334.png")405 click_image("yuhunjieshu_4.750x1334.png")406 click_image("shibai_jixu.750x1334.png")407 click_image("quick_play.750x1334.png")408 click_image("xiaobai.750x1334.png")409 click_image("tupo_queding.750x1334.png")410 click_image("close_btn.750x1334.png")411 d.free_screen()412 # click_guild()413def change_gouliang():414 print "start change gouliang"415 while d.exists("zhunbei.750x1334.png") == None:416 pass417 while d.exists("gouliang_quanbu_btn.750x1334.png") == None:418 click(216, 486)419 time.sleep(1)420 421 while d.exists("gouliang_sucai_btn.750x1334.png") == None:422 wait_image("gouliang_quanbu_btn.750x1334.png")423 time.sleep(2)424 wait_image("gouliang_sucai_btn.750x1334.png")425 swipe(148, 884, 126, 352)#å·¦æ»ä¸æ®µè·ç¦»426 time.sleep(1)427 swipe(134, 374, 370, 194)#æ¿æ¢ç¬¬ä¸å¼ çç²®428 time.sleep(2)429 swipe(138, 618, 364, 582)#æ¿æ¢ç¬¬äºå¼ çç²®430 print "end change gouliang"431def change_gouliang_and_start():432 print "change_gouliang_and_start"433 while d.exists("zhunbei.750x1334.png") == None:434 pass435 d.screenshot('screen.1920x1080.png') # Save screenshot as file436 t = find_all_image_position("screen.1920x1080.png", "gouliang_manji.750x1334.png", 0.8)437 if len(t)>1:438 print "need change gouliang"439 change_gouliang()440 441 click_image("zhunbei.750x1334.png")442 print "change gouliang end"443def tansuo_find_boss():444 while (d.exists("tansuo_daguai.750x1334.png") == None) & (d.exists("daxiaoguai_3.750x1334.png") == None):445 print "no boss to attack, move right"446 offset = random.random() * 10447 click(140 + offset, 920 + offset)448 time.sleep(1)449 return False450 print 'have boss, start find'451 while (d.exists("zhunbei.750x1334.png") == None):452 if (click_image("tansuo_daguai.750x1334.png") == None) & (click_image("daxiaoguai_3.750x1334.png") == None) :453 print "move right"454 offset = random.random() * 10455 click(140 + offset, 920 + offset)456 time.sleep(1)457 if d.exists("tilibuzu_goumaitili.750x1334.png") != None:458 stopAll()459 return False460 if (d.exists("tansuo_xiao_baoxiang.750x1334.png") != None) | (d.exists("tansuo_huodejiangli.750x1334.png") != None):461 return False462 return True463def tansuo_find():464 if d.exists("tansuo_xiao_baoxiang.750x1334.png") != None:#ç»æ以åç¹å»å®ç®±465 while (d.exists("tansuo_xiao_baoxiang.750x1334.png") != None) | (d.exists("tansuo_huodejiangli.750x1334.png") != None):466 click_image("tansuo_xiao_baoxiang.750x1334.png")467 time.sleep(2)468 if d.exists("tansuo_huodejiangli.750x1334.png") != None:469 click(330, 1160)470 print "jiang li"471 time.sleep(2)472 elif d.exists("return_btn.750x1334.png") != None:#æ¾æªç©473 if tansuo_find_boss():474 print "find boss"475 if d.exists("tilibuzu_goumaitili.750x1334.png") != None:476 stopAll()477 change_gouliang_and_start()478 else:#éåºææçé¢479 print "maybe attacking"480 click_image("zhunbei.750x1334.png")481 click_image("yuhunjieshu_3.750x1334.png")482 time.sleep(2)483 click_image("yuhunjieshu_4.750x1334.png")484 click_image("yuhunjieshu_4.750x1334.png")485 click_image("shibai_jixu.750x1334.png")486def zzz_douji():487 enter = "zzz_pipei.750x1334.png"#å¹é
æé®488 lijijiechu = "lijijiechu.750x1334.png"#ç«å³è§£é¤489 quxiao = "zzz_quxiao.750x1334.png"#åæ¶490 zidongshangzhen = "douji_zidongshangzheng.750x1334.png"#èªå¨ä¸éµ491 shoudong2zidong = "douji_shoudong_2_zidong.750x1334.png"#æå¨æ¹èªå¨492 # click_image(lijijiechu)493 # click_image(quxiao)494 # click_image(enter)495 d.keep_screen()496 click_image("douji_zhan.750x1334.png")497 click_image(zidongshangzhen)498 click_image(shoudong2zidong)499 click_image("zhunbei.750x1334.png")500 click_image("zzz_end.750x1334.png")501 click_image("douji_shibai.750x1334.png")502 # click_image("zzz_end_jiutun.750x1334.png")503 click_image("zzz_end_jiangli.750x1334.png")504 d.free_screen()505def tansuoEntranceIfNeeded(level):506 if d.exists("tansuo_home_flag.750x1334.png") != None:507 print "in tansuo home, go tansuo entrance"508 while click_image(level) != None:509 time.sleep(2)510 pass511 print("did enter", level)512def isTansuoFinished():513 if (d.exists("tansuo_home_flag.750x1334.png") != None) | (d.exists("tansuo_entrance_flag.750x1334.png") != None):514 print "tansuo finished"515 return True516 return False517 518def tansuo_once(level):519 tansuoEntranceIfNeeded(level)520 time.sleep(2)521 click_image("tansuo.750x1334.png", True)522 print "start tansuo"523 while isTansuoFinished() == False:524 tansuo_find()525 print "enter loop"526 while d.exists("tansuo_home_flag.750x1334.png") == None:527 print "try go back tansuo home"528 click_image("close_btn_1.750x1334.png")529 530 print "did go back tansuo home"531 if click_image("tansuo_baoxiang_big.750x1334.png") != None:532 time.sleep(3)533 click_image("yuhunjieshu_4.750x1334.png")534def tansuo_lianji_28():535 backHome()536 tansuo()537 time.sleep(2)538 startJiacheng("jiacheng_jingyan.750x1334.png")539 i = 0540 while i < 5:541 i = i + 1542 tansuo_once("tansuo_level_28.750x1334.png")543 stopJiacheng()544def tansuo_lianji_18():545 # backHome()546 # tansuo()547 # time.sleep(2)548 while click_image("tansuo_level_10.750x1334.png") != None:549 pass550 551 # startJiacheng("jiacheng_jingyan.750x1334.png")552 while 1:553 if click_image("tansuo_baoxiang_big.750x1334.png") != None:554 time.sleep(5)555 click_image("yuhunjieshu_4.750x1334.png")556 if click_image("tansuo_level_10.750x1334.png") != None:557 time.sleep(3)558 click_image("tansuo_start.750x1334.png")559 tansuo_find()560 elif click_image("tansuo_start.750x1334.png") != None:561 tansuo_find()562 # stopJiacheng()563def random_click():564 minX = 258565 maxX = 438566 minY = 188567 maxY = 1140568 x = random.uniform(minX, maxX)569 y = random.uniform(minY, maxY)570 click(x, y)571def yuhun_duiyuan():572 click_image("yuhunjieshu_4.750x1334.png")573 click_image("shibai_jixu.750x1334.png")574 click_image("yuhunjieshu_3.750x1334.png")575 click_image("zhunbei.750x1334.png")576 click_image("yuhun_zidong_jieshou_zudui.750x1334.png")577def baigui_yaoqing():578 i = 0579 flag = 0580 while d.exists("baigui_kaishi.750x1334.png") == None:581 while d.exists("baigui_yaoqing_start.750x1334.png") != None:582 click_image("baigui_yaoqing_start.750x1334.png")583 if d.exists("baigui_user_list_flag.750x1334.png") != None:584 print "----- user list -----"585 users = [(474, 494), (490, 770),586 (388, 494), (398, 770),587 (316, 494), (310, 770),588 (226, 494), (228, 770)]589 index = random.randint(0, 7)590 for i in xrange(0, i):591 swipe(188, 666, 472, 661)592 time.sleep(0.1)593 print("index = ", index)594 user = users[index]595 click(user[0], user[1])596 while d.exists("baigui_user_list_flag.750x1334.png") != None:597 print "chose other"598 swipe(188, 666, 472, 661)599 user = users[random.randint(0, 7)]600 click(user[0], user[1])601 print "did invite friend"602 click_image("baigui_jinru.750x1334.png")603 print "start baigui"604 time.sleep(1)605 if d.exists("baigui_jinru.750x1334.png") != None:606 print "can not invite"607 flag = flag + 1608 if flag > 3:609 i = i + 1610 flag = 0611 click_image("baigui_yaoqing_cancel.750x1334.png", True)612 time.sleep(1)613def baigui():614 baigui_yaoqing()615 616 print "did enter gui wang chose"617 click(282, 670)618 click_image("baigui_kaishi.750x1334.png", True)619 swipe(62, 402, 56, 510)620 while 1:621 d.keep_screen()622 jinru = d.exists("baigui_jinru.750x1334.png") != None623 end = d.exists("baigui_end_flag.750x1334.png") != None624 kaishi = d.exists("baigui_kaishi.750x1334.png") != None625 d.free_screen()626 if jinru | end | kaishi:627 break628 i = 0629 while i < 7:630 random_click()631 i = i + 1632 click_image("baigui_end_flag.750x1334.png")633 print "end baigui"634 635print d.rotation636#lianxiaohao()637#kaiqijiacheng()638# while 1:639# yuhun_duiyuan()...
mixin.py
Source:mixin.py
...300 _d._bounds = bounds301 return _d302 def keep_screen(self):303 """304 Freese screenshot, so all image functions will not take images, until call free_screen()305 """306 self.__last_screen = self.screenshot()307 self.__keep_screen = True308 inner_self = self309 class _C(object):310 def __enter__(self):311 pass312 def __exit__(self, type, value, traceback):313 inner_self.free_screen()314 return _C()315 def free_screen(self):316 """317 Unlock keep_screen()318 """319 self.__keep_screen = False320 return self321 def region_screenshot(self, filename=None):322 """Deprecated323 Take part of the screenshot324 """325 # warnings.warn("deprecated, use screenshot().crop(bounds) instead", DeprecationWarning)326 screen = self.__last_screen if self.__keep_screen else self.screenshot()327 if self.bounds:328 screen = screen.crop(self.bounds)329 if filename:...
position.py
Source:position.py
...23 if in_explore_map(self.d):24 x, y = self.d.match(img('chapter_list'), offset=(0, 1))[0]25 self['chapter_top'] = (x, y)26 self['chapter_bottom'] = (x, y + 4 * (self.l - x))27 self.d.free_screen()28 return True29 elif is_breaking(self.d):30 self['first_target'] = (self.l * 0.25, self.w * 0.25)31 self['break_top'] = (self.l * 0.75, self.w * 0.25)32 self['break_bottom'] = (self.l * 0.75, self.w * 0.75)33 self.d.free_screen()34 return True35 self.d.free_screen()...
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!!