예제 #1
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))
예제 #2
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))
예제 #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 runing(self):
     for k, v in self.Runlist_dir.items():
         repeattime = self.Case_info[k]["repeattime"]
         while (self.Case_info[k]["repeattime"] > 0):
             __author__ = self.Case_info[k]["caseauthor"]
             __title__ = self.Case_info[k]["casename"] + str(
                 repeattime - (self.Case_info[k]["repeattime"] - 1))
             __desc__ = self.Case_info[k]["casedec"]
             recordfile = __title__ + ".mp4"
             htmlname = self.Case_info[k]["reportname"] + str(repeattime - (
                 self.Case_info[k]["repeattime"] - 1)) + ".html"
             # logname = self.Case_info[k]["reportname"] + str(repeattime - (self.Case_info[k]["repeattime"] - 1)) + "log.txt"
             try:
                 start_record()
                 mylog.info("【{0}】启动录制成功".format(__title__))
             except:
                 mylog.info("【{0}】启动录制失败".format(__title__))
             try:
                 self.runcase(self.Runlist_dir[k])
                 self.Case_info[k]["repeattime"] = 0
             except Exception as e:
                 sleep(1)
                 mylog.error("------第出现异常", e)
                 log(e, "------出现异常----------")
                 self.resetEnv(k)
             finally:
                 self.partReport(htmlname=htmlname,
                                 __title__=__title__,
                                 k=k)
                 try:
                     stop_record(recordfile)
                     mylog.info("【{0}】生成录制文件成功".format(__title__))
                 except:
                     mylog.info("【{0}】生成录制文件失败".format(__title__))
예제 #5
0
 def bookLoad(self,bookid=None):
     """书籍加载"""
     if self.find_try("DefaultBg", description="书籍加载界面", waitTime=3, tryTime=3):
         startime = time.time()
         while self.poco("DefaultBg").wait(3).exists():
             loadtime = time.time() - startime
             if MyData.UserData_dir["bookDetailInfo"]["BookID"]:
                 MyData.download_bookresource(MyData.UserData_dir["bookDetailInfo"]["BookID"])
             else:
                 MyData.UserData_dir["bookDetailInfo"]["BookID"]=bookid
                 MyData.download_bookresource(bookid)
             sleep(3)
             if self.find_try("Discover",description="是否返回大厅",waitTime=1):
                 mylog.error("加载书籍异常")
                 log(Exception("加载书籍异常,自动返回到大厅"),snapshot=True)
                 raise Exception("加载书籍异常,自动返回到大厅")
             print("书籍加载中", loadtime)
             if loadtime > 360:
                 self.findClick_object("HomeBtn", "HomeBtn", description="加载书籍超时,返回大厅")
                 mylog.error("加载书籍超时")
                 log(loadtime, timestamp=time.time(), desc="加载书籍超时", snapshot=True)
                 raise Exception("加载书籍超时")
         loadtime = time.time() - startime
         self.BookLoad_info["书籍加载时间:"]=loadtime
         print("完成书籍加载,加载时间为{0}秒".format(loadtime))
         log(loadtime, timestamp=time.time(), desc="完成书籍加载", snapshot=True)
     return True
예제 #6
0
 def getChapterEdit_info(self):
     try:
         stroyTitle = self.poco("TxtTitle").get_TMPtext()
         stroyDescript = self.poco("TxtDescript").get_TMPtext()
         stroyStatus = self.poco("TxtStatus").get_TMPtext()
         self.ChapterEdit_info["stroyTitle"] = stroyTitle
         self.ChapterEdit_info["stroyDescript"] = stroyDescript
         self.ChapterEdit_info["stroyStatus"] = stroyStatus
     except:
         mylog.error("等待-【{}】-元素可见超时".format("书籍详情信息"))
예제 #7
0
    def Popo_Errorinfo(self):
        if self.android_tryfind("android:id/button1", description="Google提示"):
            self.android_findClick("android:id/button1",
                                   "android:id/button1",
                                   description="Google框架提示处理")
            mylog.error("检测到未安装谷歌框架,无法执行相关操作")
        if self.find_try("Context", description="加载中..."):
            TXT = self.poco("Context").get_TMPtext()
            self.GameLoaded_info["ErrorTxt"].append(TXT)
            self.click_object("CenterBtn", description="Try again", waitTime=5)
            mylog.info("异常弹框,{0}".format(TXT))


