Beispiel #1
0
 def start_app(self, device_id, bundle_id):
     device = device_service.devices.get(device_id)
     port = lyrebird.context.application.conf.get('mock.port')
     res = device.start_app(bundle_id, get_ip(), port)
     if 'ConnectionResetError' in res and '54' in res:
         return context.make_fail_response('WDA is not ready!')
     return context.make_ok_response()
Beispiel #2
0
 def stop_app(self, device_id, bundle_id):
     device = device_service.devices.get(device_id)
     res = device.stop_app()
     if 'NoneType' in res:
         return context.make_fail_response(
             'Cannot stop app before start it.')
     return context.make_ok_response()
 def import_result_handler(self):
     json_file = request.files.get('json-import')
     mimetype = json_file.content_type
     # 读取文件流,注意文件流只能read一次
     bytes_obj = json_file.read()
     try:
         result_obj = json.loads(bytes_obj)
         # 获取import文件的sha1
         import_sha1 = result_obj.get('base_sha1')
         if app_context.base_sha1 == import_sha1:
             # merge import result and cache result
             # check_result_schema(result_obj)
             app_context.coverage = json.loads(bytes_obj).get('coverage')
             mergeAlgorithm.merge_resume(result_obj.get('test_data'))
             # 放入缓存
             # app_context.merge_list = json.loads(bytes_obj).get('test_data')
             # app_context.coverage = json.loads(bytes_obj).get('coverage')
             resp = context.make_ok_response()
             lyrebird.publish('api_coverage', 'operation', name='import_result')
         else:
             resp = context.make_fail_response('导入的测试结果和之前选择base不匹配')
             lyrebird.publish('api_coverage', 'error', name='import_result')
     except Exception as e:
         resp = context.make_fail_response('导入文件内容格式有误:' + str(e))
         lyrebird.publish('api_coverage', 'error', name='import_result')
     return resp
Beispiel #4
0
 def select(self):
     """
     更新选中的case分组
     """
     grouplist = request.json.get('group')
     app_context.select_groups = grouplist
     return context.make_ok_response()
Beispiel #5
0
    def save_report(self):
        """
        保存测试报告API
        """
        report_data_path = os.path.join(os.path.dirname(__file__),
                                        'report_template/data/report-data.js')
        with codecs.open(report_data_path, 'w+', 'utf-8') as f:
            f.write('var reportCaseData=' + json.dumps(
                {'result': app_context.result_list}, ensure_ascii=False))
            f.write('\n')
            f.write('var baseData=' +
                    json.dumps(app_context.config, ensure_ascii=False))
            f.write('\n')
            f.write('var detailCollection=' +
                    json.dumps(app_context.content, ensure_ascii=False))
            f.write('\n')
        report_path = os.path.join(os.path.dirname(__file__),
                                   'report_template')
        target_path = os.path.abspath(
            os.path.join(lyrebird.get_plugin_storage(), 'report'))
        if os.path.exists(target_path):
            shutil.rmtree(target_path)
        shutil.copytree(report_path, target_path)

        return context.make_ok_response()
    def import_base_handler(self):
        json_file = request.files.get('json-import')
        mimetype = json_file.content_type
        # 判断是不是json格式的文件
        if mimetype == 'application/json':
            # 读取文件流,注意文件流只能read一次
            bytes_obj = json_file.read()
            try:
                check_result = BaseDataHandler().check_base(json.loads(bytes_obj))
                if check_result:
                    return check_result

                self.write_wb(DEFAULT_BASE, bytes_obj)
                # 读取json文件
                json_obj = json.loads(codecs.open(DEFAULT_BASE, 'r', 'utf-8').read())
                # 获取文件的sha1
                app_context.base_sha1 = self.get_sha1(bytes_obj)
                # 初次处理,切换后的result
                mergeAlgorithm.first_result_handler(json_obj)
                mergeAlgorithm.coverage_arithmetic(json_obj)
                resp = context.make_ok_response()
                lyrebird.publish('api_coverage', 'operation', name='import_base')
            except Exception as e:
                resp = context.make_fail_response('导入文件内容格式有误:' + str(e))
                lyrebird.publish('api_coverage', 'error', name='import_base')
        else:
            resp = context.make_fail_response("Error.The selected non - JSON file.")
            lyrebird.publish('api_coverage', 'error', name='import_base')
        return resp
def clear_result():
    ResultHandler().clear_cache_result()
    # 获取基准文件
    base_dict = BaseDataHandler().get_base_source()
    # 初始化正常会进行数据的处理:覆盖率初始化 & API LIST初始化
    if not isinstance(base_dict, Response):
        mergeAlgorithm.first_result_handler(base_dict)
        mergeAlgorithm.coverage_arithmetic(base_dict)
    lyrebird.publish('api_coverage', 'operation', name='clear_result')
    return context.make_ok_response()
Beispiel #8
0
    def stop_app(self, device_id, package_name):
        """

        :param device_id:
        :return:
        """
        device = device_service.devices.get(device_id)
        if not device:
            device = list(device_service.devices.values())[0]
        device.stop_app(package_name)
        return context.make_ok_response()
Beispiel #9
0
 def clear_result(self):
     """
     清空测试缓存API
     需要进行初始化,并且发送socketio消息给前端重新load页面
     """
     app_context.result_list = []
     app_context.content = []
     tracking_init()
     context.application.socket_io.emit('update',
                                        namespace='/tracking-plugin')
     return context.make_ok_response()
Beispiel #10
0
    def start_app(self, device_id, package_name):
        """

        :param device_id:
        :return:
        """
        device = device_service.devices.get(device_id)
        if not device:
            device = list(device_service.devices.values())[0]
        app = device.package_info(package_name)
        device.stop_app(package_name)
        port = lyrebird.context.application.conf.get('mock.port')
        device.start_app(app.launch_activity, get_ip(), port)
        return context.make_ok_response()
Beispiel #11
0
def execute_command():
    if request.method == 'POST':
        _command = request.json.get('command')
        if not _command:
            return context.make_fail_response('Empty command!')

        _device_id = request.json.get('device_id', '')
        device = device_service.devices.get(_device_id)
        if not device:
            return context.make_fail_response('Device not found!')

        res = device.adb_command_executor(_command)
        output = res.stdout.decode()
        err_str = res.stderr.decode()
        if err_str:
            return context.make_fail_response(err_str)
        else:
            return context.make_ok_response(data=output)
def save_result():
    # 传入文件名
    filename = request.form.get('result_name')
    ResultHandler().save_result(filename)
    lyrebird.publish('api_coverage', 'operation', name='save_result')
    return context.make_ok_response()
def get_base_info():
    return context.make_ok_response(business=app_context.business,
                                    version_name=app_context.version_name,
                                    version_code=app_context.version_code)