测试任务执行前端功能
This commit is contained in:
@@ -6,16 +6,18 @@ import com.test.common.core.domain.AjaxResult;
|
|||||||
import com.test.common.core.page.TableDataInfo;
|
import com.test.common.core.page.TableDataInfo;
|
||||||
import com.test.common.enums.BusinessType;
|
import com.test.common.enums.BusinessType;
|
||||||
import com.test.common.utils.DateUtils;
|
import com.test.common.utils.DateUtils;
|
||||||
import com.test.test.domain.TestCase;
|
import com.test.common.utils.SecurityUtils;
|
||||||
import com.test.test.domain.TestTask;
|
import com.test.test.domain.TestTask;
|
||||||
import com.test.test.domain.qo.GroupIdQO;
|
import com.test.test.domain.qo.GroupIdQO;
|
||||||
import com.test.test.domain.qo.IDQO;
|
import com.test.test.domain.qo.IDQO;
|
||||||
import com.test.test.service.ITestTaskService;
|
import com.test.test.service.ITestTaskService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务Controller
|
* 定时任务Controller
|
||||||
@@ -23,6 +25,10 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/test/task")
|
@RequestMapping("/test/task")
|
||||||
public class TestTaskController extends BaseController {
|
public class TestTaskController extends BaseController {
|
||||||
|
|
||||||
|
@Value("${test.jmeterHomePath:/opt/apache-jmeter}")
|
||||||
|
private String jmeterHomePath;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ITestTaskService testTaskService;
|
private ITestTaskService testTaskService;
|
||||||
|
|
||||||
@@ -73,5 +79,18 @@ public class TestTaskController extends BaseController {
|
|||||||
return toAjax(testTaskService.deleteTestTaskById(qo.getId()));
|
return toAjax(testTaskService.deleteTestTaskById(qo.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行任务
|
||||||
|
*/
|
||||||
|
@Log(title = "任务", businessType = BusinessType.OTHER)
|
||||||
|
@PostMapping("/run")
|
||||||
|
public AjaxResult run(@RequestBody IDQO qo) {
|
||||||
|
// 异步执行任务
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
testTaskService.executeTestTaskById(qo.getId(), 2, null, jmeterHomePath, SecurityUtils.getUsername());
|
||||||
|
});
|
||||||
|
return toAjax(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class TestCaseStepServiceImpl implements ITestCaseStepService {
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
for (TestCaseResult testCaseResult : testCaseResultList) {
|
for (TestCaseResult testCaseResult : testCaseResultList) {
|
||||||
String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, testCaseResult.getExecuteTime());
|
String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, testCaseResult.getExecuteTime());
|
||||||
testCaseResult.setTitle("结果" + i + "(" + dateStr + "),状态:" + testCaseResult.getStatus());
|
testCaseResult.setTitle("结果" + i + "(" + dateStr + "),状态:" + testCaseResult.getStatus() + ",耗时(ms):" + testCaseResult.getUseTime());
|
||||||
i ++;
|
i ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,9 +110,8 @@ public class TestTaskServiceImpl implements ITestTaskService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean executeTestTaskById(Long id, Integer triggerType, String environment, String jmeterHomePath, String operUser) {
|
public boolean executeTestTaskById(Long id, Integer triggerType, String environment, String jmeterHomePath, String operUser) {
|
||||||
TestTask testTask = testTaskMapper.selectTestTaskById(id);
|
TestTask testTask = testTaskMapper.selectTestTaskById(id);
|
||||||
if (testTask == null || testTask.getStatus() == null
|
if (testTask == null || "2".equals(testTask.getDelFlag())) {
|
||||||
|| testTask.getStatus() > 0 || "2".equals(testTask.getDelFlag())) {
|
log.error("定时任务已删除,不能执行!");
|
||||||
log.error("定时任务已删除或未启用,不能执行!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TestTaskLog testTaskLog = new TestTaskLog();
|
TestTaskLog testTaskLog = new TestTaskLog();
|
||||||
|
|||||||
@@ -44,3 +44,12 @@ export function delTask(id) {
|
|||||||
data: {id}
|
data: {id}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 执行用例
|
||||||
|
export function runTask(id) {
|
||||||
|
return request({
|
||||||
|
url: '/test/task/run',
|
||||||
|
method: 'post',
|
||||||
|
data: {id}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,13 +1,29 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container" v-loading="loading">
|
<div class="app-container" v-loading="loading">
|
||||||
<el-form :model="form" ref="form">
|
<el-form :model="form" ref="form">
|
||||||
<el-form-item label="用例名称" prop="name">
|
<el-row :gutter="20">
|
||||||
<el-input v-model="form.name" placeholder="请输入用例名称"/>
|
<el-col :span="12">
|
||||||
</el-form-item>
|
<el-form-item label="用例名称" prop="name">
|
||||||
|
<el-input v-model="name" placeholder="请输入用例名称" :disabled="isDisabled"/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12">
|
||||||
|
<el-form-item label="用例状态" prop="status">
|
||||||
|
<el-select v-model="status" placeholder="请选择用例状态" :disabled="isDisabled">
|
||||||
|
<el-option
|
||||||
|
v-for="item in caseStatusOptions"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
<el-tabs>
|
<el-tabs>
|
||||||
<el-tab-pane label="接口编排">
|
<el-tab-pane label="接口编排">
|
||||||
<step @submit="submit"/>
|
<step @data-from-child="handleChildData" @submit="submit"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<!-- <el-tab-pane label="操作日志">-->
|
<!-- <el-tab-pane label="操作日志">-->
|
||||||
<!-- </el-tab-pane>-->
|
<!-- </el-tab-pane>-->
|
||||||
@@ -27,19 +43,37 @@ export default {
|
|||||||
getCase(this.$route.query.id).then(res => {
|
getCase(this.$route.query.id).then(res => {
|
||||||
this.form = res.data;
|
this.form = res.data;
|
||||||
this.name = res.data.name
|
this.name = res.data.name
|
||||||
|
this.status = res.data.status
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
form: {},
|
form: {},
|
||||||
name: "",
|
name: "",
|
||||||
|
status: "",
|
||||||
|
isDisabled: true,
|
||||||
|
caseStatusOptions: [{
|
||||||
|
value: 1,
|
||||||
|
label: '草稿'
|
||||||
|
}, {
|
||||||
|
value: 2,
|
||||||
|
label: '通过'
|
||||||
|
}, {
|
||||||
|
value: 3,
|
||||||
|
label: '不通过'
|
||||||
|
}],
|
||||||
loading: false
|
loading: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleChildData(data) {
|
||||||
|
this.isDisabled = data;
|
||||||
|
},
|
||||||
submit(list) {
|
submit(list) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
if (this.form.name !== this.name) {
|
if (this.form.name !== this.name || this.form.status !== this.status) {
|
||||||
|
this.form.name = this.name;
|
||||||
|
this.form.status = this.status;
|
||||||
updateCase(this.form).then(res => {
|
updateCase(this.form).then(res => {
|
||||||
this.saveStep(list)
|
this.saveStep(list)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
caseEditVisible() {
|
caseEditVisible() {
|
||||||
this.isVisible = true;
|
this.isVisible = true;
|
||||||
|
this.$emit('data-from-child', false);
|
||||||
},
|
},
|
||||||
handleRun(id) {
|
handleRun(id) {
|
||||||
this.$modal.confirm('是否确认执行用例?').then(function () {
|
this.$modal.confirm('是否确认执行用例?').then(function () {
|
||||||
@@ -216,6 +217,7 @@ export default {
|
|||||||
},
|
},
|
||||||
submit() {
|
submit() {
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
|
this.$emit('data-from-child', true);
|
||||||
this.$emit("submit", this.list);
|
this.$emit("submit", this.list);
|
||||||
},
|
},
|
||||||
cancel() {
|
cancel() {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<el-table v-loading="loading" :data="dataList" @row-click="handleRowClick">
|
<el-table v-loading="loading" :data="dataList" @row-click="handleRowClick">
|
||||||
<el-table-column label="自动化测试名称" align="center" prop="name"/>
|
<el-table-column label="自动化测试名称" align="center" prop="name"/>
|
||||||
<el-table-column label="cron表达式" align="center" prop="crontab"/>
|
<el-table-column label="cron表达式" align="center" prop="crontab"/>
|
||||||
<el-table-column label="定时任务开关" align="center" prop="status" :formatter="row => row.status ? '开启' : '关闭'"/>
|
<el-table-column label="定时任务开关" align="center" prop="status" :formatter="row => row.status === 0? '开启' : '关闭'"/>
|
||||||
<el-table-column label="创建人" align="center" prop="createBy"/>
|
<el-table-column label="创建人" align="center" prop="createBy"/>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime"/>
|
<el-table-column label="创建时间" align="center" prop="createTime"/>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
import FolderPage from "@/components/FolderPage/index.vue";
|
import FolderPage from "@/components/FolderPage/index.vue";
|
||||||
import {addTask, delTask, listTask} from "@/api/test/task";
|
import {addTask, delTask, listTask, runTask} from "@/api/test/task";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Task",
|
name: "Task",
|
||||||
@@ -94,7 +94,12 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleRun(id) {
|
handleRun(id) {
|
||||||
|
this.$modal.confirm('是否确认立即执行任务?').then(function () {
|
||||||
|
return runTask(id);
|
||||||
|
}).then(() => {
|
||||||
|
this.getList();
|
||||||
|
this.$modal.msgSuccess("执行成功");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user