diff --git a/frontend/src/components/business/ms-common-script/ms-script-menu.vue b/frontend/src/components/business/ms-common-script/ms-script-menu.vue index 23c17281b3..b484edc8a0 100644 --- a/frontend/src/components/business/ms-common-script/ms-script-menu.vue +++ b/frontend/src/components/business/ms-common-script/ms-script-menu.vue @@ -108,6 +108,16 @@ headers.set('Content-type', 'application/json'); return getCodeTemplate(innerLanguageType.value, { requestHeaders: headers }); } + case 'api_stop': { + if (innerLanguageType.value === LanguageEnum.PYTHON) { + return ` + import java + StandardJMeterEngine = java.type('org.apache.jmeter.engine.StandardJMeterEngine') + StandardJMeterEngine.stopThreadNow(ctx.getThread().getThreadName()) + `; + } + return 'ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName());'; + } default: return ''; } diff --git a/frontend/src/components/business/ms-common-script/scriptDefined.vue b/frontend/src/components/business/ms-common-script/scriptDefined.vue index 9809ec02b2..700ef03d00 100644 --- a/frontend/src/components/business/ms-common-script/scriptDefined.vue +++ b/frontend/src/components/business/ms-common-script/scriptDefined.vue @@ -75,7 +75,7 @@ import { useVModel } from '@vueuse/core'; import MsCodeEditor from '@/components/pure/ms-code-editor/index.vue'; - import { Language } from '@/components/pure/ms-code-editor/types'; + import { Language, LanguageEnum } from '@/components/pure/ms-code-editor/types'; import MsTag from '@/components/pure/ms-tag/ms-tag.vue'; import FormApiImportDrawer from './formApiImportDrawer.vue'; import InsertCommonScript from './insertCommonScript.vue'; @@ -161,10 +161,17 @@ } else { let scriptStr = ''; data.forEach((item) => { - scriptStr += ` + if (item.type === LanguageEnum.PYTHON) { + scriptStr += ` +# ${item.name} +${item.script} +`; + } else { + scriptStr += ` // ${item.name} ${item.script} `; + } }); codeEditorRef.value?.insertContent(scriptStr); showInsertDrawer.value = false; diff --git a/frontend/src/components/business/ms-common-script/utils.ts b/frontend/src/components/business/ms-common-script/utils.ts index a97bc626ae..d12abb1dc5 100644 --- a/frontend/src/components/business/ms-common-script/utils.ts +++ b/frontend/src/components/business/ms-common-script/utils.ts @@ -49,7 +49,8 @@ export const SCRIPT_MENU: CommonScriptMenu[] = [ }, { title: t('project.processor.terminationTest'), - value: 'ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName());', + value: 'api_stop', + command: 'api_stop', }, ]; @@ -235,17 +236,20 @@ function _pythonCodeTemplate(obj) { const host = domain + (port ? `:${port}` : ''); - return `import httplib,urllib + return `import http.client +import urllib.parse params = ${reqBody} #例 {'username':'test'} headers = ${headers} #例 {'Content-Type':'application/json'} 或 {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'} +# Specify the host and the HTTP endpoint you want to hit host = '${host}' path = '${requestPath}' method = '${requestMethod}' # POST/GET -conn = httplib.${connType}(host) -conn.request(method, path, params, headers) +conn = http.client.${connType}(host) +conn.request(method, path, urllib.parse.urlencode(params), headers) res = conn.getresponse() -data = unicode(res.read(), 'utf-8') +data = res.read().decode('utf-8') +conn.close() log.info(data) `; } diff --git a/frontend/src/locale/en-US/index.ts b/frontend/src/locale/en-US/index.ts index 131e5e9663..53ed64bf24 100644 --- a/frontend/src/locale/en-US/index.ts +++ b/frontend/src/locale/en-US/index.ts @@ -25,12 +25,12 @@ export default { ' menu.bugManagement.bugRecycle': 'Recycle', 'menu.caseManagement': 'Case Management', 'menu.apiTest': 'API Test', - 'menu.apiTest.debug': 'API debug', + 'menu.apiTest.debug': 'Debug', 'menu.apiTest.debug.debug': 'Debug', - 'menu.apiTest.management': 'API Management', - 'menu.apiTest.management.definition': 'API Definition', + 'menu.apiTest.management': 'Definition', + 'menu.apiTest.management.definition': 'Definition', 'menu.apiTest.scenario': 'Scenario', - 'menu.apiTest.report': 'API Report', + 'menu.apiTest.report': 'Report', 'menu.uiTest': 'UI Test', 'menu.performanceTest': 'Performance Test', 'menu.projectManagement': 'Project', diff --git a/frontend/src/locale/zh-CN/index.ts b/frontend/src/locale/zh-CN/index.ts index 660d274993..7c5982ad6a 100644 --- a/frontend/src/locale/zh-CN/index.ts +++ b/frontend/src/locale/zh-CN/index.ts @@ -25,13 +25,13 @@ export default { 'menu.bugManagement.bugRecycle': '回收站', 'menu.caseManagement': '用例管理', 'menu.apiTest': '接口测试', - 'menu.apiTest.debug': '接口调试', + 'menu.apiTest.debug': '调试', 'menu.apiTest.debug.debug': '调试', - 'menu.apiTest.management': '接口管理', - 'menu.apiTest.management.definition': '接口定义', + 'menu.apiTest.management': '定义', + 'menu.apiTest.management.definition': '定义', 'menu.apiTest.api': 'API列表', 'menu.apiTest.scenario': '场景', - 'menu.apiTest.report': '接口报告', + 'menu.apiTest.report': '报告', 'menu.uiTest': 'UI测试', 'menu.workstation': '工作台', 'menu.loadTest': '性能测试', diff --git a/frontend/src/views/project-management/commonScript/utils.ts b/frontend/src/views/project-management/commonScript/utils.ts index 7364f4485a..571c99be85 100644 --- a/frontend/src/views/project-management/commonScript/utils.ts +++ b/frontend/src/views/project-management/commonScript/utils.ts @@ -48,7 +48,8 @@ export const SCRIPT_MENU: CommonScriptMenu[] = [ }, { title: t('project.processor.terminationTest'), - value: 'ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName());', + value: 'api_stop', + command: 'api_stop', }, ]; diff --git a/frontend/src/views/project-management/fileManagement/locale/en-US.ts b/frontend/src/views/project-management/fileManagement/locale/en-US.ts index 671088f442..f9340c2888 100644 --- a/frontend/src/views/project-management/fileManagement/locale/en-US.ts +++ b/frontend/src/views/project-management/fileManagement/locale/en-US.ts @@ -138,7 +138,7 @@ export default { 'project.fileManagement.caseFileVersion': 'Associated file version', 'project.fileManagement.caseTypeBug': 'Bug', 'project.fileManagement.caseTypeFeature': 'Feature', - 'project.fileManagement.caseTypeApiDebug': 'Api debug', + 'project.fileManagement.caseTypeApiDebug': 'Debug', 'project.fileManagement.caseTypeApiScene': 'Api scene', 'project.fileManagement.caseTypeApiCase': 'Api case', 'project.fileManagement.caseTypeApiDefine': 'Api definition', diff --git a/frontend/src/views/project-management/fileManagement/locale/zh-CN.ts b/frontend/src/views/project-management/fileManagement/locale/zh-CN.ts index 30ca02d730..6889d8992e 100644 --- a/frontend/src/views/project-management/fileManagement/locale/zh-CN.ts +++ b/frontend/src/views/project-management/fileManagement/locale/zh-CN.ts @@ -130,7 +130,7 @@ export default { 'project.fileManagement.caseFileVersion': '关联的文件版本', 'project.fileManagement.caseTypeBug': '缺陷', 'project.fileManagement.caseTypeFeature': '功能用例', - 'project.fileManagement.caseTypeApiDebug': '接口调试', + 'project.fileManagement.caseTypeApiDebug': '调试', 'project.fileManagement.caseTypeApiScene': '接口场景', 'project.fileManagement.caseTypeApiCase': '接口用例', 'project.fileManagement.caseTypeApiDefine': '接口定义',