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 = "/",
requestMethod = "GET", protocol = "http", requestArguments = new Map(), domain = "", port = ""} = obj;
let uri = `new URIBuilder()
.setScheme("${protocol}")
.setHost("${domain}")
.setPort(${port}) // int类型端口
.setPath("${requestPath}")
`;
.setScheme("${protocol}")
.setHost("${domain}")
.setPath("${requestPath}")
`;
// http 请求类型
let method = requestMethod.toLowerCase().replace(/^\S/, s => s.toUpperCase());
let httpMethodCode = `Http${method} request = new Http${method}(uri);`;
@ -155,7 +154,15 @@ function _beanshellTemplate(obj) {
for (let [k, v] of requestArguments) {
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 = "";
for (let [k, v] of requestHeaders) {