You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a tester with no programming skills. I use Maplocal or breakpoints on a daily basis. I noticed the scripts tab and wondered what it could be useful to me.
I am thinking about the case when I want to modify one value in the response without having to manually set up a breakpoint (situation when I need to have fresh /unique data in the response, but I need to change something specific)
As I do not know much about programming I asked the gpt chat to create such a script, unfortunately, despite many attempts/changes/analysis of errors, the data is not changed in the final response.
So, there is a simple response body (Json) with 3 attributes {"messages":10,"id":115,"card":0} , the goal is to change the response body for only messages value.
This is what i get from chatgpt:
function onResponse(context) {
if (context.response && context.response.body) {
let body = context.response.body;
try {
let json = JSON.parse(body);
json.messages = 1;
body = JSON.stringify(json);
context.response.body = body;
console.log("Modified response body:", body);
} catch (e) {
console.error("Error parsing JSON:", e);
}
} else {
console.log("Response body is empty or undefined.");
}
return context.response;
}
and this is na answer :
Response body is empty or undefined.
The text was updated successfully, but these errors were encountered:
functiononRequest(context,url,request){// Set JSON contentrequest.headers["Content-Type"]="application/json";// Get Request bodyvarjsonBody=request.body;// Modify datajsonBody["name"]="Proxyman";jsonBody["flatform"]="macOS";jsonBody["info"]={"website": "proxyman.io","region": "Earth"};// Set it again request.body=jsonBody;returnrequest;}
the situation I needed was to change the response, but this was very helpful! the final script is working <3
and it looks like this
function onResponse(context, url, request) {
// Set JSON content
response.headers["Content-Type"] = "application/json";
// Get Request body
var jsonBody = response.body;
// Modify data
jsonBody["messages"] = 1;
// Set it again
response.body = jsonBody;
return response;
}
I am a tester with no programming skills. I use Maplocal or breakpoints on a daily basis. I noticed the scripts tab and wondered what it could be useful to me.
I am thinking about the case when I want to modify one value in the response without having to manually set up a breakpoint (situation when I need to have fresh /unique data in the response, but I need to change something specific)
As I do not know much about programming I asked the gpt chat to create such a script, unfortunately, despite many attempts/changes/analysis of errors, the data is not changed in the final response.
So, there is a simple response body (Json) with 3 attributes {"messages":10,"id":115,"card":0} , the goal is to change the response body for only messages value.
This is what i get from chatgpt:
and this is na answer :
Response body is empty or undefined.
The text was updated successfully, but these errors were encountered: