Пример #1
0
 def android_findClick(self,
                       findName,
                       ClickName,
                       description="",
                       waitTime=1,
                       tryTime=1,
                       sleeptime=0):
     """用寻找目标,后并点击"""
     waitTime = waitTime + float(MyData.EnvData_dir["sleepLevel"])
     while (tryTime > 0):
         tryTime = tryTime - 1
         try:
             print("正在寻找{0}".format(description))
             gameobject = self.androidpoco(findName)
             if gameobject.wait(waitTime).exists():
                 mylog.info("查找元素-【{}】--成功".format(findName))
                 if self.androidpoco(ClickName).exists():
                     print("发现{0}点击元素,并点击".format(description))
                     mylog.info("查找点击-【{}】--元素成功".format(description))
                     self.androidpoco(ClickName).click()
                     mylog.info("点击元素-【{}】--成功".format(description))
                     sleep(sleeptime)
                     return True
                 else:
                     print("查找{0}失败".format(description))
                     mylog.error("查找点击元素-【{}】--失败".format(findName))
             else:
                 mylog.error("查找元素-【{}】--失败".format(findName))
         except Exception as e:
             mylog.error("查找【{0}】出现未知错误,{1}".format(description, e))
             return False
     log(PocoNoSuchNodeException("点击-【{}】-元素失败".format(description)),
         desc="点击元素失败",
         snapshot=True)
     raise PocoNoSuchNodeException("点击-【{}】-元素失败".format(description))
Пример #2
0
 def findClick_object(self,
                      findName,
                      ClickName,
                      description="",
                      waitTime=1,
                      tryTime=1,
                      sleeptime=0):
     """用寻找目标,后并点击"""
     waitTime = waitTime + float(MyData.EnvData_dir["sleepLevel"])
     print("正在寻找{0}".format(description))
     if self.poco(ClickName).wait(waitTime).exists():
         print("发现{0}元素,并点击".format(description))
         mylog.info("查找点击-【{}】--元素成功".format(description))
         self.poco(ClickName).click()
         mylog.info("点击元素-【{}】--成功".format(description))
         print("点击元素-【{}】--成功".format(description))
         sleep(sleeptime)
         return True
     else:
         print("查找{0}失败".format(description))
         mylog.error("查找点击元素-【{}】--失败".format(findName))
     log(PocoNoSuchNodeException("点击-【{}】-元素失败".format(description)),
         desc="点击元素失败",
         snapshot=True)
     raise PocoNoSuchNodeException("点击-【{}】-元素失败".format(description))
Пример #3
0
 def notchfit_childobject(self,
                          ClickPoco: poco,
                          description="",
                          waitTime=0.5,
                          tryTime=1,
                          sleeptime=0,
                          log=True):
     """用于关联父级才能点击到的元素"""
     waitTime = waitTime + float(MyData.EnvData_dir["sleepLevel"])
     # ADBdevice=MyData.EnvData_dir["ADBdevice"]
     # if ADBdevice in MyData.mobileconf_dir["Notch_Fit"]:
     #     self.poco.use_render_resolution(True, MyData.mobileconf_dir["Notch_Fit"][ADBdevice])
     if ClickPoco.wait(waitTime).exists():
         print("发现{0}".format(description))
         mylog.info("查找点击元素-【{}】--成功".format(description))
         ClickPoco.click()
         sleep(sleeptime)
         mylog.info("点击元素-【{}】--成功".format(description))
         # self.poco.use_render_resolution(False, MyData.mobileconf_dir["Notch_Fit"][ADBdevice])
         return True
     else:
         mylog.error("查找-【{}】-元素失败".format(description))
     log(PocoNoSuchNodeException("点击-【{}】-元素失败".format(description)),
         desc="点击元素失败",
         snapshot=True)
     raise PocoNoSuchNodeException("点击-【{}】-元素失败".format(description))
