Search code examples
jmeterperformance-testing

Jmeter On Demand triggering of any particular API during a test


I have a scenario where there is one particular API generates tokens in the below manner. Say it is generating 20 tokens now. I am passing all those token values into next 20 subsequent requests.

{

"data" : { "requestTokens" : [ "9FDE794DD00E4A09122343BDCAF214E9", "616C5DFFC1234516A925824AEA6EFE9F", "7A8C507EC1DF4AD88E0912345E1DB409", "763C32CF67899946B6BC946949BD1344", "3C143F2FC25E495012345500E0F343DF", "3FD78335C763420B1234574061D9417F", "C43C368A1E612345AB17D2BA2693BEAF", "56E8FA9036D3486123451DE3237004DC", "5867B8E399FB4E12345626337D0E143C", "D06B30BDEAFC4A7D8618BF67712345DB", "F795258D390D4812345EB62C83BEFC58", "F0829D861234560392DE432E121B3CD4", "C8B9D5E6BE6A465FB91B0123459FBA9A", "4169D93D97204123457BA5A98C914D27", "784809E5BCBF4F123459D7D848AD67CE", "D0BFDCDC13994C0123455B2B110C35F9", "4F59619BBEDE4FE812345EA14C5E785", "E3942AE182214605BE91234595D95C18", "2005C506659C425EAD2022446123459B", "FE716E2A13A74C759C12345AED5AD54C" ] } }

So this value 20 is dynamic. For now as work around I am capturing this 20 values as an array using JSON extractor and passing those values. But tomorrow if this value is changed to 10 my script will Fail. Because it generates 10 tokens and I am out of tokens after tenth request. Hence on demand we have to trigger that particular API which generates tokens and pass it to the subsequent requests. Is there some approach to handle this.


Solution

  • Both extraction and building the next request body can be done in JSR223 PostProcessor in Groovy language

    I cannot provide a code snippet because you didn't share the response data, in the meantime you can get familiarized with the following materials: