Esempio n. 1
0
 def refresh_time_difference(self, operate):
     time_out = int(operate["time_out"])
     cs_time = 0
     s_time = time.time()
     while time_out > cs_time:
         self.driver.refresh()
         time.sleep(1)
         # self.driver.implicitly_wait(3)
         new_text = self.get_text(operate)["text"]
         if (time.time() -
                 to_time_stamp(f_time=new_text)) < operate["max_time"]:
             return {'result': True, 'text': new_text}
         # time.sleep(1)
         cs_time = int(time.time() - s_time)
     return {'result': False, 'text': new_text}
Esempio n. 2
0
    def check(self):
        result = True
        if self.isOperate:
            for i in self.testcheck:
                self.rw_get_value(i)  # 执行读写容器操作

                try:
                    if i.get('expect_value', '888')[-3:] == '+拼接':
                        regex = ".*拼接值(.*)\+拼.*"
                        matches = re.findall(regex, i['expect_value'])
                        if len(matches) == 1:
                            for match in matches:
                                print(match)
                                if match[:3] == "前+后":
                                    i['expect_value'] = i['expect_value'].split(
                                        "拼接值")[0] + match[3:]
                                elif match[:3] == "后+前":
                                    if match == '后+前host':
                                        i['expect_value'] = ElementParam.HOST + i[
                                            'expect_value'].split("拼接值")[0]
                                    else:
                                        i['expect_value'] = match[3:] + i[
                                            'expect_value'].split("拼接值")[0]
                        else:
                            print('expect_value值没有被正则表达式匹配到,正则表达式匹配到的值为:',
                                  matches)
                            result = False
                            break
                except TypeError as msg:
                    print("打印type错误", msg)

                op_re = self.operateElement.operate(i, self.testInfo,
                                                    self.logTest)  #  等于result

                if not op_re['result'] and (i.get(
                        'check', ElementParam.DEFAULT_CHECK) !=
                                            ElementParam.CONTRARY):
                    msg = get_error_info({
                        'type': ElementParam.DEFAULT_ERROR,
                        'element_info': i['element_info']
                    })
                    self.testInfo[0]['msg'] = msg
                    return False

                # 默认检查点,检查元素存在
                if i.get(
                        'check', ElementParam.DEFAULT_CHECK
                ) == ElementParam.DEFAULT_CHECK and not op_re['result']:
                    msg = get_error_info({
                        "type": ElementParam.DEFAULT_CHECK,
                        "element_info": i['element_info'],
                        "info": i['info']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    return result

                L = [
                    ElementParam.CONTRARY, ElementParam.VESSEL_CONTAIN_CURRENT,
                    ElementParam.VESSEL_NOT_CONTAIN_CURRENT,
                    ElementParam.CURRENT_CONTAIN_EXPECT,
                    ElementParam.CURRENT_EQUAL_EXPECT,
                    ElementParam.VESSEL_NOT_CONTAIN_EXPECT,
                    ElementParam.VESSEL_CONTAIN_EXPECT, ElementParam.DISPLAYED,
                    ElementParam.NOT_DISPLAYED, ElementParam.TIME_DIFFERENCE,
                    ElementParam.CURRENT_NOT_EQUAL_EXPECT
                ]
                if i.get("check", 'ooo') not in L and i.get(
                        'check', ElementParam.DEFAULT_CHECK
                ) != ElementParam.DEFAULT_CHECK:
                    msg = get_error_info({
                        'type': ElementParam.VALUE_ERROR,
                        'value': i['check'],
                        'info': i['info']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break

                # 检查 元素不存在
                if i.get('check', ElementParam.DEFAULT_CHECK
                         ) == ElementParam.CONTRARY and op_re['result']:
                    msg = get_error_info({
                        'type': ElementParam.CONTRARY,
                        'element': i['element_info'],
                        'info': i['info']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 容器  包含  当前值
                if i.get(
                        'check', ElementParam.DEFAULT_CHECK
                ) == ElementParam.VESSEL_CONTAIN_CURRENT and self.is_get and op_re.get(
                        "text", "ooooooo没获取到textoooooooo"
                ) not in self.get_value[i['expect_index']]:
                    msg = get_error_info({
                        'type':
                        ElementParam.VESSEL_CONTAIN_CURRENT,
                        'history':
                        self.get_value,
                        'info':
                        i['info'],
                        'current':
                        op_re.get("text", "ooooooo没获取到textoooooooo")
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 容器 不包含 当前值
                if i.get(
                        'check', ElementParam.DEFAULT_CHECK
                ) == ElementParam.VESSEL_NOT_CONTAIN_CURRENT and self.is_get and op_re[
                        'text'] in self.get_value[i['expect_index']]:
                    msg = get_error_info({
                        'type': ElementParam.VESSEL_NOT_CONTAIN_CURRENT,
                        'history': self.get_value,
                        'info': i['info'],
                        'current': op_re['text']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 当前值 包含 预期值
                if i.get('check', ElementParam.DEFAULT_CHECK
                         ) == ElementParam.CURRENT_CONTAIN_EXPECT and i.get(
                             'expect_value', 'ooo') not in op_re['text']:
                    msg = get_error_info({
                        'type':
                        ElementParam.CURRENT_CONTAIN_EXPECT,
                        'info':
                        i['info'],
                        'get_value':
                        op_re['text'],
                        'expect_value':
                        i.get('expect_value', 'ooo')
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 当前值 等于 预期值
                try:
                    if i.get('check', ElementParam.DEFAULT_CHECK
                             ) == ElementParam.CURRENT_EQUAL_EXPECT and op_re[
                                 'text'] != i.get('expect_value', 'ooo'):
                        msg = get_error_info({
                            'type':
                            ElementParam.CURRENT_EQUAL_EXPECT,
                            'info':
                            i['info'],
                            'get_attr':
                            op_re['text'],
                            'expect_value':
                            i.get('expect_value', 'ooo')
                        })
                        self.testInfo[0]['msg'] = msg
                        result = False
                        break
                except KeyError as e:
                    if 'size' in op_re:
                        print("当前步骤为测试size")
                    else:
                        print(e)

                    if i.get('check', ElementParam.DEFAULT_CHECK
                             ) == ElementParam.CURRENT_EQUAL_EXPECT and op_re[
                                 'size'] != i.get('expect_value', 0):
                        msg = get_error_info({
                            'type':
                            ElementParam.CURRENT_EQUAL_EXPECT,
                            'info':
                            i['info'],
                            'get_attr':
                            op_re['size'],
                            'expect_value':
                            i.get('expect_value', 'ooo')
                        })
                        self.testInfo[0]['msg'] = msg
                        result = False
                        break
                # 当前值 不等于 预期值
                if i.get('check', ElementParam.DEFAULT_CHECK
                         ) == ElementParam.CURRENT_NOT_EQUAL_EXPECT and op_re[
                             'text'] == i.get('expect_value', 'ooo'):
                    msg = get_error_info({
                        'type':
                        ElementParam.CURRENT_NOT_EQUAL_EXPECT,
                        'info':
                        i['info'],
                        'get_attr':
                        op_re['text'],
                        'expect_value':
                        i.get('expect_value', 'ooo')
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 容器 不包含 预期值
                if i.get('check', ElementParam.DEFAULT_CHECK) == ElementParam.VESSEL_NOT_CONTAIN_EXPECT and self.is_get \
                        and contain_str(i['expect_value'], self.get_value, i.get('expect_index', 0)):
                    msg = get_error_info({
                        'type': ElementParam.VESSEL_NOT_CONTAIN_EXPECT,
                        'history': self.get_value,
                        'info': i['info'],
                        'current': i['expect_value']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 容器 包含 预期值
                if i.get('check', ElementParam.DEFAULT_CHECK) == ElementParam.VESSEL_CONTAIN_EXPECT and self.is_get \
                        and contain_not_str(i['expect_value'], self.get_value, i.get('expect_index', 0)):
                    msg = get_error_info({
                        'type': ElementParam.VESSEL_CONTAIN_EXPECT,
                        'history': self.get_value,
                        'info': i['info'],
                        'current': i['expect_value']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 检查页面元素显示  如果 不显示就返回False
                if i.get('check', ElementParam.DEFAULT_CHECK
                         ) == ElementParam.DISPLAYED and not op_re['result']:
                    msg = get_error_info({
                        'type': ElementParam.DISPLAYED,
                        'info': i['info'],
                        'element': i['element_info']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 检查页面元素不显示  如果 显示就返回False
                if i.get('check', ElementParam.DEFAULT_CHECK
                         ) == ElementParam.NOT_DISPLAYED and op_re['result']:
                    msg = get_error_info({
                        'type': ElementParam.NOT_DISPLAYED,
                        'info': i['info'],
                        'element': i['element_info']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                # 检查有时间差小于预期时间
                if i.get(
                        'check', ElementParam.DEFAULT_CHECK
                ) == ElementParam.TIME_DIFFERENCE and (
                        time.time() -
                        to_time_stamp(f_time=op_re.get("text", 0))) > i.get(
                            'max_time', 5):
                    print(time.time() -
                          to_time_stamp(f_time=op_re.get("text", 0)))
                    msg = get_error_info({
                        'type': ElementParam.TIME_DIFFERENCE,
                        'info': i['info']
                    })
                    self.testInfo[0]['msg'] = msg
                    result = False
                    break
                if i.get('is_time', 0) != 0:
                    sleep(i['is_time'])
        else:
            result = False
        return result