Simulating 100 users using Pre-Request and Tests

My question:
So i am trying to setup something is postman so that I can simulate new chat being created while hitting the api

Details (like screenshots):



Issue:

It not working I get status 200 put not simulating on FE. What I am doing wrong here

@kevinc-postman Any info you could share?

@sean.keegan - Any ideas

@bpricilla anything you could share ??

@kkalpana55 @rolerik - FYI

@michaelderekjones - If you can provide any info.

Your number environment variable appears to be an array, when it looks like it should just be a single entry.

What you probably need is two variables. One for the array, and one for the current number.

Personally I would call one “numberArray” and the other “currentNumber” to avoid all doubt when looking at the code.

Your pre-request script would retrieve the array and set the current number using the JavaScript array.shift() function to reduce the array and set the current number before saving both as environment variables.

Your tests tab would also retrieve the array, and then use setNextRequest if the array length is more than zero.

Please remember to stringify the object\array before saving it to the collectionVariable, and JSON.parse it when retrieving.

Lastly, you need to run this through the collection runner, otherwise setNextRequest will not be triggered. It only works through the runner.

Please note usage limits on the runner. (Hopefully you are on the enterprise license, otherwise you will run out of runs very quickly).

The following is an example using setNextRequest and array.shift().
Hopefully it shows the logic.

Pre-Request script

var array = JSON.parse(pm.collectionVariables.get("resources"));

if(array.length === 0){
    array = [
        "ba08971c-83de-777c-beb2-2dbe91e727e6",
        "c6ec9412-e19e-999-bcc8-0a9900f3c0ba",
        "268e8bd9-3381-0000-81d3-38fd4fa11110"
    ];
}

pm.test("pre-req array is not empty", () => {
    pm.expect(array).to.be.an("array").that.is.not.empty; 
});

var currentResource = array.shift();

pm.collectionVariables.set("id",currentResource);
pm.collectionVariables.set("resources", JSON.stringify(array));

Tests tab

var array = JSON.parse(pm.collectionVariables.get("resources"));

var expectedResponse = pm.collectionVariables.get("id");
var actualResponse = pm.response.json().args.test;

pm.test(`tests-tab id = ${expectedResponse}`, () => {
    pm.expect(actualResponse).to.eql(expectedResponse); 
});

if (array.length > 0){
    postman.setNextRequest("multiple_resources_delete_inonego");

} else {
    postman.setNextRequest(null);
}

pre request code :
var array = [
“what is RAM?”,
“what is adobe?”
];

pm.test(“pre-req array is not empty”, () => {
pm.expect(array).to.be.an(“array”).that.is.not.empty;
});

var currentResource = array.shift();

pm.collectionVariables.set(“id”,currentResource);
pm.collectionVariables.set(“resources”, JSON.stringify(array));
test script :
var array = JSON.parse(pm.collectionVariables.get(“resources”));
var expectedResponse = pm.collectionVariables.get(“id”);

// If there are elements left in the array, set up the next iteration
if (array.length > 0) {
// Shift the current array element from the array
var currentElement = array.shift();

// Compare the current element with the expectedResponse
pm.test(`Compare element: ${currentElement}`, () => {
    pm.expect(currentElement).to.eql(expectedResponse);
});

// Set the current element as the prompt value in the FormData body
pm.request.body.formdata.add({ key: 'prompt', value: currentElement });

// Update the collection variable "resources" with the modified array
pm.collectionVariables.set("resources", JSON.stringify(array));

postman.setNextRequest('Prompt');

} else {
postman.setNextRequest(null);
}

response :
pre-req array is not empty
FAIL
Compare element: what is adobe? | AssertionError: expected ‘what is adobe?’ to deeply equal ‘what is RAM?’
still second element is fetched


I have to define in this value according to the code