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
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 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 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()
def app_list(self, device_id): device = device_service.devices.get(device_id) if device: app_list = device.get_apps_list(device_id) return jsonify(app_list) else: return context.make_fail_response('No device_id found.')
def get_filter_conf(): msg = FilterHandler().get_filer_conf() # 如果返回的string包含报错信息,则是报错 if isinstance(msg, str): return context.make_fail_response(msg) else: return jsonify(msg)
def set_filter_conf(): filter_data = request.form.get('filter_data') try: resp = FilterHandler().save_filer_conf(json.loads(filter_data)) lyrebird.publish('api_coverage', 'operation', name='set_filter') except Exception as e: lyrebird.publish('api_coverage', 'error', name='set_filter') return context.make_fail_response("传入的非json文件" + str(repr(e))) return resp
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 take_screen_shot(self, device_id): device = device_service.devices.get(device_id) img_info = device.take_screen_shot() timestrap = img_info.get('timestrap') if img_info.get('screen_shot_file'): test = {'imgUrl': f'/ui/plugin/iOS/api/src/screenshot/{device_id}?time={timestrap}'} return jsonify(test) else: return context.make_fail_response('Could not start screenshot service! ' 'Please make sure the idevicescreenshot command works correctly')
def take_screen_shot(self, device_id): device = device_service.devices.get(device_id) img_path = device.take_screen_shot() if img_path: return jsonify({ 'imgUrl': '/ui/plugin/iOS/api/src/screenshot/%s?time=%s' % (device_id, time.time()) }) else: return context.make_fail_response( 'Could not start screenshot service! ' 'Please make sure the idevicescreenshot command works correctly' )
def desc(self): device_info = self.info().json if device_info.get('device'): return jsonify({ "code": 0, "data": "\n\n【设备应用信息】\n" + "设备类型: %s\n" % device_info.get('device').get('Model') + "设备系统: %s\n\n" % device_info.get('device').get('Version') + "应用名称: %s\n" % device_info.get('app').get('AppName') + "Version: %s\n" % device_info.get('app').get('VersionNumber') + "Build: %s\n" % device_info.get('app').get('BuildNumber') + "BundleID: %s" % device_info.get('app').get('BundleID') }) else: return context.make_fail_response('No device found, is it plugged in?')