Пример #4
0
 def findClick_childobject(self,
                           ClickPoco: poco,
                           description="",
                           waitTime=1,
                           tryTime=1,
                           sleeptime=0.1,
                           clickPos=None):
     """用于关联父级才能点击到的元素"""
     waitTime = waitTime + float(MyData.EnvData_dir["sleepLevel"])
     if ClickPoco.wait(waitTime).exists():
         print("发现{0}".format(description))
         mylog.info("查找点击元素-【{}】--成功".format(description))
         if clickPos is None:
             ClickPoco.click()
         else:
             ClickPoco.click(clickPos)
         sleep(sleeptime)
         mylog.info("点击元素-【{}】--成功".format(description))
         return True
     else:
         mylog.error("查找-【{}】-元素失败".format(description))
     log(PocoNoSuchNodeException("点击-【{}】-元素失败".format(description)),
         desc="点击元素失败",
         snapshot=True)
     raise PocoNoSuchNodeException("点击-【{}】-元素失败".format(description))
Пример #5
0
 def click_object(self, clickName, waitTime=1, description="", sleeptime=0):
     """直接点击,不存在会报错"""
     waitTime = waitTime + float(MyData.EnvData_dir["sleepLevel"])
     try:
         self.poco(clickName).wait(waitTime).click()
         mylog.info("点击元素-【{}】--成功".format(description))
         print("点击元素-【{}】--成功".format(description))
         sleep(sleeptime)
         return True
     except Exception as e:
         mylog.error("点击【{0}】出现未知错误,{1}".format(description, e))
         return False
     log(PocoNoSuchNodeException("点击-【{}】-元素失败".format(description)),
         desc="点击元素失败",
         snapshot=True)
     raise PocoNoSuchNodeException("点击-【{}】-元素失败".format(description))
Пример #6
0
 def open_game(self, sever_name_input="sever_name", game_account_input="old_game_account"):
     """
     功能向,开始游戏,启动到游戏主界面,广告和签到界面关闭
     :return:返回StdPoco().poco对象,可直接用于脚本的控件点击
     """
     try:
         self.poco = self.eg.open_game(sever_name_input, game_account_input)
         self.set_poco(self.poco)
         return self.poco
     # 如果出现断开连接的报错,就再执行一下该步骤
     except RpcTimeoutError:
         pristr = "poco断开" + str(self.info.game_is_running())
         if not self.info.game_is_running():
             game_name = self.info.get_config("App_Name", "game_name")
             start_app(game_name)
             sleep(2)
             snapshot(msg=pristr)
         snapshot(msg=pristr)
         self.poco = self.eg.open_game(sever_name_input, game_account_input)
         self.set_poco(self.poco)
     except PocoNoSuchNodeException:
         snapshot(msg="找不到控件")
         raise PocoNoSuchNodeException(self)
     except Exception:
         pristr = "报错,游戏" + str(self.info.game_is_running())
         snapshot(msg=pristr)
         raise Exception
Пример #7
0
 def my_swipe(self, start_poco, end_poco, timein=2):
     """
     两个对象中心点之间的滑动
     :param start_poco:poco对象
     :param end_poco:poco对象
     :return:两个对象的坐标
     """
     try:
         pos_2, pos_3 = self.my_poco.my_swipe(start_poco, end_poco, timein)
         return pos_2, pos_3
     # 如果出现断开连接的报错,就再执行一下该步骤
     except RpcTimeoutError:
         pristr = "poco点击断开" + str(self.info.game_is_running())
         if not self.info.game_is_running():
             game_name = self.info.get_config("App_Name", "game_name")
             start_app(game_name)
             sleep(2)
             snapshot(msg=pristr)
         snapshot(msg=pristr)
         pos_2, pos_3 = self.my_poco.my_swipe(start_poco, end_poco, timein)
         return pos_2, pos_3
     except PocoNoSuchNodeException:
         snapshot(msg="找不到控件")
         raise PocoNoSuchNodeException(self)
     except Exception:
         pristr = "点击方法报错,游戏" + str(self.info.game_is_running())
         snapshot(msg=pristr)
         raise Exception
Пример #8
0
 def _do_query(self, multiple=True, refresh=False):
     if not self._evaluated or refresh:
         self._nodes = self.poco.agent.hierarchy.select(self.query, multiple)
         if len(self._nodes) == 0:
             raise PocoNoSuchNodeException(self)
         self._evaluated = True
         self._query_multiple = multiple
     return self._nodes
