Пример #1
0
    def handle(self):
        devices = ios_helper.devices()
        if len(devices) == len(self.devices):
            if len([k for k in devices if k not in self.devices]) == 0:
                return

        self.devices = devices
        self.publish_devices_info_event(self.devices,
                                        self.get_default_app_name())
        lyrebird.emit('ios-device')
Пример #2
0
def on_ios_screenshot(msg):
    if len(msg) == 0:
        return
    for item in msg:
        attachment_id = str(uuid4())
        attachments[attachment_id] = {
            'id': attachment_id,
            'name': item['screenshot']['name'],
            'path': item['screenshot']['path']
        }
    lyrebird.emit('attachments')
Пример #3
0
    def handle(self):
        devices = android_helper.devices()
        if len(devices) == len(self.devices):
            if len([k for k in devices if k not in self.devices]) == 0:
                return

        for _device_id in [k for k in devices if k not in self.devices]:
            self.devices = devices
            self.devices[_device_id].start_log()
        for _device_id in [k for k in self.devices if k not in devices]:
            self.devices[_device_id].stop_log()
            self.devices = devices

        lyrebird.emit('android-device')
        self.publish_devices_package_info(self.devices, config.load().package_name)
Пример #4
0
def on_request(msg):
    uri = msg['flow']['request']['url']
    flow_id = msg['flow']['id']
    item = {
        "uri": uri,
        "id":flow_id
    }
    global requestList
    if len(requestList) > 9:
        requestList.pop()
        requestList.insert(0, item)
    else:
        requestList.insert(0, item)

    lyrebird.emit('loadRequestList')
Пример #5
0
 def coverage_handler(self):
     """
     总体覆盖率
     """
     # 获取handle前的历史覆盖率为做对比用
     history_coverage = app_context.coverage['total']
     test_len = len(
         list(filter(lambda x: x.get('status') == 1,
                     app_context.merge_list)))
     if app_context.coverage['len'] == 0:
         coverage = 0
     else:
         coverage = round(test_len / app_context.coverage['len'] * 100, 2)
     # 为了传给Overbridge的socket信息format数据格式
     app_context.coverage['total'] = coverage
     # 覆盖率有变化才emit & publish 覆盖率的变化消息给API-Coverage前端,overbridge前端,和消息总线
     if not history_coverage == coverage:
         handler_time = time.time()
         # 限制频繁emit io msg,在两次之间大于指定时间间隔才会emit
         if handler_time - app_context.covtime > app_context.SOCKET_PUSH_INTERVAL:
             lyrebird.emit('coverage message',
                           app_context.coverage.get('total'),
                           namespace='/api_coverage')
             app_context.covtime = handler_time
         by_priority = [
             p.get('value') for p in app_context.coverage['priorities']
         ]
         lyrebird.publish(
             'coverage',
             dict(name='coverage',
                  value=app_context.coverage.get('total'),
                  by_priority=by_priority))
     app_context.coverage['test_len'] = test_len
     # 各优先级对应覆盖率
     for item_dic in app_context.coverage.get('priorities'):
         item_length = item_dic.get('len')
         test_item_length = len(
             list(
                 filter(
                     lambda x: x.get('priority') == item_dic.get('label')
                     and x.get('status') == 1, app_context.merge_list)))
         if item_length == 0:
             coverage = 0
         else:
             coverage = round(test_item_length / item_length * 100, 2)
         item_dic['value'] = coverage
         item_dic['test_len'] = test_item_length
Пример #6
0
        def log_handler(logcat_process):
            log_file = codecs.open(self._log_file, 'w', 'utf-8')
            self._log_process = logcat_process

            while True:
                line = logcat_process.stdout.readline()
                line = line.decode(encoding='UTF-8', errors='ignore')

                if not line:
                    lyrebird.emit('android-log', self._log_cache)
                    log_file.close()
                    return

                self._log_cache.append(line)
                self.crash_checker(line)
                self.anr_checker(line)

                if len(self._log_cache) >= 10:
                    lyrebird.emit('android-log', self._log_cache)
                    log_file.writelines(self._log_cache)
                    log_file.flush()
                    self._log_cache = []
