전체 실행 추가
This commit is contained in:
@@ -277,6 +277,7 @@ class APIScenario {
|
|||||||
stopScenario() {
|
stopScenario() {
|
||||||
if (this.executor)
|
if (this.executor)
|
||||||
this.executor.reset();
|
this.executor.reset();
|
||||||
|
this.outputEditor.setValue('');
|
||||||
}
|
}
|
||||||
|
|
||||||
addStart() {
|
addStart() {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class APIScenarioExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Method to execute the current node's API request if it's an 'api' node
|
// Method to execute the current node's API request if it's an 'api' node
|
||||||
executeCurrentNode() {
|
executeCurrentNode2() {
|
||||||
console.log(this.currentNodeId)
|
console.log(this.currentNodeId)
|
||||||
|
|
||||||
let allNodes = document.querySelector('#drawflow').querySelectorAll('.drawflow-node');
|
let allNodes = document.querySelector('#drawflow').querySelectorAll('.drawflow-node');
|
||||||
@@ -89,6 +89,69 @@ class APIScenarioExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executeCurrentNode() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
console.log(this.currentNodeId)
|
||||||
|
|
||||||
|
let allNodes = document.querySelector('#drawflow').querySelectorAll('.drawflow-node');
|
||||||
|
allNodes.forEach(node => {
|
||||||
|
node.classList.remove('current-execution');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!this.currentNodeId) {
|
||||||
|
console.log('No current node to execute.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentNode = this.graph[this.currentNodeId];
|
||||||
|
|
||||||
|
if (currentNode) {
|
||||||
|
this.isRunning = true;
|
||||||
|
this.visitedNodes.add(this.currentNodeId); // Mark this node as visited
|
||||||
|
|
||||||
|
let nodeElement = document.querySelector('#drawflow').querySelector(`.drawflow-node[id="node-${this.currentNodeId}"]`);
|
||||||
|
if (nodeElement) {
|
||||||
|
nodeElement.classList.add('current-execution');
|
||||||
|
} else {
|
||||||
|
console.error('Node with ID ' + this.currentNodeId + ' not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentNode.class === 'api') {
|
||||||
|
let model = JSON.parse(JSON.stringify(this.apiTester.getApiRequestModel(currentNode.data.id)));
|
||||||
|
model.responseModel = {};
|
||||||
|
this.apiClient.sendAPIRequest(model, this.logHttpRequest.bind(this))
|
||||||
|
.then(response => {
|
||||||
|
this.isRunning = false;
|
||||||
|
this.logHttpResponse(response);
|
||||||
|
if (response.status === 200 || response.status === 201) {
|
||||||
|
nodeElement.classList.add('result-success');
|
||||||
|
} else {
|
||||||
|
nodeElement.classList.add('result-error');
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
nodeElement.classList.add('result-abort');
|
||||||
|
$('.toast-body').text(error.message);
|
||||||
|
$('.toast').toast('show');
|
||||||
|
this.appendLog(error.message);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
console.log(`Executing API request for node: ${currentNode.id} - ${currentNode.name}`);
|
||||||
|
} else if (currentNode.class === 'start') {
|
||||||
|
this.appendLog('Starting API scenario execution...');
|
||||||
|
nodeElement.classList.add('result-success');
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
console.log(`Executing script for node: ${currentNode.id} - ${currentNode.name}`);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
appendLog(text) {
|
appendLog(text) {
|
||||||
var range = new monaco.Range(this.outputEditor.getModel().getLineCount(), 1, this.outputEditor.getModel().getLineCount(), 1);
|
var range = new monaco.Range(this.outputEditor.getModel().getLineCount(), 1, this.outputEditor.getModel().getLineCount(), 1);
|
||||||
var id = {major: 1, minor: 1};
|
var id = {major: 1, minor: 1};
|
||||||
@@ -141,11 +204,24 @@ class APIScenarioExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Method to execute the entire scenario from start to end
|
// Method to execute the entire scenario from start to end
|
||||||
|
// async executeAll() {
|
||||||
|
// while (this.currentNodeId) {
|
||||||
|
// console.log(this.currentNodeId)
|
||||||
|
// this.executeCurrentNode(); //TODO: how can I make sure this call wait until response is received
|
||||||
|
// await this.moveToNextNodeWithDelay(250);
|
||||||
|
// }
|
||||||
|
// console.log('Completed execution of all API nodes.');
|
||||||
|
// }
|
||||||
async executeAll() {
|
async executeAll() {
|
||||||
while (this.currentNodeId) {
|
while (this.currentNodeId) {
|
||||||
console.log(this.currentNodeId)
|
console.log(this.currentNodeId);
|
||||||
this.executeCurrentNode();
|
try {
|
||||||
await this.moveToNextNodeWithDelay(500);
|
await this.executeCurrentNode();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error executing node: ', error);
|
||||||
|
// Handle error or break loop if necessary
|
||||||
|
}
|
||||||
|
await this.moveToNextNodeWithDelay(250);
|
||||||
}
|
}
|
||||||
console.log('Completed execution of all API nodes.');
|
console.log('Completed execution of all API nodes.');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user