Пример #9
0
 def find_childobject(self,
                      findPoco: poco,
                      description="",
                      waitTime=1,
                      tryTime=3,
                      sleeptime=0):
     """用于关联父级才能找到的元素"""
     waitTime = waitTime + float(MyData.EnvData_dir["sleepLevel"])
     if findPoco.wait(waitTime).exists():
         print("发现{0}".format(description))
         mylog.info("查找点击元素-【{}】--成功".format(description))
         return True
     else:
         mylog.error("查找-【{}】-元素失败".format(description))
     log(PocoNoSuchNodeException("点击-【{}】-元素失败".format(description)),
         desc="点击元素失败",
         snapshot=True)
     raise PocoNoSuchNodeException("点击-【{}】-元素失败".format(description))
Пример #10
0
 def find_object(self,
                 findName,
                 description="",
                 waitTime=1,
                 tryTime=1,
                 sleeptime=0):
     """寻找目标"""
     waitTime = waitTime + float(MyData.EnvData_dir["sleepLevel"])
     print("正在寻找{0}".format(description))
     if self.poco(findName).wait(waitTime).exists():
         print("发现{0}".format(description))
         sleep(sleeptime)
         mylog.info("等待元素-【{}】--加载成功".format(description))
         return True
     log(PocoNoSuchNodeException("等待-【{}】-元素超时".format(description)),
         desc="等待元素超时",
         snapshot=True)
     raise PocoNoSuchNodeException("等待-【{}】-元素超时".format(description))
Пример #11
0
 def _do_query(self, multiple=True, refresh=False):
     if not self._evaluated or refresh:
         self._nodes = self.poco.agent.hierarchy.select(
             self.query, multiple)
         if len(self._nodes) == 0:
             # 找不到节点时,将当前节点状态重置,强制下一次访问时重新查询一次节点信息
             self.invalidate()
             raise PocoNoSuchNodeException(self)
         self._evaluated = True
         self._query_multiple = multiple
     return self._nodes
