示例#1
0
    def check_bookshelf(self, topic):
        size_s = copy.deepcopy(device_info.device_screen_real)
        width_s = size_s[2]
        size_p1 = [0, 40, width_s, 210]  # 书架头部
        size_p2 = [0, 266, width_s, 660]
        check_title = self.aw.get_par_list(topic)[1]

        rate1 = picture.pic_operate(check_title + "_p1", self.aw.is_update_pic(self.aw.get_marker(topic)), size_p1,
                                    self.driver)
        rate2 = picture.pic_operate(check_title + "_p2", self.aw.is_update_pic(self.aw.get_marker(topic)), size_p2,
                                    self.driver)
        # 重试一次
        picture.is_reCompare = 1
        if rate1 < 99 or rate2 < 99:
            sleep(3)
            rate1 = picture.pic_operate(check_title + "_p1", self.aw.is_update_pic(self.aw.get_marker(topic)), size_p1,
                                        self.driver)
            rate2 = picture.pic_operate(check_title + "_p2", self.aw.is_update_pic(self.aw.get_marker(topic)), size_p2,
                                        self.driver)

        logger.info("相似度 p1: " + str(rate1) + " p2: " + str(rate2))
        picture.is_reCompare = 0
        if rate1 > 99 and rate2 > 99:
            logger.info(check_title + ": pass")
        else:
            #上报失败结果
            result.set_check_result(check_title)
 def check_ele(self, topic):
     """
     校验控件是否存在
     eg: topic = check_ele:element_name:TC_003  检查是否存在name为element_name的控件
     """
     self.driver.implicitly_wait(5)
     check_title = self.get_par_list(topic)[2]
     try:
         self.driver.find_element_by_name(self.get_par_list(topic)[1])
     except Exception,ex:
         result.set_check_result(check_title)
 def check(self, topic):
     """
     图片校验
     eg1: topic = check:TC_001 按默认比例截图对比
     eg2: topic = check:0,0,0.5,1:TC_002 按起点坐标比例 0,0 终点坐标比例 0.5,1截图对比
     eg3: eg2: topic = check:element_name:TC_002 截取name为element_name的控件截图
     """
     size = []
     case_title = ""
     if self.get_par_list(topic).__len__() == 2:
         #默认截图
         size = copy.deepcopy(device_info.device_screen_real)
         size[1] = size[3]*40/1136
         size[3] = size[3] - (size[1]*2)
         case_title = self.get_par_list(topic)[1]
     elif self.get_par_list(topic).__len__() == 3:
         #ele截图 或 比例截图
         case_title = self.get_par_list(topic)[2]
         if self.get_par_list(topic)[1].split(",", 5).__len__() == 4:
             scale = copy.deepcopy(self.get_par_list(topic)[1].split(",", 5))
             size = copy.deepcopy(device_info.device_screen_real)
             size[0] = int(size[2]*string.atof(scale[0]))
             size[1] = int(size[3]*string.atof(scale[1]))
             size[2] = int(size[2]*string.atof(scale[2])) - size[0]
             size[3] = int(size[3]*string.atof(scale[3])) - size[1]
         else:
             el1 = self.driver.find_element_by_name(self.get_par_list(topic)[1])
             size.append(el1.location["x"]*device_info.device_scaling)
             size.append(el1.location["y"]*device_info.device_scaling)
             size.append(el1.size["width"]*device_info.device_scaling)
             size.append(el1.size["height"]*device_info.device_scaling)
     rate = picture.pic_operate(case_title, self.is_update_pic(self.get_marker(topic)), size, self.driver)
     #重试一次
     #上报重试
     picture.is_reCompare = 1
     if rate < 99:
         sleep(3)
         rate = picture.pic_operate(case_title, self.is_update_pic(self.get_marker(topic)), size, self.driver)
     print rate
     logger.info("相似度: " + str(rate))
     picture.is_reCompare = 0
     if rate > 99:
         logger.info(case_title + " check pass")
     else:
         result.set_check_result(case_title)
    def test_act(self, file_path = None, ui_case = None):
        #ui_case=0 时用例为release.xmind,为1时用例为test.xmind
        logger = self.log_init()

        case = test_case.Tcase(ui_case=int(ui_case))
        ac = action.Action()

        for i in range(1, case.caseCount + 1):
            try:
                marker = case.getCaseList(i)[0].getMarkers()[0].getMarkerId().name
            except Exception,ex:
                marker = "None"
                logger.info("no Marker")
            #上报当前执行用例名
            exe_status.exe_case_title = ActionWord.get_par_list(case.getCaseList(i)[0])[1]

            if marker != "flag-red":
                #初始化setting
                self.fs.restore()
                self.driver.reset()
                #上报用例目的
                if case.getCaseList(i)[0].getNotes() == None:
                    print "无测试备注"
                else:
                    result.case_purpose[exe_status.exe_case_title] = case.getCaseList(i)[0].getNotes().getContent()

                for p in case.getCaseList(i)[::-1]:
                    try:
                        exe_status.exe_path += p.getTitle() + " -> "
                        logger.info(p.getTitle())
                        ac.action_do(self.driver, p)
                        #上报结果
                        result.set_pass_result(exe_status.exe_case_title)
                    except Exception,ex:
                        info=sys.exc_info()
                        err_str = p.getTitle() + ": " + str(info[1])
                        logger.error(msg=err_str)
                        #上报错误
                        result.set_check_result(exe_status.exe_path)
                        break
                exe_status.exe_path = ""
                sleep(2)