# GameLoaded1=GameLoaded()
# GameLoaded1.Popo_Errorinfo()
예제 #8
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))
예제 #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 writelogs(self):
     """转存log到logs"""
     try:
         log_file = open(self.logpath, "r")
         logs_file = open(self.logspath, "a")
         lines = log_file.readlines()
         for val in range(len(lines)):
             # alllog_file = open(alllogspath, "a")
             # alllog_file.write(lines[val])
             # if "assert_equal" in lines[val] or "traceback" in lines[val]:
             logs_file.write(lines[val])
     except Exception as e:
         print("转存log到logs失败", e)
         mylog.error("转存log到logs失败", e)
     else:
         print("转存log到logs成功")
         mylog.info("转存log到logs成功")
     finally:
         log_file.close()
         logs_file.close()
예제 #11
0
 def notchfit__Click_try(self,
                         findName,
                         ClickName,
                         description="",
                         waitTime=0.5,
                         tryTime=1,
                         sleeptime=0,
                         log=True,
                         POCOtype=None):
     """解决上部分黑屏问题,更改渲染"""
     if POCOtype == "Androidpoco":
         poco = self.androidpoco
     else:
         poco = self.poco
         # ADBdevice=MyData.EnvData_dir["ADBdevice"]
         # if ADBdevice in MyData.mobileconf_dir["Notch_Fit"]:
         #     poco.use_render_resolution(True, MyData.mobileconf_dir["Notch_Fit"][ADBdevice])
     try:
         print("尝试寻找{0}".format(description))
         # gameobject = self.poco(findName)
         if poco(findName).wait(waitTime).exists():
             print("发现{0}".format(description))
             # if ADBdevice in MyData.mobileconf_dir["Notch_Fit"]:
             #     poco.use_render_resolution(True, MyData.mobileconf_dir["Notch_Fit"][ADBdevice])
             if poco(ClickName).wait(waitTime + 1).exists():
                 print("发现{0}按钮,并点击".format(ClickName))
                 poco(ClickName).click()
                 sleep(sleeptime)
                 self.Popuplist.append(description)
                 mylog.info("尝试点击-【{}】-元素成功并加入弹框列表".format(description))
                 # poco.use_render_resolution(False, MyData.mobileconf_dir["Notch_Fit"][ADBdevice])
                 return True
             else:
                 mylog.info("尝试点击-【{}】-元素失败".format(description))
                 print("未触发点击")
     except:
         log(Exception("点击-【{}】-元素失败".format(description)),
             desc="点击元素失败",
             snapshot=True)
         mylog.error("尝试点击-【{}】-元素失败".format(description))
         return False
예제 #12
0
 def progressjudge(self, achatProgress):
     readprogress = MyData.getreadprogress(
         self.ReadBook_info["BookID"])  # 获取当前进度
     self.ReadBook_info["chatProgress"] = readprogress[
         self.ReadBook_info["BookID"]]["chatProgress"]
     print("点击后进度:", self.ReadBook_info["chatProgress"])
     if achatProgress == str(self.ReadBook_info["chatProgress"]):
         self._etime = self._etime + 1
         if self._etime >= 2:
             self._etime = 0
             self.ReadBook_info["异常次数"] = self.ReadBook_info["异常次数"] + 1
             print("卡顿或异常次数:", self.ReadBook_info["异常次数"])
             if self.ReadBook_info["异常次数"] > 50:
                 print("卡顿或异常次数较多", self.ReadBook_info["异常次数"])
                 mylog.error("异常次数过多读书可能卡死")
                 log(Exception("异常次数过多读书可能卡死"), snapshot=True)
                 raise Exception
                 return False
     else:
         print("正常点击")
         self._etime = 0
