fix(自定义代码片段): 从API定义导入,自动生成的脚本报错

--bug=1007475 --user=lyh 【接口测试】前置脚本-从API定义导入,自动生成的脚本报错了
https://www.tapd.cn/55049933/s/1061715
This commit is contained in:
shiziyuan9527 2021-10-29 16:16:01 +08:00 committed by shiziyuan9527
parent e48d9d99d2
commit ac5ff17af5
1 changed files with 13 additions and 6 deletions

View File

@ -143,11 +143,10 @@ function _beanshellTemplate(obj) {
let {requestHeaders = new Map(), requestBody = "", requestPath = "/", let {requestHeaders = new Map(), requestBody = "", requestPath = "/",
requestMethod = "GET", protocol = "http", requestArguments = new Map(), domain = "", port = ""} = obj; requestMethod = "GET", protocol = "http", requestArguments = new Map(), domain = "", port = ""} = obj;
let uri = `new URIBuilder() let uri = `new URIBuilder()
.setScheme("${protocol}") .setScheme("${protocol}")
.setHost("${domain}") .setHost("${domain}")
.setPort(${port}) // int类型端口 .setPath("${requestPath}")
.setPath("${requestPath}") `;
`;
// http 请求类型 // http 请求类型
let method = requestMethod.toLowerCase().replace(/^\S/, s => s.toUpperCase()); let method = requestMethod.toLowerCase().replace(/^\S/, s => s.toUpperCase());
let httpMethodCode = `Http${method} request = new Http${method}(uri);`; let httpMethodCode = `Http${method} request = new Http${method}(uri);`;
@ -155,7 +154,15 @@ function _beanshellTemplate(obj) {
for (let [k, v] of requestArguments) { for (let [k, v] of requestArguments) {
uri = uri + `.setParameter("${k}", "${v}")`; uri = uri + `.setParameter("${k}", "${v}")`;
} }
uri = uri + ".build();"; if (port) {
uri += `.setPort(${port}) // int类型端口
`;
uri += ` .build();`;
} else {
uri += `// .setPort(${port}) // int类型端口
`;
uri += ` .build();`;
}
// 设置请求头 // 设置请求头
let setHeader = ""; let setHeader = "";
for (let [k, v] of requestHeaders) { for (let [k, v] of requestHeaders) {