def operate(self): if self.test_msg[0] is False: self.isOperate = False return False self.operateElement = OperateElement(self.driver) for item in self.testCase: result = self.operateElement.operate(item, self.testInfo, self.logTest) if not result["result"]: msg = get_error({ "type": be.DEFAULT_ERROR, "element_info": item["element_info"] }) print(msg) self.testInfo[0]["msg"] = msg self.isOperate = False return False if item.get("is_time", "0") != "0": time.sleep(item["is_time"]) # 等待时间 print("==等待%s秒==" % item["is_time"]) if item.get("operate_type", "0") == be.GET_VALUE or item.get( "operate_type", "0") == be.GET_TEXT: self.get_value.append(result["text"]) self.is_get = True # 对比数据 return True
def check(self, kwargs): result = True m_s_g = self.msg + "\n" if self.msg != "" else "" # 如果有重跑机制,成功后会默认把日志传进来 # if kwargs.get("check_point", "0") != "0": 自定义检查点 # return kwargs["check_point"] if self.isOperate: for item in self.testcheck: if kwargs.get("check", be.DEFAULT_CHECK) == be.TOAST: result = \ self.operateElement.toast(item["element_info"], testInfo=self.testInfo, logTest=self.logTest)[ "result"] if result is False: m = get_error({ "type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: resp = self.operateElement.operate(item, self.testInfo, self.logTest, self.device) if kwargs.get("check", be.DEFAULT_CHECK ) == be.DEFAULT_CHECK and not resp["result"]: m = get_error({ "type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break else: result = False return result
def check(self, kwargs): result = True m_s_g = self.msg + "\n" if self.msg != "" else "" # 如果有重跑机制,成功后会默认把日志传进来 # if kwargs.get("check_point", "0") != "0": 自定义检查点 # return kwargs["check_point"] if self.isOperate: for item in self.testcheck: if item.get("check", be.DEFAULT_CHECK) == be.TOAST: result = \ self.operateElement.toast(item["element_info"], testInfo=self.testInfo, logTest=self.logTest)[ "result"] if result is False: m = get_error({ "type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: resp = self.operateElement.operate(item, self.testInfo, self.logTest, self.device) if item.get("check", be.DEFAULT_CHECK ) == be.DEFAULT_CHECK and not resp["result"]: m = get_error({ "type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break if item.get( "check", be.DEFAULT_CHECK) == be.CONTRARY and resp["result"]: m = get_error({ "type": be.CONTRARY, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = self.msg result = False break # 检查点关键字contrary_getval: 相反值检查点,如果对比成功,说明失败 if item.get("check", be.DEFAULT_CHECK) == be.CONTRARY_GETVAL and self.is_get and resp["result"] \ in self.get_value: m = get_error({ "type": be.CONTRARY_GETVAL, "current": item["element_info"], "history": resp["text"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break print(resp) if item.get("check", be.DEFAULT_CHECK ) == be.COMPARE and self.is_get and resp.get( "text", "NoSuchElementError") != str( item["msg"]): # 历史数据和实际数据对比 result = False m = get_error({ "type": be.COMPARE, "current": resp.get("text", "NoSuchElementError"), "expectValue": item["msg"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: result = False return result
def check(self, kwargs): ''' 检查点 caseName:测试用例函数名 用作统计 logTest: 日志记录 devices 设备名 contrary:相反检查点,传1表示如果检查元素存在就说明失败 toast: 表示提示框检查点 contrary_getval: 相反值检查点,如果对比成功,说明失败 check_point: 自定义检查结果 ''' result = True m_s_g = self.msg + "\n" if self.msg != "" else "" # 如果有重跑机制,成功后会默认把日志传进来 # if kwargs.get("check_point", "0") != "0": 自定义检查点 # return kwargs["check_point"] if self.isOperate: for item in self.testcheck: if kwargs.get("check", be.DEFAULT_CHECK) == be.TOAST: result = \ self.operateElement.toast(item["element_info"], testInfo=self.testInfo, logTest=self.logTest)[ "result"] if result is False: m = get_error( {"type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: resp = self.operateElement.operate(item, self.testInfo, self.logTest, self.device) if kwargs.get("check", be.DEFAULT_CHECK) == be.DEFAULT_CHECK and not resp["result"]: m = get_error( {"type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break if kwargs.get("check", be.DEFAULT_CHECK) == be.CONTRARY and resp["result"]: m = get_error({"type": be.CONTRARY, "element_info": item["element_info"], "info": item["info"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = self.msg result = False break # 检查点关键字contrary_getval: 相反值检查点,如果对比成功,说明失败 if kwargs.get("check", be.DEFAULT_CHECK) == be.CONTRARY_GETVAL and self.is_get and resp["result"] \ in self.get_value: m = get_error( {"type": be.CONTRARY_GETVAL, "current": item["element_info"], "history": resp["text"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break if kwargs.get("check", be.DEFAULT_CHECK) == be.COMPARE and self.is_get and resp["text"] \ not in self.get_value: # 历史数据和实际数据对比 result = False m = get_error({"type": be.COMPARE, "current": item["element_info"], "history": resp["text"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: result = False return result
def check(self, kwargs): result = True m_s_g = self.msg + "\n" if self.msg != "" else "" # 如果有重跑机制,成功后会默认把日志传进来 # if kwargs.get("check_point", "0") != "0": 自定义检查点 # return kwargs["check_point"] if self.isOperate: for item in self.testcheck: if kwargs.get("check", be.DEFAULT_CHECK) == be.TOAST: result = \ self.operateElement.toast(item["element_info"], testInfo=self.testInfo, logTest=self.logTest)[ "result"] if result is False: m = get_error( {"type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: resp = self.operateElement.operate(item, self.testInfo, self.logTest, self.device) if kwargs.get("check", be.DEFAULT_CHECK) == be.DEFAULT_CHECK and not resp["result"]: m = get_error( {"type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break if kwargs.get("check", be.DEFAULT_CHECK) == be.CONTRARY and resp["result"]: m = get_error({"type": be.CONTRARY, "element_info": item["element_info"], "info": item["info"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = self.msg result = False break # 检查点关键字contrary_getval: 相反值检查点,如果对比成功,说明失败 if kwargs.get("check", be.DEFAULT_CHECK) == be.CONTRARY_GETVAL and self.is_get and resp["result"] \ in self.get_value: m = get_error( {"type": be.CONTRARY_GETVAL, "current": item["element_info"], "history": resp["text"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break if kwargs.get("check", be.DEFAULT_CHECK) == be.COMPARE and self.is_get and resp["text"] \ not in self.get_value: # 历史数据和实际数据对比 result = False m = get_error({"type": be.COMPARE, "current": item["element_info"], "history": resp["text"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: result = False return result
def check(self, kwargs): result = True m_s_g = self.msg + "\n" if self.msg != "" else "" # 如果有重跑机制,成功后会默认把日志传进来 # if kwargs.get("check_point", "0") != "0": 自定义检查点 # return kwargs["check_point"] if self.isOperate: for item in self.testcheck: #如果check的值为toast,则检查点为toast,否则为默认检查点 print("-------start checking-----------") print(item.get("check")) print("-----------end check------------") if item.get("check", be.DEFAULT_CHECK) == be.TOAST: result = \ self.operateElement.toast(item["element_info"], testInfo=self.testInfo, logTest=self.logTest)[ "result"] if result is False: m = get_error({ "type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m break else: #调用BaseOperate里的operateElement.operate方法,传入检查点check的信息,operate()方法会调用findElement方法 #如果findElement方法找到元素会return true,又因为检查点信息check里没有operate_type字段,operate_by方法会直接将此判定为true #不执行元素操作,所以此处的调用就是完成 查找默认检查点是否存在的操作 resp = self.operateElement.operate(item, self.testInfo, self.logTest, self.device) #如果找到元素,resp["result"]为Ture,not resp["result"]就是false if item.get("check", be.DEFAULT_CHECK ) == be.DEFAULT_CHECK and not resp["result"]: m = get_error({ "type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break #如果找到这个元素,就是检查失败 if item.get( "check", be.DEFAULT_CHECK) == be.CONTRARY and resp["result"]: m = get_error({ "type": be.CONTRARY, "element_info": item["element_info"], "info": item["info"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = self.msg result = False break # 检查点关键字contrary_getval: 相反值检查点,如果对比成功,说明失败 if item.get("check", be.DEFAULT_CHECK) == be.CONTRARY_GETVAL and self.is_get and resp["result"] \ in self.get_value: m = get_error(\ {"type": be.CONTRARY_GETVAL, "current": item["element_info"], "history": resp["text"]}) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break if item.get("check", be.DEFAULT_CHECK) == be.COMPARE and self.is_get and resp["text"] \ not in self.get_value: # 历史数据和实际数据对比 m = get_error({ "type": be.COMPARE, "current": item["element_info"], "history": resp["text"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break #文本检查点,如果元素的text文本和设置的msg不想等,则判定为失败 if item.get("check", be.DEFAULT_CHECK ) == be.TEXT_CHECK and resp["text"] == item["msg"]: m = get_error({ "type": be.TEXT_CHECK, "flag": item["msg"], "current": resp["text"] }) self.msg = m_s_g + m print(m) self.testInfo[0]["msg"] = m result = False break else: result = False return result
def check(self, kwargs): result = True # if kwargs.get("check_point", "0") != "0": # return kwargs["check_point"] if self.isOperate: for item in self.test_check: resp = self.operateElement.operate(item, self.testInfo, self.logTest) # 默认检查点,就是查找页面元素 if kwargs.get("check", be.DEFAULT_CHECK ) == be.DEFAULT_CHECK and not resp["result"]: m = get_error({ "type": be.DEFAULT_CHECK, "element_info": item["element_info"], "info": item["info"] }) print(m) self.testInfo[0]["msg"] = m result = False break # 历史数据和实际数据对比 if kwargs.get("check", be.DEFAULT_CHECK) == be.COMPARE and self.is_get and resp["text"]\ not in self.get_value: # 历史数据和实际数据对比 result = False m = get_error({ "type": be.COMPARE, "current": item["element_info"], "history": resp["text"] }) print(m) self.testInfo[0]["msg"] = m break # 相反检查点,表示如果检查元素存在就说明失败,如删除后,此元素依然存在 if kwargs.get( "check", be.DEFAULT_CHECK) == be.CONTRARY and resp["result"]: m = get_error({ "type": be.CONTRARY, "element_info": item["element_info"], "info": item["info"] }) print(m) self.testInfo[0]["msg"] = m result = False break # 检查点关键字contrary_getval: 相反值检查点,如果对比成功,说明失败 if kwargs.get("check", be.DEFAULT_CHECK) == be.CONTRARY_GETVAL and self.is_get and resp["result"] \ in self.get_value: m = get_error({ "type": be.CONTRARY_GETVAL, "current": item["element_info"], "history": resp["text"] }) print(m) self.testInfo[0]["msg"] = m result = False break else: result = False return result