From 47d997866a2edbacfa6688814636447b218149c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=98=84=EC=84=B1=ED=95=84?= Date: Mon, 19 Feb 2024 15:18:14 +0900 Subject: [PATCH] =?UTF-8?q?APIClient=20variable=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ApiTestManager/src/APIClient.js | 28 +++++++++++-------- ApiTestManager/src/APITester.js | 4 --- .../service/LoadTestGraphBuilder.java | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ApiTestManager/src/APIClient.js b/ApiTestManager/src/APIClient.js index c18a00b..99cc6bd 100644 --- a/ApiTestManager/src/APIClient.js +++ b/ApiTestManager/src/APIClient.js @@ -12,7 +12,6 @@ class APIClient { constructor() { window.globals = {}; - this.variables = {}; this.abortController = null; this.contextPath = document.querySelector('meta[name="context-path"]').getAttribute('content'); @@ -31,8 +30,9 @@ class APIClient { async sendAPIRequest(model, preProcessCallback, consoleOutput) { try { - const updatedModel = await this.executePreRequestScript(model, consoleOutput); - let processedRequest = this.replacePlaceholdersWithVariables(updatedModel); + let variables = {}; + const updatedModel = await this.executePreRequestScript(model, variables, consoleOutput); + let processedRequest = this.replacePlaceholdersWithVariables(updatedModel, variables); if (preProcessCallback) { preProcessCallback(processedRequest); @@ -46,7 +46,7 @@ class APIClient { } const finalResponse = this.formatResponse(responseData); - return this.executePostRequestScript(model.postRequestScript, finalResponse, consoleOutput).catch(error => { + return this.executePostRequestScript(model.postRequestScript, variables, processedRequest, finalResponse, consoleOutput).catch(error => { $('.toast-body').text(error); $('.toast').toast('show'); return finalResponse; // Return the original response even if there's an error in the post-request script @@ -99,7 +99,7 @@ class APIClient { } } - replacePlaceholdersWithVariables(original) { + replacePlaceholdersWithVariables(original, variables) { let request = JSON.parse(JSON.stringify(original)); let mergedVariables = {}; @@ -107,8 +107,8 @@ class APIClient { mergedVariables[key] = value; }); - if (this.variables) { - _.forEach(this.variables, (value, key) => { + if (variables) { + _.forEach(variables, (value, key) => { mergedVariables[key] = value; }); } @@ -139,12 +139,12 @@ class APIClient { return request; } - executePreRequestScript(model, consoleOutput) { + executePreRequestScript(model, variables, consoleOutput) { return new Promise((resolve, reject) => { let script = model.preRequestScript; let resultFrame = document.getElementById('preRequest'); - this.variables = {}; + window.preRequestComplete = (updatedModel, error) => { if (error) { @@ -154,7 +154,7 @@ class APIClient { } }; - window.temp_variable = this.variables; + window.temp_variable = variables; window.currentRequest = model; window.consoleOutput = consoleOutput; resultFrame.srcdoc = `