15 | JMeter | Functions and Variables |

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

Комментарии • 26

  • @Gsuresh_3
    @Gsuresh_3 5 месяцев назад

    While giving function helper values, if I want to give dynamic values while running in HTTP request how to give? I mean one http request response I need to pass to function how to do?

    • @RaghavPal
      @RaghavPal  5 месяцев назад +1

      Suresh
      Let's break down the problem step by step.
      Problem Statement:
      You're using JMeter and want to pass dynamic values to a function helper while running an HTTP request. Specifically, you want to use the response from one HTTP request as an input to the function helper in another HTTP request.
      Step-by-Step Solution:
      1. Capture the response from the first HTTP request:
      Use a Regular Expression Extractor (RegExp Extractor) or JSON Extractor (if the response is in JSON format) to extract the required value from the response of the first HTTP request.
      * Add a RegExp Extractor or JSON Extractor as a child element of the first HTTP request.
      * Configure the extractor to extract the desired value from the response. For example, if the response is in JSON format, you can use a JSON Path expression to extract the value.
      * Give a name to the extracted variable, e.g., `myVariable`.
      2. Store the extracted value in a JMeter variable:
      The extracted value will be stored in a JMeter variable. You can use this variable in subsequent requests.
      3. Pass the variable to the function helper:
      In the second HTTP request, add a BeanShell PreProcessor or JSR223 PreProcessor as a child element.
      * In the preprocessor, use the JMeter variable `myVariable` as an input to the function helper.
      * Write a script that calls the function helper and passes the variable as an argument. For example, in BeanShell:
      ```java
      import my.function.helper.Class;
      // Get the extracted value from the previous request
      String myValue = vars.get("myVariable");
      // Call the function helper with the dynamic value
      Class.myFunction(myValue);
      ```
      4. Use the output of the function helper in the HTTP request:
      If the function helper returns a value, you can store it in another JMeter variable using the `vars` object. Then, you can use this variable in the HTTP request.
      For example, if the function helper returns a string value, you can store it in a variable `myOutput`:
      ```java
      String myOutput = Class.myFunction(myValue);
      vars.put("myOutput", myOutput);
      ```
      Now, you can use the `myOutput` variable in the HTTP request, e.g., as a parameter or in the request body.
      That's it! By following these steps, you should be able to pass dynamic values from one HTTP request
      -

    • @Gsuresh_3
      @Gsuresh_3 5 месяцев назад

      @@RaghavPal thank you, helpful

  • @vnecksurferdude7041
    @vnecksurferdude7041 3 года назад

    So whatever number of parameters a function can take in, one extra at the end will be a variable that can store the functions output value? Is that true for all Jmeter functions? If not, how do you know it's true for which ones?

    • @RaghavPal
      @RaghavPal  3 года назад +1

      Hi, yes, but you should check the syntax, it may differ for diff functions

  • @rahulsharma-xk6db
    @rahulsharma-xk6db 3 года назад +1

    Thanks sir

  • @yazh403
    @yazh403 2 года назад

    Hi bro , in html report , we get usually fail , 90 per , avg sample right?
    Instead of fail , can we change mode for pass count ? Is this possible?
    Plz give some tricks , i will catch up 🙏

    • @RaghavPal
      @RaghavPal  2 года назад

      Hi, you can check the HTML report configuration - jmeter.apache.org/usermanual/generating-dashboard.html

    • @yazh403
      @yazh403 2 года назад

      @@RaghavPal i have tried thjs format ,the transaction names updated correctly but pass details not come in html report bro

    • @RaghavPal
      @RaghavPal  2 года назад +1

      If I get something on this, will update here

    • @yazh403
      @yazh403 2 года назад

      @@RaghavPal if possible please make video bro . please

  • @in.meraki
    @in.meraki 3 года назад

    Sir Thank you for all the effort you are putting for us. Is this Jmeter series complete sir, or there will be more topics coming on this?

    • @RaghavPal
      @RaghavPal  3 года назад +1

      Hi, thanks, yes this is done and you can find more JMeter tutorials here - automationstepbystep.com/

    • @in.meraki
      @in.meraki 3 года назад

      @@RaghavPal Thank you for replying sir. 🙏

  • @manishvarshney12345
    @manishvarshney12345 Год назад

    Hi Raghav,
    First of all thank you so much for bringing simplicity in your contents and tutorials. I have a scenario where I need to execute multiple orders (Primary key is OrderID) for multiple users but each time the listener should have the different OrderID. The payload is there in the body part of the "Sampler". Now question is that how can I increment Order id for the next thread and send it to the respective end point? i.e each time the new request should be sent with payload having incremented Order id.
    Please help me out to solve this scenario :)

    • @RaghavPal
      @RaghavPal  Год назад

      Hi Manish,
      In JMeter, you can use a Counter or a User Defined Variable to increment the Order ID value for each thread. Here are the steps you can follow to achieve this:
      Define a User Defined Variable for the initial Order ID value. For example, you can set the variable name as OrderID and the initial value as 1000.
      In the HTTP Request Sampler, use ${OrderID} to reference the Order ID value in the request body. For example, if your request body looks like this:
      {
      "order_id": 1000,
      "customer_id": "12345",
      "product_id": "67890"
      }
      You can replace the order_id value with ${OrderID} like this:
      {
      "order_id": ${OrderID},
      "customer_id": "12345",
      "product_id": "67890"
      }
      Add a Counter or a User Defined Variable Config Element to the test plan. For example, you can add a Counter Config Element and set the Start value as 1000, the Increment value as 1, and the Reference Name as OrderID.
      In the Thread Group, set the Number of Threads to the number of users you want to simulate. For example, if you want to simulate 10 users, set the Number of Threads to 10.
      Set the Loop Count to the number of times you want each user to execute the HTTP Request Sampler. For example, if you want each user to execute the request 5 times, set the Loop Count to 5.
      Run the test plan, and JMeter will execute the HTTP Request Sampler for each thread, with the Order ID value incremented for each iteration.
      This way, each thread will have a unique Order ID value, and the value will be incremented for each iteration of the thread

  • @yazh403
    @yazh403 3 года назад

    Hi bro,
    If particular request failed and we hqve to omit that iteration , that time we can use "Result action control '.
    is there any other solution for jumping another iteration if we observe error in particular api ?
    Plz hlp me on that bro

    • @RaghavPal
      @RaghavPal  3 года назад

      Hi Yazh, yes, you can check this setting in Test Plan editor

    • @yazh403
      @yazh403 3 года назад

      @@RaghavPal if i did anything in test plan ,it will reflect whole api.
      "I want "particular api" getting error then jmeter have to start next iteration""

    • @RaghavPal
      @RaghavPal  3 года назад

      need to check why exactly a specific api is throwing error, can check controllers and loops

    • @yazh403
      @yazh403 3 года назад

      @@RaghavPal sometimes that api will work , sometimes not(may it will fail by increasing load )."thats is not a problem ".
      I have to say to my jmeter,hey that api fail ,u need to break current iteration and Start the next iteration .
      I can use result action controller but sometimes not working perfectly 🙂 thats why i am asking 🙏

    • @RaghavPal
      @RaghavPal  3 года назад

      Okay, this you can also do with scripting, check this
      stackoverflow.com/questions/24207638/jmeter-stop-current-iteration
      www.quora.com/How-do-I-exit-the-current-thread-loop-and-continue-to-the-next-in-JMeter

  • @JaaOffendJaa
    @JaaOffendJaa Год назад

    would u please give an example of split function

    • @RaghavPal
      @RaghavPal  Год назад

      Hi,
      The "Split Function" in Apache JMeter is a string manipulation function that is used to split a string into an array of substrings based on a specified delimiter.
      Here is an example of how you can use the split function in JMeter:
      Add a User Defined Variables element to your test plan.
      Define a variable with a string value that you want to split, for example: myString=apple,banana,cherry
      In a Sampler or another Post-Processor element, you can use the following syntax to split the string into an array:
      ${__split(myString, ",", myArray)}
      This will split the myString variable into an array myArray based on the comma delimiter. The resulting array can be accessed using the following syntax: ${myArray_1}, ${myArray_2}, etc.
      You can also use the split function to extract parts of the string, for example:
      ${__split(myString, ",", myArray)[1]}
      This will extract the second element of the array, which is banana.
      Note that the split function is available in Apache JMeter version 3.2 and later.