Want to use response body item in different post issue in my script. Is there any way holding response body item anywhere and getting that item in another post issue? Searched for k6 load test scripts but didn't find anything.Searching for alternative ways
Asked
Active
Viewed 1,279 times
0
-
1Not sure what you mean exactly. Access the response of a request with `response.body`, store it in a variable and then use this variable's value later? Or do you want to write the responses to disk and use them in a different process? Can you add a rough outline, perhaps with dummy code or comments, of your script(s) and expected/intended behavior? – knittl Feb 17 '22 at 13:51
1 Answers
1
k6's biggest strength is it's scriptable, you can use js.
To show an example, I'm using reqres.
import http from 'k6/http';
export default function(){
let response = http.get("https://reqres.in/api/users?page=1");
let users = response.json("data")
// List users
for (let user of users){
console.log(`${user.id}\t${user.first_name} ${user.last_name}`)
}
// Do some dummy PATCH operations, change their first_name to firstie
for (let user of users){
const response = http.patch(`https://reqres.in/api/users/${user.id}/`, JSON.stringify(
{
first_name: "firstie"
}
));
console.log(`User ${user.id} status code: ${response.status}`)
}
}

Umut Gerçek
- 630
- 6
- 9