System Performance Testing (JMeter)

Purpose

  • Consolidate what you have learned about system performance testing
  • Master the skills of performance testing and be able to complete simple performance testing independently
  • Improve the practical ability to use the performance testing tool (JMeter)

Environmental preparation

  • Virtual machine installed Windows7 system
    virtual machine installed Windows7 steps
  • Prepare the tested Web system (recommended Web Tours, hereinafter referred to as WTours), if conditions permit, it is recommended to install the tested system on an independent server (or virtual machine), and keep the testing machine with access to the tested system. The system’s network connection
    virtual machine installs WTours steps
  • A test (master) machine
      JDK installed with JDK and JMeter installed, there are also in the above steps to install WTours, if you follow the above steps to install WTours, you can complete it together, here is a separate post: [Install JDK on a virtual machine Steps]
    to install JMeter on a virtual machine with detailed steps
  • One or more test (load) machines with JRE and JMeter installed
  • Network connection to ensure that the tester can access the system under test

Testing process

Step1: Record the script (method 1 is used here)

Use BadBoy (recommended) or JMeter proxy to record the initial script that generates the user booking

  • Method 1: BadBoy recording script (the easiest way, you can also export to JMeter after recording)
     The following items 1-5 are the basic functions of BadBoy, and the sixth item is the official start
     1. After entering the url address, click the green arrow
      The red origin means “start recording”, the
      black square has been selected by default: stop recording, need to stop manually
     2.
      Right-click step1->Play All to play back the script, or use the toolbar button
     3. Export the script to .jmx format
      File–>Export to Jmeter
     4. jmeter import jmx script
      to open JMeter
       to find the JMeter path you installed, then bin/jmeter.bat, double-click to execute the
      file -> open, select the .jmx file
     5.jmeter playback script
      Right-click Step1 under ThreadGroup -> Add -> Listener -> View Results Tree
      Click “View Results Tree”, click the green triangle icon in the toolbar to
      view the playback results in graphical mode,
       click “View” Result tree”–> select “HTML” in the drop-down list–> select a URL–> click “response data”
    to start using
     6. Start BadBoy, under the installation path, double-click badboy.exe
     7. Start WebTours, in the path where you saved WebTours, double-click xigui32.exe, and a successful startup sign will appear in the lower right corner of the taskbar
     8. Enter the address of WTours in the BadBoy address bar (http://your IP address: 1080/webtours/), click the green arrow, it will jump to the WebTours web page
     9. At the same time, you can find that our operations, requests, and responses are automatically recorded in the Script column on the left.
     10. Start to complete a complete set of booking operations, first log in to your registered account (if you follow the [steps I provided to install WTours] before , I will talk about registering an account first, so I won’t go into details here)
     11. Click the Flights button on the page to enter the flight search page, where you can choose at will, and then click continue
     12. In the displayed page, select the flight called flight, you can choose any, and then click continue
     13. Fill in the payment details, fill in freely, and then click continue
     14. After the booking is completed, the page displays the booking information
     15. Click Book Another in the picture, then after the page jumps, click Sign Off on the left
     16. To end the recording, click the red circle in the upper toolbar
     17. Play back the script to see if the recording is successful, right-click and select Step1 – click Play All
     18. How to save the script locally
     19. The script will be used later in JMeter, so export the script to a format that JMeter can use
     At this point, the BadBoy recording is over, let’s start to operate in JMeter
     1. Open JMeter, in the path where JMeter is saved, execute bin/jmeter.bat to start
     2. Open the jmx file previously saved in BadBoy
      Description of the figure above: In the tree view in the left column, you can see our recorded content in the step. Here, the content just recorded is mainly converted into the ThreadGroup thread group under TestPlan in JMeter, in the thread group , added a loop controller (ie Step1), in addition, it also includes the manager of HTTP Cookie, user-defined variables, and manager of Http request headers
     . –> View the result tree, then select Step1, click the green triangle at the top, run the script, and then click View the result tree under Step1, you can view the response results

      So far, the initial operation script in JMeter has a basic understanding, and then jump to Step2 to start to enhance the script

  • Method 2: JMeter proxy recording script
     1. Set the IP address for the computer
     2. Set the proxy server in the browser
      Open the browser -> Tools -> Internet Options -> Connection -> LAN Settings -> Check “Set proxy server for LAN” “, address input JMeter’s IP, port 8888 (Jmeter default)
     3. Add a thread group to the test plan and
      add “Configuration Element”—>http cookie manager, otherwise it will affect the associated effect
     4. Add “Non-Test Element” under the workbench –> HTTP proxy server
      target controller: Test plan –> Thread group
      grouping:   no  sample
     grouping

  • Method 3: Write the script yourself

Step2: Enhance the script

    1. Add transaction: Add a transaction controller to the script, and classify each request into the corresponding transaction according to the functions it implements, thereby improving the modularity of the script
        – the method of creating a transaction controller
        – Modify the transaction controller name and manually drag different types of requests to the transaction controller,
        click the created transaction controller, and you can change the name on the right side
       - The following figure is given here, which is to divide the request into different modules according to different functions (create a transaction controller multiple times, and then change the name)
    1. Add assertion: Check the key requests in the user booking process (such as opening the home page, user login, user booking, etc.) and their responses
        – add a response assertion to visiting the home page
        (1) First analyze the result tree generated before , Steps: Click to view the result tree, switch to the HTML view, and find the corresponding position in the result tree of the last request in the access home page
        (3) Right-click to select the last in the transaction controller to access the home page. a request, adding a response assertion
        . In addition, some assertions have been added in other places. The content and location of the assertion are given below. You can refer to the above “Add access home page assertion”. For example, you can complete it by yourself
        (1) Response assertion – user login successfully
        (4) Response assertion – logout successful
    1. Add a loop controller: Allows users to reorder multiple different tickets; add other components (such as Debug PostProcessor or BeanShell PostProcessor) to the script as needed, and debug the enhanced script until it works correctly
        – before In the process of , only 1 ticket can be ordered at a time. By setting the loop controller, multiple tickets can be ordered at one time. The following is an example of ordering 3 tickets
        – (1) Create a loop controller and set the number of loops Set to 3, then put the transaction controller for booking the ticket into the loop controller
        – (2) In order to select different departure places and destinations in the 3 bookings, perform the third step of parameterization processing
    1. Parameterization: Create a test data file for key parameters in the booking process (such as user name, password, origin, destination, etc.), and parameterize it in the script-
        (1) Select this option to book 3 tickets Loop controller, right click to create a CSV Data Set Config
        – (2) This component can support obtaining data from a CSV data source we specify, so we need to create a txt file as the data source of the component to obtain data, here we use relative paths to set, that is, directly in Just create a txt file in the bin directory of the JMeter installation path, and then directly reference it in Filename
        – (3) Set CSV Data Source
        – (4) Associate the paired variables set in the CSV in the flight search request, and modify the depart and arrive
        – (5) For the convenience of checking the number of bookings, you can add a counter to the “book 3 tickets” loop controller
        Associate the counter in the transaction controller “Reservation Ticket”
    1. Association: In order to ensure the normal execution of the booking business, the necessary association must be established between the parameters of the relevant request in the script and the response (such as the session value UserSession)
        – (1) Explain the reason for this step: If you execute Go to the fourth step above, and then execute the test script. It is found that it will not succeed. The reason is that when the login operation is performed in the script (that is, the first request under the user login transaction controller), a userSession data will be sent, and the userSession The value of the userSession will change every time you visit the home page, so we need to get the value of the userSession generated during each visit, and then fill it in the parameter userSession sent when logging in, as shown in the following figure.
        According to the comparison of the above 1 and 3, it can be found that the values ​​are different-
        (2) Create a regular expression extractor to extract the userSession when accessing the home page,
        – (3) Pass the extracted userSession into the request parameters submitted during login
        – (4) Additional processing: In order to achieve random selection of flights during the flight booking process, regular expressions can also be used to extract the data in the search flight, and then associate the data in the flight selection, and the subsequent steps are all to achieve this function-
        ( 5) Set up a regular expression extractor in the flight search request (strong reminder: the regular expressions in the following two figures have a space after the second left parenthesis)
        – (6) Associate the obtained random departure and return flights with the request parameters for selecting flights and completing payment
        – (7) In addition, a response assertion to confirm the success of the booking needs to be set where the payment is completed.
        – (8) Then in the response assertion, what test mode should be added? You can choose to judge whether the booking information displayed on the page where the payment is completed is consistent with the flight information provided in the previous flight search and selection flight , so it is necessary to extract the flight number, date and other information from the selected flight again as a basis
        – (9) Use BeanShell PostProcessor to extract the selected flight information, and create it in Find Flights
        Add the following code to the script:

${__split(${chosenRandomOutBoundFlight},outBoundFlightDetails,;)}
${__split(${chosenRandomReturnFlight},returnFlightDetails,;)}
responseMessage = "${outBoundFlightDetails_1}" + "${returnFlightDeatils_1}";

– (10) Add test mode in response assertion – booking success
  – (11) Right-click ThreadGroup for script running test
  and generate a viewing result tree
  – (12) Select ThreadGroup, click the green triangle symbol on the upper toolbar, and then click to view the result tree

– (13) Save the stand-alone test file to prepare for later
The single-user test has ended successfully.
  Here are a few problems encountered: The first one is when writing the regular expression selector, I did not notice that there is a space after the second left parenthesis in the regular expression. It was not found at the beginning, resulting in the flight number not always being obtained; the second is in the response assertion that the booking is successful, because it is a two-way ticket, the from and to of the two test modes (that is, the origin and destination are to be Upside down), I didn’t pay attention at the beginning, which led to the assertion always failing, and it took a long time for error correction

Step3: Scenario design (multiple users and booking tickets)

  • Through timers (in JMeter), and design multiple sets of loads (mainly reflected in different numbers of concurrent users)
  • The following steps need to use the final test result file of the previous step. First, copy a copy of the previous single-machine test file, then change the name to multi-user and book tickets, then open JMeter, and open the new file, as shown in the figure below, the rest is in the file make changes in
  • (1) Create a CVS under ThreadGroup to save the username and password
  • (2) “Register” accounts on WTours in batches (I unified account number test + serial number, password 1234).
     First of all, let me explain that all WTours accounts are stored locally, and the path is: your WebTours location/ MercuryWebTours/users, I used a root user before, so a file named root will be displayed here, we only need to create 100 files according to this file format, here is a .bat script file, just run, with these file, then it is equivalent to having registered these users on WTours
  • (3) In the same way in the bin directory of JMeter, create a bat script file to help us generate the information corresponding to the user password
  • (4) Modify the login request, parameterize the user name and password
  • (5) Set the properties of the thread group, adjust the number of concurrently executed threads, click ThreadGroup, and set it in the right column
  • (6) Set the timer. If we need to let every 5 users perform the operation of booking 3 tickets at the same time, we need to use the synchronous timer at this time. Here, we will briefly introduce the synchronous timer and
     create a synchronous timer . , drag it before booking 3 tickets
      the second parameter: if the timeout time is set to 0, the thread will wait for the number of threads to reach the set value before releasing. If the number of threads is less than the number set in the rendezvous point, it will always be waiting; if the set time is greater than 0, then if the value set in the simulated user group has not been reached after the set maximum waiting time, the thread group will no longer wait , release the arriving thread
     transfer Step4, and add some listeners that can be used to observe the results of multi-user concurrent execution

Step4: Run unit tests in GUI and monitor scenarios

  • Add necessary listeners to scripts (such as graph results, view results in tables, aggregate reports, etc.), run tests in JMeterGUI interface, view and analyze test results
  • (1) Connect to Step3, right-click to select ThreadGroup, and add three common listeners based on the original
  • (2) Start execution, select ThreadGroup, and click the green triangle at the top

Step5: Multi-machine joint test

  • Distribute the set load balance to the multi-state load machines, prepare corresponding test data for each load machine, start the test operation of multiple load machines through the control machine, and view and analyze the test results

Step6: Use a non-GUI way to run the test

Leave a Comment

Your email address will not be published. Required fields are marked *