Search code examples
loopsjmeterbeanshell

Jmeter Loop : Changing path value on each loop iteration


I am having a single HTTP Request which i need to execute with three different values in path as

Request : ${base_url}/1/file/object/${objPath}/file/${XLSXFileId}/process

  1. /file/${XLSXFileId}/process
  2. /file/${XLSFileId}/process
  3. /file/${CSVFileId}/process

Is there any way to achieve this by using loop controller so that i don't need to make individual requests


Solution

  • You can add a BeanShell PostProcessor as a child of the previous request after the JSON Extractor with the below code in the script area (The request which you extract the values of these variables from ${XLSXFileId} ${XLSFileId} ${CSVFileId}):

    vars.put("Var_1",vars.get("XLSXFileId"));
    vars.put("Var_2",vars.get("XLSFileId"));
    vars.put("Var_3",vars.get("CSVFileId"));
    

    Then add a ForEach Controller with the below configurations:

    • Input variable prefix: Var
    • Output variable name: MyVar

    Now add your request as a child of the ForEach Controller and edit the path to the below:

    ${base_url}/1/file/object/${objPath}/file/${MyVar}/process
    

    This ForEach Controller will execute your request 3 times, each time the value of the variable ${MyVar} will be different.