From 46e7557bef2938204f706079b413740df3f7f359 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Sat, 7 Oct 2023 13:58:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=BA=E5=9B=BE=E7=89=87=E6=A0=BC=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1013006 --user=王孝刚 github#26624 支持返回数据类型为图片格式的接口测试 https://www.tapd.cn/55049933/s/1422624 --- .../components/response/ResponseResult.vue | 45 ++++++++++++++----- .../io/metersphere/dto/ResponseResult.java | 4 ++ .../io/metersphere/jmeter/JMeterBase.java | 12 +++-- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/api-test/frontend/src/business/definition/components/response/ResponseResult.vue b/api-test/frontend/src/business/definition/components/response/ResponseResult.vue index 93c26c046a..1dda201546 100644 --- a/api-test/frontend/src/business/definition/components/response/ResponseResult.vue +++ b/api-test/frontend/src/business/definition/components/response/ResponseResult.vue @@ -2,15 +2,22 @@
- + + ref="codeEdit"/> + + + + + + @@ -19,7 +26,7 @@ :read-only="true" :data.sync="responseResult.headers" ref="codeEdit" - v-if="activeName === 'headers'" /> + v-if="activeName === 'headers'"/> @@ -29,7 +36,7 @@ :data.sync="responseResult.console" ref="codeEdit" v-if="activeName === 'console'" - height="calc(100vh - 300px)" /> + height="calc(100vh - 300px)"/> @@ -38,11 +45,11 @@ :read-only="true" :data.sync="responseResult.console" ref="codeEdit" - v-if="activeName === 'console'" /> + v-if="activeName === 'console'"/> - + @@ -51,7 +58,7 @@ :read-only="true" :data.sync="responseResult.vars" v-if="activeName === 'label'" - ref="codeEdit" /> + ref="codeEdit"/> @@ -60,7 +67,7 @@ :read-only="true" :data.sync="reqMessages" v-if="activeName === 'request_body'" - ref="codeEdit" /> + ref="codeEdit"/> @@ -69,8 +76,8 @@ v-if="currentProtocol === 'SQL'" :commands="sqlModes" :default-command="mode" - @command="sqlModeChange" /> - + @command="sqlModeChange"/> + @@ -81,8 +88,9 @@ import MsAssertionResults from './AssertionResults'; import MsCodeEdit from '../MsCodeEdit'; import MsDropdown from '../../../../business/commons/MsDropdown'; -import { BODY_FORMAT } from '../../model/ApiTestModel'; +import {BODY_FORMAT} from '../../model/ApiTestModel'; import MsSqlResultTable from './SqlResultTable'; +import {downloadByURL} from "fit2cloud-ui/src/tools/utils"; export default { name: 'MsResponseResult', @@ -114,12 +122,15 @@ export default { mode: BODY_FORMAT.TEXT, isMsCodeEditShow: true, reqMessages: '', + contentType: ['image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/webp', 'image/svg+xml', 'image/apng', 'image/avif'], + srcUrl: '', }; }, watch: { response() { this.setBodyType(); this.setReqMessage(); + this.showPicture(); }, activeName: { handler() { @@ -143,6 +154,12 @@ export default { sqlModeChange(mode) { this.mode = mode; }, + showPicture() { + if (this.responseResult.contentType && this.contentType.includes(this.responseResult.contentType)) { + this.modes.push('picture') + this.srcUrl = 'data:' + this.responseResult.contentType + ';base64,' + this.responseResult.imageUrl; + } + }, setBodyType() { if ( this.response && @@ -206,6 +223,7 @@ export default { mounted() { this.setBodyType(); this.setReqMessage(); + this.showPicture(); }, computed: { isSqlType() { @@ -220,6 +238,9 @@ export default { responseResult() { return this.response && this.response.responseResult ? this.response.responseResult : {}; }, + isPicture() { + return this.responseResult.contentType && this.contentType.includes(this.responseResult.contentType) && this.mode === 'picture'; + }, }, }; diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/ResponseResult.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/ResponseResult.java index 6b4ea3f1d8..ce4a03eec9 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/ResponseResult.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/ResponseResult.java @@ -27,6 +27,10 @@ public class ResponseResult { private String console; + private String contentType; + + private byte[] imageUrl; + private final List assertions = new ArrayList<>(); } diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/jmeter/JMeterBase.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/jmeter/JMeterBase.java index c985b3de24..1c65fa0440 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/jmeter/JMeterBase.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/jmeter/JMeterBase.java @@ -19,10 +19,7 @@ import org.apache.jmeter.visualizers.backend.BackendListener; import org.apache.jorphan.collections.HashTree; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; public class JMeterBase { private final static String THREAD_SPLIT = " "; @@ -30,6 +27,8 @@ public class JMeterBase { private final static String SPLIT_EQ = "split=="; private final static String SPLIT_AND = "split&&"; + private static final List imageList = Arrays.asList("image/png", "image/jpeg", "image/gif", "image/bmp", "image/webp", "image/svg+xml", "image/apng", "image/avif"); + public static HashTree getHashTree(Object scriptWrapper) throws Exception { Field field = scriptWrapper.getClass().getDeclaredField("testPlan"); field.setAccessible(true); @@ -105,6 +104,11 @@ public class JMeterBase { && result.getResponseDataAsString().length() > size) { requestResult.setBody(""); } else { + //判断返回的类型是否是图片 + if (StringUtils.isNotEmpty(result.getContentType()) && imageList.contains(result.getContentType())) { + responseResult.setContentType(result.getContentType()); + responseResult.setImageUrl(result.getResponseData()); + } responseResult.setBody(result.getResponseDataAsString()); } responseResult.setHeaders(result.getResponseHeaders());