def traceback(self, errtype, e, tb): # tb1 用来获取最近报错调用帧栈 # tb用来format一个完整的tb # 去到离现场最近的tb位置 tb1 = tb tb_stack = [tb1] while tb1.tb_next: tb1 = tb1.tb_next tb_stack.append(tb1) # 跳过unittest相关的tb frame while tb and '__unittest' in tb.tb_frame.f_globals: tb = tb.tb_next lineno, srcfilename = None, None if tb: while tb_stack: lineno, srcfilename = get_current_lineno_of(self.collector.get_testcases_filenames(), tb_stack.pop().tb_frame) if srcfilename: break if srcfilename: srcfilename = os.path.relpath(srcfilename, self.collector.get_project_root_path()) formatted_tb = ''.join(traceback.format_exception(errtype, e, tb)) else: formatted_tb = '' self.emit(self.TAG, {'method': 'traceback', 'errtype': errtype.__name__, 'traceback': formatted_tb, 'lineno': lineno, 'srcfilename': srcfilename})
def click(self, tid, pos, desc): lineno, srcfilename = get_current_lineno_of( self.collector.get_testcases_filenames()) self.emit( self.TAG, { 'action': 'click', 'tid': tid, 'origin': pos, 'targetDescription': desc, 'lineno': lineno, 'srcfilename': srcfilename })
def swipe(self, tid, origin, direction, desc): lineno, srcfilename = get_current_lineno_of( self.collector.get_testcases_filenames()) self.emit( self.TAG, { 'action': 'swipe', 'tid': tid, 'origin': origin, 'direction': direction, 'targetDescription': desc, 'lineno': lineno, 'srcfilename': srcfilename })
def motion(self, tid, desc, points): """ 记录motion event,一个motion event就是一个点的轨迹,比如从A拖动到B,每个motion event使用tid分组,同一个tid分组的会归并在一起, 多点触控的两组轨迹就必须是相同的tid,调用两次这个方法并传入相同的tid即可 :param tid: event 分组标号 :param desc: 事件描述 :param points: 点序列,按顺序构成一系列轨迹 :return: None """ lineno, srcfilename = get_current_lineno_of( self.collector.get_testcases_filenames()) self.emit( self.TAG, { 'action': 'click', 'tid': tid, 'targetDescription': desc, 'points': points, 'lineno': lineno, 'srcfilename': srcfilename })
def fail(self, errmsg, assertionMsg, tb): lineno, srcfilename = get_current_lineno_of(self.collector.get_testcases_filenames()) self.emit(self.TAG, {'method': 'fail', 'errmsg': errmsg, 'msg': assertionMsg, 'traceback': tb, 'lineno': lineno, 'srcfilename': srcfilename})
def assert_(self, assertionType, args, assertionMsg): lineno, srcfilename = get_current_lineno_of(self.collector.get_testcases_filenames()) self.emit(self.TAG, {'method': 'assert', 'type': assertionType, 'args': args, 'msg': assertionMsg, 'lineno': lineno, 'srcfilename': srcfilename})