feat: 显示Jmeter的内置函数提示

This commit is contained in:
Captain.B 2020-08-10 14:59:20 +08:00
parent 18eb1827ef
commit da226cf76e
6 changed files with 54 additions and 8 deletions

View File

@ -76,6 +76,7 @@
</span> </span>
<p>{{ $t('api_test.request.parameters_filter_example') }}@string(10) | md5 | substr: 1, 3</p> <p>{{ $t('api_test.request.parameters_filter_example') }}@string(10) | md5 | substr: 1, 3</p>
<p>{{ $t('api_test.request.parameters_filter_example') }}@integer(1, 5) | concat:_metersphere</p> <p>{{ $t('api_test.request.parameters_filter_example') }}@integer(1, 5) | concat:_metersphere</p>
<p><strong>{{ $t('api_test.request.parameters_filter_tips') }}</strong></p>
</div> </div>
</div> </div>
</el-dialog> </el-dialog>
@ -84,7 +85,7 @@
<script> <script>
import {KeyValue} from "../model/ScenarioModel"; import {KeyValue} from "../model/ScenarioModel";
import {MOCKJS_FUNC} from "@/common/js/constants"; import {JMETER_FUNC, MOCKJS_FUNC} from "@/common/js/constants";
import {calculate} from "@/business/components/api/test/model/ScenarioModel"; import {calculate} from "@/business/components/api/test/model/ScenarioModel";
export default { export default {
@ -159,7 +160,7 @@ export default {
}; };
}, },
funcSearch(queryString, cb) { funcSearch(queryString, cb) {
let funcs = MOCKJS_FUNC; let funcs = MOCKJS_FUNC.concat(JMETER_FUNC);
let results = queryString ? funcs.filter(this.funcFilter(queryString)) : funcs; let results = queryString ? funcs.filter(this.funcFilter(queryString)) : funcs;
// callback // callback
cb(results); cb(results);

View File

@ -43,6 +43,10 @@ export const calculate = function (itemValue) {
return; return;
} }
try { try {
if (itemValue.trim().startsWith("${")) {
// jmeter 内置函数不做处理
return itemValue;
}
let funcs = itemValue.split("|"); let funcs = itemValue.split("|");
let value = Mock.mock(funcs[0].trim()); let value = Mock.mock(funcs[0].trim());
if (funcs.length === 1) { if (funcs.length === 1) {

View File

@ -111,3 +111,41 @@ export const MOCKJS_FUNC = [
{name: '@id'}, {name: '@id'},
{name: '@increment'} {name: '@increment'}
] ]
export const JMETER_FUNC = [
{name: "${__threadNum}"},
{name: "${__samplerName}"},
{name: "${__machineIP}"},
{name: "${__machineName}"},
{name: "${__time}"},
{name: "${__log}"},
{name: "${__logn}"},
{name: "${__StringFromFile}"},
{name: "${__FileToString}"},
{name: "${__CSVRead}"},
{name: "${__XPath}"},
{name: "${__counter}"},
{name: "${__intSum}"},
{name: "${__longSum}"},
{name: "${__Random}"},
{name: "${__RandomString}"},
{name: "${__UUID}"},
{name: "${__BeanShell}"},
{name: "${__javaScript}"},
{name: "${__jexl}"},
{name: "${__jexl2}"},
{name: "${__property}"},
{name: "${__P}"},
{name: "${__setProperty}"},
{name: "${__split}"},
{name: "${__V}"},
{name: "${__eval}"},
{name: "${__evalVar}"},
{name: "${__regexFunction}"},
{name: "${__escapeOroRegexpChars}"},
{name: "${__char}"},
{name: "${__unescape}"},
{name: "${__unescapeHtml}"},
{name: "${__escapeHtml}"},
{name: "${__TestPlanName}"},
]

View File

@ -387,6 +387,7 @@ export default {
path_description: "etc/login", path_description: "etc/login",
parameters: "Query parameters", parameters: "Query parameters",
parameters_filter_example: "Example", parameters_filter_example: "Example",
parameters_filter_tips: "Only support MockJs function result preview",
parameters_advance: "Advanced parameter settings", parameters_advance: "Advanced parameter settings",
parameters_preview: "Preview", parameters_preview: "Preview",
parameters_preview_warning: "Please enter the template first", parameters_preview_warning: "Please enter the template first",
@ -497,9 +498,9 @@ export default {
execution_result: ": Please select the execution result", execution_result: ": Please select the execution result",
actual_result: ": The actual result is empty", actual_result: ": The actual result is empty",
case: { case: {
input_test_case:'Please enter the associated case name', input_test_case: 'Please enter the associated case name',
test_name:'TestName', test_name: 'TestName',
other:'--Other--', other: '--Other--',
test_case: "Case", test_case: "Case",
move: "Move case", move: "Move case",
case_list: "Test case list", case_list: "Test case list",

View File

@ -387,6 +387,7 @@ export default {
parameters_filter: "内置函数", parameters_filter: "内置函数",
parameters_filter_desc: "使用方法", parameters_filter_desc: "使用方法",
parameters_filter_example: "示例", parameters_filter_example: "示例",
parameters_filter_tips: "只支持 MockJs 函数结果预览",
parameters_advance: "高级参数设置", parameters_advance: "高级参数设置",
parameters_preview: "预览", parameters_preview: "预览",
parameters_preview_warning: "请先输入模版", parameters_preview_warning: "请先输入模版",

View File

@ -386,6 +386,7 @@ export default {
url_invalid: "URL無效", url_invalid: "URL無效",
parameters: "請求參數", parameters: "請求參數",
parameters_filter_example: "示例", parameters_filter_example: "示例",
parameters_filter_tips: "只支持MockJs函數結果預覽",
parameters_advance: "高級參數設置", parameters_advance: "高級參數設置",
parameters_preview: "預覽", parameters_preview: "預覽",
parameters_preview_warning: "請先輸入模版", parameters_preview_warning: "請先輸入模版",
@ -496,9 +497,9 @@ export default {
execution_result: ": 請選擇執行結果", execution_result: ": 請選擇執行結果",
actual_result: ": 實際結果為空", actual_result: ": 實際結果為空",
case: { case: {
input_test_case:'請輸入關聯用例名稱', input_test_case: '請輸入關聯用例名稱',
test_name:'測試名稱', test_name: '測試名稱',
other:'--其他--', other: '--其他--',
test_case: "測試用例", test_case: "測試用例",
move: "移動用例", move: "移動用例",
case_list: "用例列表", case_list: "用例列表",