def GoFarSeek(): """进入远征页面""" if exists(T[TM.farseek]) or exists(T[TM.farseek_temp]): touch(T[PM.farseek]) sleep(0.5) return True return False
def lookRanking(self, rank, category): #点击标签 self.poco(text=rank).click() sleep(1) if exists( Template(r"tpl1524195197433.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.194, -0.837), resolution=(1080, 1920))): print("切换总榜成功") if exists( Template(r"tpl1524195245944.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.194, -0.843), resolution=(1080, 1920))): print("切换周榜成功") self.poco(text=category).click() sleep(1) if exists( Template(r"tpl1522639179495.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(-0.129, -0.702), resolution=(1440, 2560))): print("切换到了猎人榜") if exists( Template(r"tpl1522639216724.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.19, -0.707), resolution=(1440, 2560))): print("切换到了工匠榜") if exists( Template(r"tpl1522639268505.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(-0.151, -0.711), resolution=(1440, 2560))): print("切换到了巨星榜") #滑动 self.swipeRanking(rank, category) #查看奖励 self.poco("Btn_RewardDetail").click() sleep(1) whatRanking = "Rewards-(%s)%s" % (rank, category) title = self.poco("TitleBg").child("Text_Title").get_text() if whatRanking == title: print("查看%s成功" % (whatRanking)) self.poco("Btn_Close").click() sleep(1) if not self.poco("TitleBg").exists(): print("关闭%s成功" % (whatRanking))
def exit(): """中途退出战斗""" if exists(T[TM.battle_menu]): touch(T[TM.battle_menu]) if exists(T[TM.quit_battle]): touch(T[TM.quit_battle]) if exists(T[TM.quit_confirm]): touch(T[TM.quit_confirm]) return True return False
def is_in_detail(): ret = exists(Template(CLICK_BACK)) # 直接返回False if not ret: return ret if ret[1] > 70 and ret[0] > X_MIDDLE: return False pos = ret ret = exists(Template(MORE_TEXT)) if not ret: return ret if ret[1] > 70 and ret[0] < X_MIDDLE: return False return pos
def runTest(self): keyboard = Template(self.R('res/img/keyboard-digits.png')) keyboard_landscape = Template( self.R('res/img/keyboard-digits-landscape.png')) self.assertTrue( exists(keyboard) or exists(keyboard_landscape), 'App started.') self.poco('com.google.android.calculator:id/digit_1').click() self.poco('com.google.android.calculator:id/op_add').click() self.poco('com.google.android.calculator:id/digit_1').click() self.poco('com.google.android.calculator:id/eq').click() time.sleep(1) result = self.poco( 'com.google.android.calculator:id/formula').get_text() self.site_capturer.snapshot('check-point-1') self.assertEqual(result, '2', '1+1=2 ^^')
def switchPrivacy(self): # self.poco = UnityPoco() self.poco(text="Public").click() sleep(1) assert_exists( Template(r"tpl1526632435537.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(-0.384, -0.207), resolution=(576, 1024)), "switch to Open pass") self.poco("OnlyFriend").click() sleep(1) assert_exists( Template(r"tpl1526632538433.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(-0.295, -0.127), resolution=(576, 1024)), "switch to Just pass") self.poco("OnlyMe").click() sleep(1) assert_exists( exists( Template(r"tpl1526632587864.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(-0.267, -0.042), resolution=(576, 1024))), "switch to Publicity pass")
def click_subscribe(): """ 点击点阅按钮,成功返回True,失败返回False """ ret = exists(Template(CLICK_SUBSCRIBE, threshold=0.80)) if ret: touch(Template(CLICK_SUBSCRIBE, threshold=0.80)) return True return False
def auto_retry(): """ 战斗结算重试+符卡|技能页面收回 最终异常处理 """ if exists(T[TM.battle_fail]): touch(T[TM.battle_fail]) return if exists(T[TM.battle_success]): touch(T[TM.battle_success]) return #删除了旧版的结算决定按键 if exists(T[TM.spell_expanded]): touch(T[TM.spell_expanded]) return if exists(T[TM.skill_expanded]): touch(T[TM.skill_expanded]) return exit()
def SelectDifficulty(d: Difficulty): ''' 切换副本难度 example:SelectDifficulty(Difficulty.normal) ''' if d in [Difficulty.normal, Difficulty.hard, Difficulty.lunatic]: #pos = PointSet([427, 652], src_resolution) for i in range(3): if not exists(T[d]): touch(P[PM.difficultychange]) sleep(1) else: break
def GoHome(): """返回主界面""" auto_timeout() if AtHome(): return True #有回家按钮直接点 if exists(T[TM.home]): touch(T[TM.home]) sleep(3) #结算页面的情况 elif exists(T[TM.next]): touch(P[PM.next]) sleep(3) touch(T[TM.home]) sleep(3) #如果在战斗中退出战斗之后回主页 elif exists(T[TM.battle_menu]): if exit(): sleep(3) touch(T[TM.home]) sleep(3) return AtHome()
def switchFliters(self): self.poco(text="Filters").click() sleep(1) while exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))): touch( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))) sleep(1) self.poco("My").click() sleep(1) assert_exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(0.095, -0.21), resolution=(1440, 2560)), "去除mine勾选成功") self.poco("My").click() sleep(1) self.poco("other").click() sleep(1) assert_exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(0.095, -0.21), resolution=(1440, 2560)), "other可以除去勾选框") self.poco("other").click() sleep(1) self.poco("Played").click() sleep(1) assert_exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(0.095, -0.21), resolution=(1440, 2560)), "not hide played today可以除去勾选框")
def buy(): poco = UnityPoco() #确定购买 poco("Tree").child("ShopProp(Clone)")[0].child("BuyIt").click() sleep(1) poco(text="OK").click() sleep(5) #弹出sdk界面 if poco("lable").exists(): if poco("lable").get_text() == "Top-up failed:3:Billing Unavailable": print("内网无法购买") poco(text="Confirm").click() sleep(1) if poco(text="You got").exists(): print("购买成功") while poco("xxxxxxxx").child("Text").exists(): poco("xxxxxxxx").child("Text").click() sleep(1) if poco(text="Not enough diamonds!").exists(): if poco(text="Not enough diamonds!").get_text() == "Not enough diamonds!": print("钻石不足无法购买") poco("copypop").child("BG").child("Button").child("Text").click() if poco(text="Not enough coins!").exists(): if poco(text="Not enough coins!").get_text() == "Not enough coins!": print("金币不足无法购买") poco("copypop").child("BG").child("Button").child("Text").click() if exists(Template(r"tpl1522392116057.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(-0.215, -0.074), resolution=(1440, 2560))): print("弹出购买sdk界面成功") #购买失败 shell("input keyevent 4") assert_exists(Template(r"tpl1522392162168.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.003, 0.023), resolution=(1440, 2560)), "取消购买成功") print("购买成功请手动测试") if exists(Template(r"tpl1522399084096.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.001, 0.015), resolution=(1440, 2560))): print("内网钻石无法购买成功")
def FindMap(m, times=5): """ 查询图片是否存在 m:airtest.cv.Template times:重试次数 """ try: for i in range(times): findit = exists(m) if findit: return True else: SwipeLevel() sleep(1.5) except TargetNotFoundError: logger.error("cannot find map") return False
def recoveryFilters(self): self.poco(text="Filters").click() while exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))): touch( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))) sleep(1) self.poco.click([360.0 / 720, 700.0 / 1280]) sleep(2)
def cancelAll(self): #去除所有勾选 while exists( Template(r"tpl1524898630127.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.096, -0.211), resolution=(720, 1280))): touch( Template(r"tpl1524898630127.png", threshold=0.9, target_pos=5, rgb=False, record_pos=(0.096, -0.211), resolution=(720, 1280))) sleep(0.5) self.poco.click([360.0 / 720, 700.0 / 1280]) sleep(1) assert ("去掉所有人的关卡") if not self.poco("Tree").child().exists(): assert ("去掉所有人的关卡成功")
def _exists(self,ui:Union[PocoUi,PootUi,Picture],**kw): ''' 是否存在此控件 :param ui:poco\poot\图片 :param kw:常规查询的其他参数 :return: ''' # 参数校验 self.__para_check(ui, [PocoUi,PootUi,Picture]) # 逻辑处理 if type(ui) == Picture: return exists(ui.getTemplate()) self.__pre_action() try: if type(ui) == PocoUi: u = self.__poco(ui.info, **kw) return u.exists() if type(ui)==PootUi: return self.__poot(ui.info) != None except: return False raise BaseException("不支持对类型为{}的操作".format(type(ui)))
def onlyMine(self, player): self.poco(text="Filters").click() sleep(1) while exists( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))): touch( Template(r"tpl1522138307590.png", threshold=0.85, target_pos=5, rgb=False, record_pos=(-0.188, -0.208), resolution=(1440, 2560))) sleep(0.5) self.poco("other").click() sleep(1) self.poco("Played").click() sleep(1) self.poco.click([360.0 / 720, 700.0 / 1280]) sleep(1) self.poco(text="Popularity").click() sleep(1) myLevels = self.poco("Tree").child() marklist = [] # player = self.poco("ToUserInfo").child("Text").get_text() for i in myLevels: if str(player) in i.child("LvMaker").get_text(): marklist.append(1) else: marklist.append(0) assert (marklist) if max(marklist) == min(marklist) and max(marklist) == 1: assert ("只保留自己的关卡成功")
def exists(obj): return exists(obj)
def Back(): """ 返回[特殊] """ if exists(T[TM.back]): touch(T[TM.back])
def toch_while(self, y): self.y = y while True: if exists(self.y): touch(self.y) break
def GoExplore(): """进入探索[战斗地图]页面""" if exists(T[TM.explore]): touch(T[TM.explore])
def AtHome(): """是否在主界面""" if exists(T[TM.explore]): return True return False
def auto_timeout(): """是否链接超时并尝试重连一次""" if exists(T[TM.msg_box_title]): touch(T[TM.msg_box_confirm]) return True return False
def exists(self): if isinstance(self.template, Template): return exists(self.template) else: return self.template.exists()
def exists_check(template): if isinstance(template, Template): return exists(template) else: return template.exists()
def img_element_exists(self, img_file, is_rgb): return exists( Template(filename=img_file, threshold=self.threshold, resolution=self.resolution, rgb=is_rgb))
def toch_new(self, x): for i in range(3): self.x = x if exists(self.x): touch(self.x) break