예제 #13
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))
예제 #14
0
 def findClick_try(self,
                   findName,
                   ClickName,
                   description="",
                   waitTime=0.5,
                   tryTime=1,
                   sleeptime=0,
                   log=True,
                   pocotype=None):
     """尝试寻找并点击,不一定存在"""
     if pocotype == "Androidpoco":
         poco = self.androidpoco
     else:
         poco = self.poco
     try:
         print("尝试寻找{0}".format(description))
         # gameobject = self.poco(findName)
         if poco(findName).wait(waitTime).exists():
             print("发现{0}".format(description))
             if poco(ClickName).wait(waitTime + 1).exists():
                 print("发现{0}按钮,并点击".format(ClickName))
                 poco(ClickName).click()
             else:
                 mylog.info("尝试点击-【{}】-元素失败".format(description))
                 print("未触发点击")
     except:
         log(Exception("点击-【{}】-元素失败".format(description)),
             desc="点击元素失败",
             snapshot=True)
         mylog.error("尝试点击-【{}】-元素失败".format(description))
         return False
     else:
         sleep(sleeptime)
         self.Popuplist.append(description)
         mylog.info("尝试点击-【{}】-元素成功并加入弹框列表".format(description))
         return True
예제 #15
0
                try:
                    self.runcase(self.Runlist_dir[k])
                    self.Case_info[k]["repeattime"] = 0
                except Exception as e:
                    sleep(1)
                    mylog.error("------第出现异常", e)
                    log(e, "------出现异常----------")
                    self.resetEnv(k)
                finally:
                    self.partReport(htmlname=htmlname,
                                    __title__=__title__,
                                    k=k)
                    try:
                        stop_record(recordfile)
                        mylog.info("【{0}】生成录制文件成功".format(__title__))
                    except:
                        mylog.info("【{0}】生成录制文件失败".format(__title__))


if __name__ == '__main__':
    try:
        myRun = Run()
        myRun.initialize()
        myRun.runing()
    except Exception as e:
        mylog.error("------出现异常{}", e)
        log(e, "------出现异常--------")
    # myRun.pull_errorLog()
    # myRun.writelogs()
    myRun.togetherReport()
예제 #16
0
 def buy_member_step(self):
     """购买会员步骤"""
     MyData.getUsermemberinfo()
     mylog.info("用户信息【{}】".format(MyData.UserData_dir))
     MyData.UserData_dir["member_type_old"] = MyData.UserData_dir[
         "member_type"]
     self.swipe_diamonds()
     self.click_buy_member()
     if self.poco(nameMatches=".*SubBtn").wait(5).exists():
         self.click_subs()  #点击订阅会员按钮
         time.sleep(2)
         self.dealwith_error()
         self.mysleep(5)
         self.click_subscribed()
         boolis = True
         clock()
         while boolis:
             if self.android_tryfind("android.widget.RadioButton",
                                     description="购买身份验证",
                                     waitTime=2):
                 androidpoco = self.androidpoco(
                     "android.widget.RadioButton")[0]
                 self.findClick_childobject(androidpoco,
                                            description="一律启用",
                                            waitTime=1,
                                            sleeptime=1)
                 self.mysleep(3)
                 self.click_affirm()
             time.sleep(5)
             try:
                 self.poco("BtnReturn").click()
                 boolis = False
                 print("订阅后点击返回按钮")
                 mylog.info("订阅后点击返回按钮")
             except:
                 pass
             mytime = float(clock("stop"))
             if mytime > 30:
                 mylog.error("未发现订阅返回按钮")
                 log(Exception("未发现订阅返回按钮"), snapshot=True)
         try:
             self.click_top_back()
         except:
             pass
         try:
             self.click_top_back()
         except:
             pass  # 购买完后的用户数据
         MyData.getUsermemberinfo()
         mylog.info("用户会员状态:【{}】".format(MyData.UserData_dir))
         self.Shopmodule_info["member_type"] = MyData.UserData_dir[
             "member_type"]
         self.Shopmodule_info["member_type_old"] = MyData.UserData_dir[
             "member_type_old"]
         return self.Shopmodule_info
     else:
         self.click_topbackbtn()
         self.click_top_back()
         MyData.getUsermemberinfo()
         mylog.info("用户会员状态:【{}】".format(MyData.UserData_dir))
         self.Shopmodule_info["member_type"] = MyData.UserData_dir[
             "member_type"]
         self.Shopmodule_info["member_type_old"] = MyData.UserData_dir[
             "member_type_old"]
         return self.Shopmodule_info