def _to_json(self):
     result = False
     try:
         self.command_json = json.loads(self.command_string)
         result = True
     except JSONDecodeError as e:
         self.exception = error_log("json 命令格式解析错误:", e)
         #self.exception = "json 命令格式解析错误:" + str(e)
         #self.exception_list.append(error_log("json 命令格式解析错误:", e))
     except BaseException as e:
         self.exception = error_log("json 命令解析错误:", e)
         #self.exception = "json 命令格式解析错误:"  + str(e)
         #self.exception_list.append(error_log("json 命令解析错误:", e))
     else:
         pass
     return result
 def _json_to_command_ui(self, json_object):
     command = Command(command = json.dumps(json_object,ensure_ascii=False))
     if json_object.__contains__('element'):
         element = json_object['element']
         element_dict = self.parse_ui_element(element)
         command.element = element
         command.element_selector = element_dict['element_selector']
         command.element_value = element_dict['element_value']
     if json_object.__contains__('value'):
         if not json_object.__contains__('element'):
             self.exception = error_log("无法定位,存在value元素,但没有element元素")
             return
         command.value = json_object['value']
     if json_object.__contains__('action'):
         command.action = self.parse_ui_action(json_object['action'])
     return command
 def parse_ui_element(self, element):
     element_dict = {}
     if element is not None:
         try:
             args = element.split('=')
             element_dict = {
                 'element_selector' : args[0],
                 'element_value' : args[1]
             }
         except BaseException as e:
             self.exception = error_log("element 元素不符合规范: " + element , e)
             #self.exception = "element 元素不符合规范: " + element + str(e)
             #self.exception_list.append(error_log("element 元素不符合规范: " + element , e))
         else:
             pass
     return element_dict
 def validate(self):
     for json in self.command_json:
         for k,v in json.items():
             if not self.keywords.__contains__(k):
                 self.exception = error_log("json 命令解析错误,无法解析的命令关键字:"+ k)
                 return
 def create_error(self, command=None, e=None, message='出错'):
     self.fail_log = error_log(
         '页面:' + str(self.driver.current_url) + " " +
         ('' if command is None else "命令:" + command.command) + message, e)