Пример #7
0
    def handle(self, handler_context: HandlerContext):
        # UI自动化等需要mock的手段orgin url 需要调用这个方法
        org_url = handler_context.get_origin_url()
        if not org_url:
            org_url = handler_context.request.url
        short_url = org_url.replace('http://', '').replace('https://',
                                                           '').split('?')[0]
        # format之后的真正PATH,处理{num}这样的情况,emit给前端,做刷新table用,同时处理成小写
        path = format_url.format_api(short_url).lower()
        # 获取handler_context.id,为前端展开看详情准备
        path_id = handler_context.id
        device_ip = handler_context.request.headers.get('lyrebird.device.ip')

        # 当请求过来的时候,base还没有init,需要进行init处理
        if not app_context.base_list:
            base_dict = BaseDataHandler().get_base_source()
            if isinstance(base_dict, Response):
                lyrebird.get_logger().error('API-Coverage base file is None.')
            else:
                mergeAlgorithm.first_result_handler(base_dict)

        if path in app_context.base_list:
            # merge到 context merge list中
            mergeAlgorithm.merge_handler_new(path, path_id)
            # 在base里的需要去计算下覆盖率
            mergeAlgorithm.coverage_handler()
            # path传给覆盖详情表格
            lyrebird.emit('test_data message', path, namespace='/api_coverage')
            # 如果设备信息抓取到,进行上报
            # if device_ip in app_context.info:
            report_worker(path, device_ip)

        # 如果path配置了对应的参数
        if path in list(app_context.path_param_dic.keys()):
            ulr_list = app_context.path_param_dic[path]
            flag = 0
            for item in ulr_list:
                if compare_query(item['url'], handler_context.request.url):
                    mergeAlgorithm.merge_handler_new(item['url_base'], path_id)
                    mergeAlgorithm.coverage_handler()
                    lyrebird.emit('test_data message',
                                  item['url_base'],
                                  namespace='/api_coverage')
                    # 如果设备信息抓取到,进行上报
                    # if device_ip in app_context.info:
                    report_worker(item['url_base'], device_ip)
                    flag = 1
            # 如果参数组合不存在,提取关注的字段
            if flag == 0:
                url_pgroup = ''
                params_list = []
                for item in ulr_list:
                    params_list.extend(item['params'].keys())
                # 去重
                for p in list(set(params_list)):
                    val = handler_context.request.args.get(p)
                    if url_pgroup:
                        url_pgroup = url_pgroup + '&' + str(p) + '=' + str(val)
                    else:
                        url_pgroup = path + '?' + str(p) + '=' + str(val)

                mergeAlgorithm.merge_handler_new(url_pgroup, path_id)
                mergeAlgorithm.coverage_handler()
                lyrebird.emit('test_data message',
                              url_pgroup,
                              namespace='/api_coverage')
                # 如果设备信息抓取到,进行上报
                # if device_ip in app_context.info:
                report_worker(url_pgroup, device_ip)

        # 如果不在base里,需要判断这些API是否被筛掉
        else:
            # 如果不在筛除列表内,才进行merge等一系列算法
            if not Filter().filter_all(path):
                # merge到 context merge list中
                mergeAlgorithm.merge_handler_new(path, path_id)
                # 传给api_coverage前端的socket信息
                lyrebird.emit('test_data message',
                              path,
                              namespace='/api_coverage')
                # 如果设备信息抓取到,进行上报
                # if device_ip in app_context.info:
                report_worker(path, device_ip)
            else:
                pass
Пример #8
0
def on_ios_device(msg):
    logger.debug(f'PluginHandler: [iOS.device] {msg}')
    global ios_devices
    ios_devices = msg
    lyrebird.emit('devices')
Пример #9
0
def on_android_device(msg):
    logger.debug(f'PluginHandler: [Android.device] {msg}')
    global android_devices
    android_devices = msg
    lyrebird.emit('devices')
Пример #10
0
 def emit(self, starttime, path):
     duration = starttime - app_context.endtime
     if duration > app_context.SOCKET_PUSH_INTERVAL:
         app_context.endtime = starttime
         lyrebird.emit('test_data message', path, namespace='/api_coverage')
Пример #11
0
def emit(starttime, path):
    duration = starttime - app_context.endtime
    if duration > app_context.SOCKET_PUSH_INTERVAL:
        app_context.endtime = starttime
        lyrebird.emit('apiCoverageBaseData')