Merge branch 'master' of https://github.com/metersphere/server into v1.3

This commit is contained in:
chenjianxing 2020-09-27 11:13:42 +08:00
commit b98c21b009
43 changed files with 457 additions and 480 deletions

View File

@ -12,6 +12,7 @@ public class KeyValue {
private String type;
private List<BodyFile> files;
private String description;
private String contentType;
private boolean enable;
public KeyValue() {

View File

@ -3,11 +3,11 @@ package io.metersphere.api.jmeter;
import io.metersphere.api.service.APIReportService;
import io.metersphere.api.service.APITestService;
import io.metersphere.base.domain.ApiTestReport;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.notice.domain.NoticeDetail;
import io.metersphere.notice.service.MailService;
import io.metersphere.notice.service.NoticeService;
import org.apache.commons.lang3.StringUtils;
@ -141,6 +141,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
requestResult.setBody(result.getSamplerData());
requestResult.setHeaders(result.getRequestHeaders());
requestResult.setRequestSize(result.getSentBytes());
requestResult.setStartTime(result.getStartTime());
requestResult.setTotalAssertions(result.getAssertionResults().length);
requestResult.setSuccess(result.isSuccessful());
requestResult.setError(result.getErrorCount());

View File

@ -16,6 +16,8 @@ public class RequestResult {
private long requestSize;
private long startTime;
private int error;
private boolean success;

View File

@ -1,6 +1,7 @@
package io.metersphere.controller;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.User;
import io.metersphere.commons.utils.SessionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
@ -15,7 +16,8 @@ public class TestController {
@PostMapping(value = "/upload", consumes = {"multipart/form-data"})
public Object testUpload(@RequestPart(value = "id") String id, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
public Object testUpload(@RequestPart(value = "id") String id, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles
, @RequestPart(value = "user") User user, @RequestParam(value = "name") String name) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id);
jsonObject.put("file", file.getOriginalFilename());

View File

@ -14,7 +14,6 @@ import org.quartz.TriggerKey;
public class ApiTestJob extends MsScheduleJob {
private APITestService apiTestService;
private MailService mailService;
public ApiTestJob() {
apiTestService = (APITestService) CommonBeanFactory.getBean(APITestService.class);
}

View File

@ -1,7 +1,7 @@
package io.metersphere.notice.controller;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.notice.controller.request.NoticeRequest;
import io.metersphere.notice.domain.NoticeDetail;
import io.metersphere.notice.service.NoticeService;
import org.springframework.web.bind.annotation.*;

View File

@ -1,6 +1,6 @@
package io.metersphere.notice.controller.request;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.notice.domain.NoticeDetail;
import lombok.Data;
import java.util.List;

View File

@ -1,9 +0,0 @@
package io.metersphere.notice.domain;
import io.metersphere.base.domain.Notice;
import lombok.Data;
@Data
public class NoticeDTO extends Notice {
private String[] names;
}

View File

@ -1,5 +1,6 @@
package io.metersphere.base.domain;
package io.metersphere.notice.domain;
import io.metersphere.base.domain.Notice;
import lombok.Data;
@Data

View File

@ -1,7 +1,6 @@
package io.metersphere.notice.service;
import io.metersphere.api.dto.APIReportResult;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.base.domain.SystemParameter;
import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.ParamConstants;
@ -10,6 +9,7 @@ import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.notice.domain.NoticeDetail;
import io.metersphere.service.SystemParameterService;
import io.metersphere.service.UserService;
import io.metersphere.track.request.testreview.SaveCommentRequest;

View File

@ -1,10 +1,10 @@
package io.metersphere.notice.service;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.base.domain.NoticeExample;
import io.metersphere.base.mapper.NoticeMapper;
import io.metersphere.notice.controller.request.NoticeRequest;
import io.metersphere.notice.domain.NoticeDetail;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

View File

@ -19,6 +19,7 @@ import io.metersphere.dto.LoadTestDTO;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.PerformanceTestJob;
import io.metersphere.notice.domain.NoticeDetail;
import io.metersphere.notice.service.MailService;
import io.metersphere.notice.service.NoticeService;
import io.metersphere.performance.engine.Engine;

View File

@ -61,7 +61,8 @@ public class TestCaseCommentService {
testCaseComments.forEach(testCaseComment -> {
String authorId = testCaseComment.getAuthor();
User user = userMapper.selectByPrimaryKey(authorId);
testCaseComment.setAuthor(user.getName());
String author = user == null ? authorId : user.getName();
testCaseComment.setAuthor(author);
});
return testCaseComments;
}

View File

@ -115,7 +115,8 @@ public class TestPlanService {
return Optional.ofNullable(testPlanMapper.selectByPrimaryKey(testPlanId)).orElse(new TestPlan());
}
public int editTestPlan(TestPlan testPlan) {
public int editTestPlan(TestPlanDTO testPlan) {
editTestPlanProject(testPlan);
testPlan.setUpdateTime(System.currentTimeMillis());
checkTestPlanExist(testPlan);
//进行中状态写入实际开始时间

View File

@ -90,6 +90,10 @@ export default {
methods: {
registerEvents() {
ApiEvent.$on(LIST_CHANGE, () => {
// todo refs
if (!this.$refs.projectRecent) {
return;
}
this.$refs.projectRecent.recent();
this.$refs.testRecent.recent();
this.$refs.reportRecent.recent();

View File

@ -1,231 +1,25 @@
<template>
<ms-container v-loading="loading" :element-loading-text="$t('api_report.running')">
<ms-main-container>
<el-card>
<section class="report-container" v-if="this.report.testId">
<header class="report-header">
<el-row>
<el-col>
<span>{{ report.projectName }} / </span>
<router-link :to="path">{{ report.testName }}</router-link>
<span class="time">{{ report.createTime | timestampFormatDate }}</span>
<el-button class="export-button" plain type="primary" size="mini" @click="handleExport(report.name)"
style="margin-left: 1200px">
{{$t('test_track.plan_view.export_report')}}
</el-button>
</el-col>
</el-row>
</header>
<main v-if="this.isNotRunning">
<ms-metric-chart :content="content" :totalTime="totalTime"/>
<el-row :gutter="20">
<el-col :span="8">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane :label="$t('api_report.total')" name="total">
<ms-scenario-results :scenarios="content.scenarios" v-on:requestResult="requestResult"/>
</el-tab-pane>
<el-tab-pane name="fail">
<template slot="label">
<span class="fail">{{ $t('api_report.fail') }}</span>
</template>
<ms-scenario-results v-on:requestResult="requestResult" :scenarios="fails"/>
</el-tab-pane>
</el-tabs>
</el-col>
<el-col :span="16" style="margin-top: 40px;">
<ms-request-result-tail v-if="isRequestResult" :request="request" :scenario-name="scenarioName"/>
</el-col>
</el-row>
<ms-api-report-export v-if="reportExportVisible" id="apiTestReport" :title="report.testName" :content="content" :total-time="totalTime"/>
</main>
</section>
</el-card>
</ms-main-container>
</ms-container>
<ms-api-report-view-detail :report-id="reportId"/>
</template>
<script>
import MsRequestResult from "./components/RequestResult";
import MsRequestResultTail from "./components/RequestResultTail";
import MsScenarioResult from "./components/ScenarioResult";
import MsMetricChart from "./components/MetricChart";
import MsScenarioResults from "./components/ScenarioResults";
import MsContainer from "@/business/components/common/components/MsContainer";
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
import MsApiReportExport from "./ApiReportExport";
import {exportPdf} from "../../../../common/js/utils";
import html2canvas from "html2canvas";
import MsApiReportViewDetail from "./ApiReportViewDetail";
export default {
name: "MsApiReportView",
components: {
MsApiReportExport,
MsMainContainer,
MsContainer, MsScenarioResults, MsRequestResultTail, MsMetricChart, MsScenarioResult, MsRequestResult
MsApiReportViewDetail,
},
data() {
return {
activeName: "total",
content: {},
report: {},
loading: true,
fails: [],
totalTime: 0,
isRequestResult: false,
request: {},
scenarioName: null,
reportExportVisible: false
}
},
activated() {
this.isRequestResult = false
},
methods: {
init() {
this.loading = true;
this.report = {};
this.content = {};
this.fails = [];
},
handleClick(tab, event) {
this.isRequestResult = false
},
getReport() {
this.init();
if (this.reportId) {
let url = "/api/report/get/" + this.reportId;
this.$get(url, response => {
this.report = response.data || {};
if (response.data) {
if (this.isNotRunning) {
try {
this.content = JSON.parse(this.report.content);
} catch (e) {
console.log(this.report.content)
throw e;
}
this.getFails();
this.loading = false;
} else {
setTimeout(this.getReport, 2000)
}
} else {
this.loading = false;
this.$error(this.$t('api_report.not_exist'));
}
});
}
},
getFails() {
if (this.isNotRunning) {
this.fails = [];
this.totalTime = 0
this.content.scenarios.forEach((scenario) => {
this.totalTime = this.totalTime + Number(scenario.responseTime)
let failScenario = Object.assign({}, scenario);
if (scenario.error > 0) {
this.fails.push(failScenario);
failScenario.requestResults = [];
scenario.requestResults.forEach((request) => {
if (!request.success) {
let failRequest = Object.assign({}, request);
failScenario.requestResults.push(failRequest);
}
})
}
})
}
},
requestResult(requestResult) {
this.isRequestResult = false;
this.$nextTick(function () {
this.isRequestResult = true;
this.request = requestResult.request;
this.scenarioName = requestResult.scenarioName;
});
},
handleExport(name) {
this.loading = true;
this.reportExportVisible = true;
let reset = this.exportReportReset;
this.$nextTick(function () {
setTimeout(() => {
html2canvas(document.getElementById('apiTestReport'), {
scale: 2
}).then(function(canvas) {
exportPdf(name, [canvas]);
reset();
});
}, 1000);
});
},
exportReportReset() {
this.reportExportVisible = false;
this.loading = false;
}
},
watch: {
'$route': 'getReport',
},
created() {
this.getReport();
},
computed: {
reportId: function () {
return this.$route.params.reportId;
},
path() {
return "/api/test/edit?id=" + this.report.testId;
},
isNotRunning() {
return "Running" !== this.report.status;
}
}
}
</script>
<style>
.report-container .el-tabs__header {
margin-bottom: 1px;
}
</style>
<style scoped>
.report-container {
height: calc(100vh - 155px);
min-height: 600px;
overflow-y: auto;
}
.report-header {
font-size: 15px;
}
.report-header a {
text-decoration: none;
}
.report-header .time {
color: #909399;
margin-left: 10px;
}
.report-container .fail {
color: #F56C6C;
}
.report-container .is-active .fail {
color: inherit;
}
.export-button {
float: right;
}
</style>

View File

@ -0,0 +1,224 @@
<template>
<ms-container v-loading="loading" :element-loading-text="$t('api_report.running')">
<ms-main-container>
<el-card>
<section class="report-container" v-if="this.report.testId">
<ms-api-report-view-header :report="report" @reportExport="handleExport"/>
<main v-if="this.isNotRunning">
<ms-metric-chart :content="content" :totalTime="totalTime"/>
<el-row :gutter="20">
<el-col :span="8">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane :label="$t('api_report.total')" name="total">
<ms-scenario-results :scenarios="content.scenarios" v-on:requestResult="requestResult"/>
</el-tab-pane>
<el-tab-pane name="fail">
<template slot="label">
<span class="fail">{{ $t('api_report.fail') }}</span>
</template>
<ms-scenario-results v-on:requestResult="requestResult" :scenarios="fails"/>
</el-tab-pane>
</el-tabs>
</el-col>
<el-col :span="16" style="margin-top: 40px;">
<ms-request-result-tail v-if="isRequestResult" :request="request" :scenario-name="scenarioName"/>
</el-col>
</el-row>
<ms-api-report-export v-if="reportExportVisible" id="apiTestReport" :title="report.testName" :content="content" :total-time="totalTime"/>
</main>
</section>
</el-card>
</ms-main-container>
</ms-container>
</template>
<script>
import MsRequestResult from "./components/RequestResult";
import MsRequestResultTail from "./components/RequestResultTail";
import MsScenarioResult from "./components/ScenarioResult";
import MsMetricChart from "./components/MetricChart";
import MsScenarioResults from "./components/ScenarioResults";
import MsContainer from "@/business/components/common/components/MsContainer";
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
import MsApiReportExport from "./ApiReportExport";
import {exportPdf} from "../../../../common/js/utils";
import html2canvas from "html2canvas";
import MsApiReportViewHeader from "./ApiReportViewHeader";
export default {
name: "MsApiReportViewDetail",
components: {
MsApiReportViewHeader,
MsApiReportExport,
MsMainContainer,
MsContainer, MsScenarioResults, MsRequestResultTail, MsMetricChart, MsScenarioResult, MsRequestResult
},
data() {
return {
activeName: "total",
content: {},
report: {},
loading: true,
fails: [],
totalTime: 0,
isRequestResult: false,
request: {},
scenarioName: null,
reportExportVisible: false
}
},
props: ['reportId'],
activated() {
this.isRequestResult = false;
},
watch: {
reportId() {
this.getReport();
}
},
methods: {
init() {
this.loading = true;
this.report = {};
this.content = {};
this.fails = [];
this.report = {};
this.isRequestResult = false;
},
handleClick(tab, event) {
this.isRequestResult = false
},
getReport() {
this.init();
if (this.reportId) {
let url = "/api/report/get/" + this.reportId;
this.$get(url, response => {
this.report = response.data || {};
if (response.data) {
if (this.isNotRunning) {
try {
this.content = JSON.parse(this.report.content);
} catch (e) {
console.log(this.report.content)
throw e;
}
this.getFails();
this.loading = false;
} else {
setTimeout(this.getReport, 2000)
}
} else {
this.loading = false;
this.$error(this.$t('api_report.not_exist'));
}
});
}
},
getFails() {
if (this.isNotRunning) {
this.fails = [];
this.totalTime = 0
this.content.scenarios.forEach((scenario) => {
this.totalTime = this.totalTime + Number(scenario.responseTime)
let failScenario = Object.assign({}, scenario);
if (scenario.error > 0) {
this.fails.push(failScenario);
failScenario.requestResults = [];
scenario.requestResults.forEach((request) => {
if (!request.success) {
let failRequest = Object.assign({}, request);
failScenario.requestResults.push(failRequest);
}
})
}
})
}
},
requestResult(requestResult) {
this.isRequestResult = false;
this.$nextTick(function () {
this.isRequestResult = true;
this.request = requestResult.request;
this.scenarioName = requestResult.scenarioName;
});
},
handleExport(name) {
this.loading = true;
this.reportExportVisible = true;
let reset = this.exportReportReset;
this.$nextTick(function () {
setTimeout(() => {
html2canvas(document.getElementById('apiTestReport'), {
scale: 2
}).then(function(canvas) {
exportPdf(name, [canvas]);
reset();
});
}, 1000);
});
},
exportReportReset() {
this.reportExportVisible = false;
this.loading = false;
}
},
created() {
this.getReport();
},
computed: {
path() {
return "/api/test/edit?id=" + this.report.testId;
},
isNotRunning() {
return "Running" !== this.report.status;
}
}
}
</script>
<style>
.report-container .el-tabs__header {
margin-bottom: 1px;
}
</style>
<style scoped>
.report-container {
height: calc(100vh - 155px);
min-height: 600px;
overflow-y: auto;
}
.report-header {
font-size: 15px;
}
.report-header a {
text-decoration: none;
}
.report-header .time {
color: #909399;
margin-left: 10px;
}
.report-container .fail {
color: #F56C6C;
}
.report-container .is-active .fail {
color: inherit;
}
.export-button {
float: right;
}
</style>

View File

@ -0,0 +1,52 @@
<template>
<header class="report-header">
<el-row>
<el-col>
<span>{{ report.projectName }} / </span>
<router-link :to="path">{{ report.testName }}</router-link>
<span class="time">{{ report.createTime | timestampFormatDate }}</span>
<el-button :disabled="isReadOnly" class="export-button" plain type="primary" size="mini" @click="handleExport(report.name)"
style="margin-left: 1200px">
{{$t('test_track.plan_view.export_report')}}
</el-button>
</el-col>
</el-row>
</header>
</template>
<script>
import {checkoutTestManagerOrTestUser} from "../../../../common/js/utils";
export default {
name: "MsApiReportViewHeader",
props: ['report'],
computed: {
path() {
return "/api/test/edit?id=" + this.report.testId;
},
},
data() {
return {
isReadOnly: false,
}
},
created() {
if (!checkoutTestManagerOrTestUser()) {
this.isReadOnly = true;
}
},
methods: {
handleExport(name) {
this.$emit('reportExport', name);
}
}
}
</script>
<style scoped>
.export-button {
float: right;
}
</style>

View File

@ -2,10 +2,13 @@
<div class="request-result">
<div @click="active">
<el-row :gutter="10" type="flex" align="middle" class="info">
<el-col :span="16">
<el-col :span="12">
<i class="icon el-icon-arrow-right" :class="{'is-active': isActive}"/>
{{scenarioName}}
</el-col>
<el-col :span="4">
{{$t('api_report.start_time')}}
</el-col>
<el-col :span="2">
{{$t('api_report.response_time')}}
</el-col>
@ -20,17 +23,20 @@
</el-col>
</el-row>
<el-row :gutter="10" type="flex" align="middle" class="info">
<el-col :span="4">
<el-col :span="2">
<div class="method">
{{request.method}}
</div>
</el-col>
<el-col :span="12">
<el-col :span="10">
<div class="name">{{request.name}}</div>
<el-tooltip effect="dark" :content="request.url" placement="bottom" :open-delay="800">
<div class="url">{{request.url}}</div>
</el-tooltip>
</el-col>
<el-col :span="4">
{{request.startTime | timestampFormatDate(true) }}
</el-col>
<el-col :span="2">
<div class="time">
{{request.responseResult.responseTime}}

View File

@ -14,9 +14,13 @@
</el-select>
</el-input>
<el-button type="primary" plain :disabled="isReadOnly" @click="saveTest">
{{ $t('commons.save') }}
</el-button>
<el-tooltip :content="'Ctrl + S'"
placement="top"
:enterable="false">
<el-button type="primary" plain :disabled="isReadOnly" @click="saveTest">
{{ $t('commons.save') }}
</el-button>
</el-tooltip>
<el-button type="primary" plain :disabled="isReadOnly"
@click="saveRunTest">
@ -67,7 +71,7 @@
<script>
import MsApiScenarioConfig from "./components/ApiScenarioConfig";
import {Test, Scenario} from "./model/ScenarioModel"
import {Scenario, Test} from "./model/ScenarioModel"
import MsApiReportStatus from "../report/ApiReportStatus";
import MsApiReportDialog from "./ApiReportDialog";
import {checkoutTestManagerOrTestUser, downloadFile, getUUID} from "@/common/js/utils";
@ -368,11 +372,25 @@ export default {
this.debugReportId = response.data;
this.resetBodyFile();
});
}
},
handleEvent(event) {
if (event.keyCode === 83 && event.ctrlKey) {
console.log('拦截到 ctrl + s');//ctrl+s
this.saveTest();
event.preventDefault();
event.returnValue = false;
return false;
}
},
},
created() {
this.init();
//
document.addEventListener('keydown', this.handleEvent)
},
beforeDestroy() {
document.removeEventListener('keydown', this.handleEvent);
}
}
</script>

View File

@ -6,8 +6,8 @@
<div class="kv-row" v-for="(item, index) in items" :key="index">
<el-row type="flex" :gutter="20" justify="space-between" align="middle">
<el-col v-if="isShowEnable" class="kv-checkbox">
<input type="checkbox" v-if="!isDisable(index)" @change="change" :value="item.uuid" v-model="checkedValues"
:disabled="isDisable(index) || isReadOnly"/>
<input type="checkbox" v-if="!isDisable(index)" v-model="item.enable"
:disabled="isReadOnly"/>
</el-col>
<el-col>
@ -52,7 +52,7 @@
},
data() {
return {
checkedValues: []
// checkedValues: []
}
},
computed: {
@ -79,10 +79,6 @@
let isNeedCreate = true;
let removeIndex = -1;
this.items.forEach((item, index) => {
//
if (this.isShowEnable) {
item.enable = this.checkedValues.indexOf(item.uuid) != -1 ? true : false;
}
if (!item.name && !item.value) {
//
if (index !== this.items.length - 1) {
@ -93,13 +89,7 @@
}
});
if (isNeedCreate) {
//
if (this.isShowEnable) {
this.items[this.items.length - 1].enable = true;
// v-model
this.checkedValues.push(this.items[this.items.length - 1].uuid);
}
this.items.push(new KeyValue());
this.items.push(new KeyValue({enable: true}));
}
this.$emit('change', this.items);
// TODO key
@ -112,9 +102,6 @@
let results = queryString ? suggestions.filter(this.createFilter(queryString)) : suggestions;
cb(results);
},
uuid: function () {
return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1);
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
@ -123,15 +110,7 @@
},
created() {
if (this.items.length === 0) {
this.items.push(new KeyValue());
} else if (this.isShowEnable) {
this.items.forEach((item, index) => {
let uuid = this.uuid();
item.uuid = uuid;
if (item.enable) {
this.checkedValues.push(uuid);
}
})
this.items.push(new KeyValue({enable: true}));
}
}
}

View File

@ -3,26 +3,27 @@
<span class="kv-description" v-if="description">
{{ description }}
</span>
<div class="kv-row" v-for="(item, index) in parameters" :key="index">
<el-row type="flex" :gutter="20" justify="space-between" align="middle">
<el-col class="kv-checkbox">
<input type="checkbox" v-if="!isDisable(index)" @change="change" :value="item.uuid" v-model="checkedValues"
:disabled="isDisable(index) || isReadOnly"/>
<input type="checkbox" v-if="!isDisable(index)" v-model="item.enable"
:disabled="isReadOnly"/>
</el-col>
<el-col>
<el-input v-if="!suggestions" :disabled="isReadOnly" v-model="item.name" size="small" maxlength="200"
@change="change" :placeholder="keyText" show-word-limit>
<template v-slot:prepend>
<el-select v-if="type === 'body'" :disabled="isReadOnly" class="kv-type" v-model="item.type">
<el-select v-if="type === 'body'" :disabled="isReadOnly" class="kv-type" v-model="item.type" @change="typeChange(item)">
<el-option value="text"/>
<el-option value="file"/>
</el-select>
</template>
</el-input>
<el-autocomplete :disabled="isReadOnly" :maxlength="200" v-if="suggestions" v-model="item.name" size="small"
<el-autocomplete :disabled="isReadOnly" v-if="suggestions" v-model="item.name" size="small"
:fetch-suggestions="querySearch" @change="change" :placeholder="keyText" show-word-limit/>
</el-col>
@ -44,6 +45,13 @@
<el-col v-if="item.type === 'file'">
<ms-api-body-file-upload :parameter="item"/>
</el-col>
<el-col v-if="type === 'body'">
<el-input :disabled="isReadOnly" v-model="item.contentType" size="small" maxlength="100"
@change="change" :placeholder="$t('api_test.request.content_type')" show-word-limit>
</el-input>
</el-col>
<el-col class="kv-delete">
<el-button size="mini" class="el-icon-delete-solid" circle @click="remove(index)"
:disabled="isDisable(index) || isReadOnly"/>
@ -85,7 +93,6 @@
data() {
return {
currentItem: null,
checkedValues: []
}
},
computed: {
@ -98,9 +105,6 @@
},
methods: {
remove: function (index) {
//
let checkIndex = this.checkedValues.indexOf(this.parameters[index].uuid);
checkIndex != -1 ? this.checkedValues.splice(checkIndex, 1) : this.checkedValues;
//
this.parameters.splice(index, 1);
this.$emit('change', this.parameters);
@ -109,9 +113,6 @@
let isNeedCreate = true;
let removeIndex = -1;
this.parameters.forEach((item, index) => {
//
item.enable = this.checkedValues.indexOf(item.uuid) != -1 ? true : false;
if (!item.name && !item.value) {
//
if (index !== this.parameters.length - 1) {
@ -122,11 +123,7 @@
}
});
if (isNeedCreate) {
//
this.parameters[this.parameters.length - 1].enable = true;
// v-model
this.checkedValues.push(this.parameters[this.parameters.length - 1].uuid);
this.parameters.push(new KeyValue(null, null, 'text', false, this.uuid()));
this.parameters.push(new KeyValue({type: 'text', enable: true, uuid: this.uuid(), contentType: 'text/plain'}));
}
this.$emit('change', this.parameters);
// TODO key
@ -161,22 +158,18 @@
advanced(item) {
this.$refs.variableAdvance.open();
this.currentItem = item;
this.itemValue = '';
this.mockVariableFuncs = [];
},
typeChange(item) {
if (item.type === 'file') {
item.contentType = 'application/octet-stream';
} else {
item.contentType = 'text/plain';
}
}
},
created() {
if (this.parameters.length === 0) {
this.parameters.push(new KeyValue(null, null, 'text', false, this.uuid()));
} else {
this.parameters.forEach((item, index) => {
let uuid = this.uuid();
item.uuid = uuid;
if (item.enable) {
this.checkedValues.push(uuid);
}
})
this.parameters.push(new KeyValue( {type: 'text', enable: true, uuid: this.uuid(), contentType: 'text/plain'}));
}
}
}

View File

@ -173,7 +173,7 @@ export default {
}
];
if (this.environment) {
let variables = JSON.parse(this.environment.variables);
let variables = this.environment.config.commonConfig.variables;
this.environmentParams = [
{
name: this.environment.name,

View File

@ -105,9 +105,9 @@
.api-body-upload {
min-height: 32px;
/*border: 1px solid #EBEEF5;*/
/*padding: 2px;*/
/*border-radius: 4px;*/
border: 1px solid #EBEEF5;
padding: 2px;
border-radius: 4px;
}
.upload-item {

View File

@ -34,7 +34,7 @@
codeTemplates: [
{
title: this.$t('api_test.request.processor.code_template_get_variable'),
value: 'vars.get("variable_name");',
value: 'vars.get("variable_name")',
},
{
title: this.$t('api_test.request.processor.code_template_set_variable'),
@ -42,17 +42,17 @@
},
{
title: this.$t('api_test.request.processor.code_template_get_response_header'),
value: 'prev.getResponseHeaders();',
value: 'prev.getResponseHeaders()',
disabled: this.isPreProcessor
},
{
title: this.$t('api_test.request.processor.code_template_get_response_code'),
value: 'prev.getResponseCode();',
value: 'prev.getResponseCode()',
disabled: this.isPreProcessor
},
{
title: this.$t('api_test.request.processor.code_template_get_response_result'),
value: 'prev.getResponseDataAsString();',
value: 'prev.getResponseDataAsString()',
disabled: this.isPreProcessor
}
],
@ -93,6 +93,9 @@
this.jsr223Processor.script = "";
}
this.jsr223Processor.script += template.value;
if (this.jsr223Processor.language === 'beanshell') {
this.jsr223Processor.script += ';';
}
this.reload();
},
reload() {

View File

@ -156,7 +156,7 @@ export default {
let url = new URL(urlStr);
url.searchParams.forEach((value, key) => {
if (key && value) {
this.request.parameters.splice(0, 0, new KeyValue(key, value));
this.request.parameters.splice(0, 0, new KeyValue({name: name, value: value}));
}
});
return url;

View File

@ -5,11 +5,24 @@
<el-input v-model="request.name" maxlength="300" show-word-limit/>
</el-form-item>
<el-form-item :label="$t('api_test.request.sql.dataSource')" prop="dataSource">
<el-select v-model="request.dataSource">
<el-option v-for="(item, index) in databaseConfigsOptions" :key="index" :value="item.id" :label="item.name"/>
</el-select>
</el-form-item>
<div class="one-row">
<el-form-item :label="$t('api_test.request.sql.dataSource')" prop="dataSource">
<el-select v-model="request.dataSource">
<el-option v-for="(item, index) in databaseConfigsOptions" :key="index" :value="item.id" :label="item.name"/>
</el-select>
</el-form-item>
<el-form-item :label="$t('api_test.request.sql.timeout')" prop="queryTimeout">
<el-input-number :disabled="isReadOnly" size="mini" v-model="request.queryTimeout" :placeholder="$t('commons.millisecond')" :max="1000*10000000" :min="0"/>
</el-form-item>
<el-form-item>
<el-switch
v-model="request.useEnvironment"
:active-text="$t('api_test.request.refer_to_environment')" @change="getDatabaseConfigsOptions">
</el-switch>
</el-form-item>
</div>
<el-form-item :label="$t('api_test.request.sql.result_variable')" prop="resultVariable">
<el-input v-model="request.resultVariable" maxlength="300" show-word-limit/>
@ -25,17 +38,6 @@
<!--</el-select>-->
<!--</el-form-item>-->
<el-form-item :label="$t('api_test.request.sql.timeout')" prop="queryTimeout">
<el-input-number :disabled="isReadOnly" size="mini" v-model="request.queryTimeout" :placeholder="$t('commons.millisecond')" :max="1000*10000000" :min="0"/>
</el-form-item>
<el-form-item>
<el-switch
v-model="request.useEnvironment"
:active-text="$t('api_test.request.refer_to_environment')" @change="getDatabaseConfigsOptions">
</el-switch>
</el-form-item>
<el-button :disabled="!request.enable || !scenario.enable || isReadOnly" class="debug-button" size="small" type="primary" @click="runDebug">{{$t('api_test.request.debug')}}</el-button>
<el-tabs v-model="activeName">
@ -147,4 +149,12 @@
height: calc(100vh - 570px);
}
.one-row .el-form-item {
display: inline-block;
}
.one-row .el-form-item:nth-child(2) {
margin-left: 60px;
}
</style>

View File

@ -344,6 +344,9 @@ export class HTTPSamplerArguments extends Element {
}
elementProp.stringProp('Argument.value', arg.value);
elementProp.stringProp('Argument.metadata', arg.metadata || "=");
if (arg.contentType) {
elementProp.stringProp('HTTPArgument.content_type', arg.contentType, "");
}
}
});
}
@ -363,7 +366,7 @@ export class HTTPsamplerFiles extends Element {
let elementProp = collectionProp.elementProp(arg.value, 'HTTPFileArg');
elementProp.stringProp('File.path', arg.value);
elementProp.stringProp('File.paramname', arg.name);
elementProp.stringProp('File.mimetype', arg.metadata || "application/octet-stream");
elementProp.stringProp('File.mimetype', arg.contentType || "application/octet-stream");
});
}
}

View File

@ -656,35 +656,18 @@ export class Body extends BaseConfig {
}
export class KeyValue extends BaseConfig {
constructor() {
let options, key, value, type, enable, uuid;
if (arguments.length === 1) {
options = arguments[0];
}
constructor(options) {
options = options || {};
options.enable = options.enable != false ? true : false;
if (arguments.length === 2) {
key = arguments[0];
value = arguments[1];
}
if (arguments.length === 3) {
key = arguments[0];
value = arguments[1];
type = arguments[2];
}
if (arguments.length === 5) {
key = arguments[0];
value = arguments[1];
type = arguments[2];
enable = arguments[3];
uuid = arguments[4];
}
super();
this.name = key;
this.value = value;
this.type = type;
this.name = undefined;
this.value = undefined;
this.type = undefined;
this.files = undefined;
this.enable = enable;
this.uuid = uuid;
this.enable = undefined;
this.uuid = undefined;
this.contentType = undefined;
this.set(options);
}
@ -956,7 +939,7 @@ class JMXHttpRequest {
this.domain = environment.config.httpConfig.domain;
this.port = environment.config.httpConfig.port;
this.protocol = environment.config.httpConfig.protocol;
let url = new URL(environment.config.httpConfig.protocol + "://" + environment.config.commonConfig.socket);
let url = new URL(environment.config.httpConfig.protocol + "://" + environment.config.httpConfig.socket);
this.path = this.getPostQueryParameters(request, decodeURIComponent(url.pathname + (request.path ? request.path : '')));
}
this.connectTimeout = request.connectTimeout;
@ -1117,7 +1100,7 @@ class JMXGenerator {
}
envArray.forEach(item => {
if (item.name && !keys.has(item.name)) {
target.push(new KeyValue(item.name, item.value));
target.push(new KeyValue({name: item.name, value: item.value}));
}
})
}
@ -1294,7 +1277,7 @@ class JMXGenerator {
}
}
}
request.headers.push(new KeyValue('Content-Type', type));
request.headers.push(new KeyValue({name: 'Content-Type', value: type}));
}
addRequestArguments(httpSamplerProxy, request) {
@ -1323,7 +1306,7 @@ class JMXGenerator {
let files = [];
let kvs = this.filterKVFile(request.body.kvs);
kvs.forEach(kv => {
if (kv.files) {
if ((kv.enable != false) && kv.files) {
kv.files.forEach(file => {
let arg = {};
arg.name = kv.name;

View File

@ -63,10 +63,10 @@
>
<template v-slot:default="{row}">
<el-switch
v-model="row.enable"
active-value="true"
inactive-value="false"
inactive-color="#ff4949"
v-model="row.enable"
active-value="true"
inactive-value="false"
inactive-color="#DCDFE6"
/>
</template>
</el-table-column>

View File

@ -98,6 +98,10 @@ export default {
methods: {
registerEvents() {
PerformanceEvent.$on(LIST_CHANGE, () => {
// todo refs
if (!this.$refs.projectRecent) {
return;
}
this.$refs.projectRecent.recent();
this.$refs.testRecent.recent();
this.$refs.reportRecent.recent();

View File

@ -150,6 +150,10 @@ export default {
},
registerEvents() {
TrackEvent.$on(LIST_CHANGE, () => {
// todo refs
if (!this.$refs.projectRecent) {
return;
}
this.$refs.projectRecent.recent();
this.$refs.planRecent.recent();
this.$refs.caseRecent.recent();

View File

@ -1,5 +1,5 @@
<template>
<ms-report-export-template :title="title" :type="$t('report.load_test_report')">
<ms-report-export-template :title="title" :type="$t('report.test_plan_report')">
<div v-for="(item, index) in previews" :key="item.id">
<template-component :isReportView="true" :metric="metric" :preview="item" :index="index" ref="templateComponent"/>
</div>

View File

@ -449,6 +449,7 @@
testRun(reportId) {
this.testCase.reportId = reportId;
this.saveReport(reportId);
this.activeTab = 'result';
},
testTabChange(data) {
if (this.testCase.type == 'performance' && data.paneName == 'result') {

View File

@ -36,12 +36,12 @@
<div v-for="(item, index) in previews" :key="item.id">
<template-component :isReportView="true" :metric="metric" :preview="item" :index="index" ref="templateComponent"/>
</div>
<ms-test-case-report-export v-if="reportExportVisible" id="testCaseReportExport" :title="report.name" :metric="metric" :previews="previews"/>
</el-main>
</div>
</template>
</el-drawer>
<ms-test-case-report-export v-if="reportExportVisible" id="testCaseReportExport" :title="report.name" :metric="metric" :previews="previews"/>
<test-case-report-template-edit :metric="metric" ref="templateEdit" @refresh="getReport"/>
</div>
</template>

View File

@ -16,7 +16,7 @@
</el-row>
</el-header>
<ms-api-scenario-config :project-id="test.projectId" :is-read-only="true" :scenarios="test.scenarioDefinition" ref="config"/>
<ms-api-scenario-config :test="test" :project-id="test.projectId" :is-read-only="true" :scenarios="test.scenarioDefinition" ref="config"/>
</el-container>
</el-card>

View File

@ -1,136 +1,22 @@
<template>
<ms-container>
<ms-main-container>
<span v-if="!reportId">{{$t('commons.not_performed_yet')}}</span>
<el-card v-if="reportId">
<section class="report-container" v-loading="loading">
<header class="report-header">
<span>{{report.projectName}} / </span>
<span class="time">{{report.createTime | timestampFormatDate}}</span>
</header>
<main>
<ms-metric-chart v-if="content" :content="content"/>
<el-tabs v-model="activeName">
<el-tab-pane :label="$t('api_report.total')" name="total">
<ms-scenario-results :scenarios="content.scenarios"/>
</el-tab-pane>
<el-tab-pane name="fail">
<template slot="label">
<span class="fail">{{$t('api_report.fail')}}</span>
</template>
<ms-scenario-results :scenarios="fails"/>
</el-tab-pane>
</el-tabs>
</main>
</section>
</el-card>
</ms-main-container>
</ms-container>
<div>
<span v-if="!reportId">{{$t('commons.not_performed_yet')}}</span>
<ms-api-report-view-detail v-if="reportId" :report-id="reportId"/>
</div>
</template>
<script>
import MsScenarioResult from "../../../../../api/report/components/ScenarioResult";
import MsMetricChart from "../../../../../api/report/components/MetricChart";
import MsScenarioResults from "../../../../../api/report/components/ScenarioResults";
import MsRequestResult from "../../../../../api/report/components/RequestResult";
import MsContainer from "../../../../../common/components/MsContainer";
import MsMainContainer from "../../../../../common/components/MsMainContainer";
import MsApiReportViewDetail from "../../../../../api/report/ApiReportViewDetail";
export default {
name: "ApiTestResult",
components: {MsMainContainer, MsContainer, MsRequestResult, MsScenarioResults, MsMetricChart, MsScenarioResult},
data() {
return {
activeName: "total",
content: {},
report: {},
loading: true,
fails: [],
}
},
props:['reportId'],
watch: {
reportId() {
this.init();
}
},
mounted() {
this.init();
},
methods: {
init() {
this.loading = true;
this.report = {};
this.content = {};
this.fails = [];
this.getReport();
},
getReport() {
if (this.reportId) {
let url = "/api/report/get/" + this.reportId;
this.$get(url, response => {
this.report = response.data || {};
if (this.report.status == 'Completed' || this.report.status == 'Success' || this.report.status == 'Error') {
this.content = JSON.parse(this.report.content);
this.getFails();
this.loading = false;
} else {
setTimeout(this.getReport, 2000)
}
});
}
},
getFails() {
this.fails = [];
this.content.scenarios.forEach((scenario) => {
let failScenario = Object.assign({}, scenario);
if (scenario.error > 0) {
this.fails.push(failScenario);
failScenario.requestResults = [];
scenario.requestResults.forEach((request) => {
if (!request.success) {
let failRequest = Object.assign({}, request);
failScenario.requestResults.push(failRequest);
}
});
}
});
}
}
}
name: "ApiTestResult",
components: {MsApiReportViewDetail},
props: ['reportId'],
}
</script>
<style>
.report-container .el-tabs__header {
margin-bottom: 1px;
}
</style>
<style scoped>
.report-container {
height: calc(100vh - 155px);
min-height: 600px;
overflow-y: auto;
}
.report-header {
font-size: 15px;
}
.report-header a {
text-decoration: none;
}
.report-header .time {
color: #909399;
margin-left: 10px;
}
.report-container .fail {
color: #F56C6C;
}
.report-container .is-active .fail {
color: inherit;
}
</style>

@ -1 +1 @@
Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9
Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1

View File

@ -10,7 +10,7 @@ const options = function (value, array) {
return value;
};
const timestampFormatDate = function (timestamp) {
const timestampFormatDate = function (timestamp, showMs) {
if (!timestamp) {
return timestamp
}
@ -34,7 +34,14 @@ const timestampFormatDate = function (timestamp) {
let s = date.getSeconds();
s = s < 10 ? ('0' + s) : s;
return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
let format = y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
if (showMs === true) {
let ms = date.getMilliseconds();
format += ':' + ms
}
return format
};
const filters = {

View File

@ -255,7 +255,7 @@ export function exportPdf(name, canvasList) {
}
}
pdf.save(name + '.pdf');
pdf.save(name.replace(" ", "_") + '.pdf');
}

View File

@ -468,6 +468,7 @@ export default {
input_url: "Please enter the request URL",
input_path: "Please enter the request path",
name: "Name",
content_type: "Content Type",
method: "Method",
url: "URL",
path: "Path",
@ -597,6 +598,7 @@ export default {
scenario_name: "Scenario name",
response_time: "Response time(ms)",
latency: "Latency",
start_time: "Start Time",
request_size: "Request Size",
response_size: "Response Size",
response_code: "Response Code",

View File

@ -468,6 +468,7 @@ export default {
input_url: "请输入请求URL",
input_path: "请输入请求路径",
name: "请求名称",
content_type: "请求类型",
method: "请求方法",
url: "请求URL",
path: "请求路径",
@ -597,6 +598,7 @@ export default {
delete_confirm: '确认删除报告: ',
delete_batch_confirm: '确认批量删除报告',
scenario_name: "场景名称",
start_time: "开始时间",
response_time: "响应时间(ms)",
latency: "网络延迟",
request_size: "请求大小",

View File

@ -470,6 +470,7 @@ export default {
name: "請求名稱",
method: "請求方法",
url: "請求URL",
content_type: "請求類型",
path: "請求路徑",
address: "請求地址",
refer_to_environment: "引用環境",
@ -597,6 +598,7 @@ export default {
delete_confirm: '確認刪除報告: ',
delete_batch_confirm: '確認批量刪除報告',
scenario_name: "場景名稱",
start_time: "開始時間",
response_time: "響應時間(ms)",
latency: "網絡延遲",
request_size: "請求大小",