15 | JMeter | Functions and Variables |

Поділитися
Вставка
  • Опубліковано 20 чер 2021
  • All FREE courses - automationstepbystep.com/
    - What are functions
    - What are variables
    - How to use functions and variables
    Functions - methods used to populate fields in any other element of a test plan
    Syntax
    ${__funcName}
    ${__funcName(var1, var2, ….)}
    Variables - containers that can store values, which can be referred in any element within a thread
    ${varName}
    Never Stop Learning
    Raghav Pal
    Join Automation Step By Step channel: ua-cam.com/users/automationste...
    Stories by Raghav - automationstepbystep.com/stor...
    My Udemy Courses - automationstepbystep.com/udem...
    Every LIKE & SUBSCRIPTION gives me great motivation to keep working for you
    You can support my mission for education by sharing this knowledge and helping as many people as you can
    If my work has helped you, consider helping any animal near you, in any way you can.
    #JMeterBeginnerTutorials
    _______ ONLINE COURSES TO LEARN _______
    automationstepbystep.com/onli...
    GitHub - github.com/Raghav-Pal/
    Udemy - www.udemy.com/user/raghav-pal-3/
    Training by Raghav at your venue - raghav.qna@gmail.com
    Training schedule - automationstepbystep.com/trai...
    ----------- UI TESTING -----------
    Selenium Beginners - bit.ly/2MGRS8K
    Selenium Java Framework from Scratch - bit.ly/2N9xvR6
    Selenium Python - bit.ly/2oyMp5x
    Selenium Tips - bit.ly/2owxc50
    Selenium Builder - bit.ly/2MKNtlq
    Katalon Studio - bit.ly/2wARFdi
    Robot Framework with RIDE- bit.ly/2Px6Ue9
    Robot Framework with Eclipse - bit.ly/2N8DZxb
    Protractor - bit.ly/2KtqVkU
    TestProject - bit.ly/2DRNJYE
    ----------- API TESTING -----------
    Web Services (API) - bit.ly/2MGafL7
    SoapUI - bit.ly/2MGahmd
    Postman - bit.ly/2wz8LrW
    General - bit.ly/2PYdwmV
    Katalon Studio API Testing - bit.ly/2BwuCTN
    ----------- MOBILE TESTING -----------
    Appium - bit.ly/2ZHFSGX
    Mobile Playlist - bit.ly/2PxpeUv
    ----------- CI | CD | DEVOPS -----------
    Jenkins Beginner - bit.ly/2MIn8EC
    Jenkins Tips & Trick - bit.ly/2LRt6xC
    Docker - bit.ly/2MInnzx
    Kubernetes - bit.ly/2MJIlMK
    ------------VIRTUALISATION------------
    Virtualization on windows - bit.ly/2SItIL9
    ----------- VERSION CONTROL SYSTEM -----------
    Git & GitHub - bit.ly/2Q1pagY
    GitLab - bit.ly/2kQPGyQ
    ----------- PERFORMANCE TESTING -----------
    JMeter Beginner - bit.ly/2oBbtIU
    JMeter Intermediate - bit.ly/2oziNVB
    JMeter Advanced - bit.ly/2Q22Y6a
    JMeter Tips & Tricks - bit.ly/2NOfWD2
    Performance Testing - bit.ly/2wEXbLS
    ----------- PROGRAMMING -----------
    Java Beginners - bit.ly/2PVUcXs
    Java Tips & Tricks - bit.ly/2CdcDnJ
    GROOVY - bit.ly/2FvWV5C
    JAVASCRIPT - bit.ly/2KJDZ8o
    PYTHON - bit.ly/2Z4iRye
    ----------- IDE -----------
    Visual Studio Code - bit.ly/2V15yvt
    ----------- BUILD TOOLS -----------
    Maven - bit.ly/2NJdDRS
    Gradle - bit.ly/30l3h1B
    ----------- OTHERS -----------
    Redis- bit.ly/2N9jyCG
    Misc - bit.ly/2Q2q5xQ
    Tools & Tips - bit.ly/2oBfwoR
    QnA Friday- bit.ly/2NgwGpw
    Sunday Special - bit.ly/2wB23BO
    Ask Raghav - bit.ly/2CoJGWf
    Interviews - bit.ly/2NIPPxk
    All Playlists - bit.ly/2LSiezA
    ---------- Connect with Raghav -----------
    Website - automationstepbystep.com/
    LifeCharger - lifecharger.org/
    Udemy Courses - www.udemy.com/user/raghav-pal-3/
    Facebook - / automationstepbystep
    Twitter - / learnwithraghav
    UA-cam - / automationstepbystep
    Never Stop Learning
    Raghav

КОМЕНТАРІ • 26

  • @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

  • @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

  • @rahulsharma-xk6db
    @rahulsharma-xk6db 3 роки тому +1

    Thanks sir

  • @vnecksurferdude7041
    @vnecksurferdude7041 2 роки тому

    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  2 роки тому +1

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

  • @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. 🙏

  • @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

  • @K8LOYT
    @K8LOYT Рік тому

    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.

  • @yazh403
    @yazh403 2 роки тому

    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  2 роки тому

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

    • @yazh403
      @yazh403 2 роки тому

      @@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  2 роки тому

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

    • @yazh403
      @yazh403 2 роки тому

      @@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  2 роки тому

      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