Пример #12
0
 def find_poco(self, find_name, find_type="text", click_name=None, ynlist="不翻", direction="竖屏", click_type=None,
               click_list=None):
     """
     查找控件并点击,默认三次内找不到报错,间隔5秒
     :param find_name:查找的控件名
     :param find_type:查找的控件类型 text、name....
     :param click_name:点击的控件名,默认none,表示查找和点击的控件是一个点
     :param click_type:点击的控件类型text、name....
     :param ynlist:是否翻页查找,默认x:1/2 ,y1/5-4/5范围,建议使用my_swipe方法
     :param direction:和翻页相关,横屏还是竖屏范围翻页
     :param click_list:控件点击偏移点[0,0]-[1,1]范围
     :return:PocoNoSuchNodeException
     """
     try:
         self.my_poco.find_poco(find_name, find_type=find_type, click_name=click_name, ynlist=ynlist,
                                direction=direction, click_type=click_type,
                                click_list=click_list)
     # 如果出现断开连接的报错,就再执行一下该步骤
     except RpcTimeoutError:
         pristr = "poco点击断开" + str(self.info.game_is_running())
         if not self.info.game_is_running():
             game_name = self.info.get_config("App_Name", "game_name")
             start_app(game_name)
             sleep(2)
             snapshot(msg=pristr)
         snapshot(msg=pristr)
         self.poco = StdPoco()  # todo 需要根据游戏不同区分
         self.set_poco(self.poco)
         self.my_poco.find_poco(find_name, find_type=find_type, click_name=click_name, ynlist=ynlist,
                                direction=direction, click_type=click_type,
                                click_list=click_list)
     except PocoNoSuchNodeException:
         snapshot(msg="找不到控件")
         raise PocoNoSuchNodeException(self)
     except Exception:
         pristr = "点击方法报错,游戏" + str(self.info.game_is_running())
         snapshot(msg=pristr)
         raise Exception
    def find_poco(self,
                  find_name,
                  find_type="text",
                  click_name=None,
                  ynlist="不翻",
                  direction="竖屏",
                  click_type=None,
                  click_list=None):
        """
        只一个参数时,默认poco(text=find_name)
        :param find_name:需要查找的控件名
        :param find_type:name/text/obj
        :param click_name:需要点击的控件,默认none,表示和find_name是一个控件
        :param ynlist:是否翻页查找(上翻页、下翻页、不翻)
        :param click_type:需要点击的控件的类型,name/text,默认none,表示和find_name是一个控件
        :param click_list:点击UI偏移量[0,0]-[1,1]
        :return:
        """
        sleep(0.5)
        global find_to
        find_to = False
        for i in range(3):
            # 判断是否因为异常弹窗导致找不到
            self.uw.unexpected_win()
            if "翻页" in ynlist:
                self.phone_size = self.info.get_phone_size()
                for i in range(20):
                    i_go = i + 1
                    long_side = self.phone_size[0]
                    short_side = self.phone_size[1]
                    # 循环中找不到时可以继续下次循环
                    try:
                        # 查找的和点击的不一致
                        if click_name is not None:
                            # 判断需要点击的类型,后续可加入其他类型
                            if click_type == "name":
                                if find_type == "name":
                                    if self.poco(name=find_name).exists():
                                        self.poco(
                                            name=click_name).click(click_list)
                                        find_to = True
                                        break
                                if find_type == "text":
                                    if self.poco(text=find_name).exists():
                                        self.poco(
                                            name=click_name).click(click_list)
                                        find_to = True
                                        break
                        else:
                            if find_type == "obj":
                                if find_name.exists():
                                    find_name.click(click_list)
                                    find_to = True
                                    break
                            # 查找和点击是一个,翻页版
                            if find_type == "name":
                                if self.poco(name=find_name).exists():
                                    self.poco(
                                        name=click_name).click(click_list)
                                    find_to = True
                                    break
                            if find_type == "text":
                                if self.poco(text=find_name).exists():
                                    self.poco(text=find_name).click(click_list)
                                    find_to = True
                                    break
                    except PocoNoSuchNodeException:
                        print("第" + str(i_go) + "遍未找到")
                    # 循环结束再找不到报错
                    if i_go == 20:
                        snapshot(msg="翻页查找报错退出时画面")
                        raise PocoNoSuchNodeException(self)
                    if "下" in ynlist:
                        if direction == "横屏":
                            swipe([long_side / 2, short_side * 0.8],
                                  [long_side / 2, short_side * 0.2])
                        else:
                            swipe([short_side / 2, long_side * 0.8],
                                  [short_side / 2, long_side * 0.2])
                    if "上" in ynlist:
                        if direction == "横屏":
                            swipe([long_side / 2, short_side * 0.2],
                                  [long_side / 2, short_side * 0.8])
                        else:
                            swipe([short_side / 2, long_side * 0.2],
                                  [short_side / 2, long_side * 0.8])
                    sleep(3)
            # 不翻页
            else:
                # 查找的和点击的不一致

                if click_name is not None:
                    # 判断需要点击的类型,后续可加入其他类型
                    if click_type == "name":
                        if find_type == "name":
                            if self.poco(name=find_name).exists():
                                self.poco(name=click_name).click(click_list)
                                find_to = True
                                break
                        if find_type == "text":
                            if self.poco(text=find_name).exists():
                                self.poco(name=click_name).click(click_list)
                                find_to = True
                                break
                else:
                    # 查找和点击是一个
                    if find_type == "obj":
                        if find_name.exists():
                            find_name.click(click_list)
                            find_to = True
                            break
                    if find_type == "name":
                        if self.poco(name=find_name).exists():
                            self.poco(name=find_name).click(click_list)
                            find_to = True
                            break
                    else:
                        if self.poco(text=find_name).exists():
                            self.poco(text=find_name).click(click_list)
                            find_to = True
                            break
            if find_to:
                break
            sleep(5)
            if i == 2:
                if not find_to:
                    snapshot(msg="点击报错退出时画面")
                    raise PocoNoSuchNodeException(self)