1. Preparation

1.1 Scenario Presetting

In the previous test, a scene of registration and login was isolated. However, in the actual scene, most users have logged in and remain logged in. The user’s login information may be saved in the cookie of the browser or in the LOCALstorage of the App.

Therefore, a typical e-shopping mall scene is extracted from the default user login state. The interfaces involved are as follows:

  • 1) Browse the home page
  • 2) Add browsing history (automatic trigger)
  • 3) Add items/shopping cart
  • 4) Order placing/settlement

1.2 Token Data Preparation

In this demonstration scenario, the Authorization in the header is carried by the token value to complete the authentication of user identity. The registration and login script created before is used to obtain many user token values and save them locally for testing:

– Using Jmeter parameterization function +JSR223 PreProcessor+JSON Extractor to complete the registration login data driver

2. Scripting

2.1 Viewing the Home Page

  • Since every request requires a token in the Header, we use HTTP Header Manager to set a global variable

  • 2) Parameterized acquisition of token Data — CSV Data set Config Using CSV Data set Config, obtain the token value prepared in TokenFile in advance, and pass it to the variable ${auth}

  • Transaction Controller: Transaction Controller: Transaction Controller: Transaction Controller: Transaction Controller: Transaction Controller: Transaction Controller: Transaction Controller: Transaction Controller

  • 3) Control the ratio of interfaces on the home page — Loop Controller The home page has many categories of goods. Here, it is assumed that the list of categories of goods will be accessed twice after visiting the home page once. The Loop Controller is called /home/productcatelist /{parentId} twice:

  • 4) parentId is required for the commodity classification interface:

    In general, it is not recommended to use the same ID in the pressure test script to access. First, it is easy to hit the cache. Even without Redis cache, MySQL will optimize the loading of the same request, which will cause errors between the test data and the real scene. Therefore, we still choose to obtain the classification ID in advance and pass it in through CSV Data set Config

    Look at the database, different levels have a variety of classification information

    Get all of them after de-replayparent_id:

    Save parentId to file and set CSV:

    $ cat parentId_Data
    0
    1
    12
    2
    3
    4
    5
    Copy the code

  • 5) The setting of obtaining recommended products is consistent with the page view:

  • 6) Control the proportion of thematic interfaces on the home page — If Controller here, we set the scene that the number of users visiting the topic is half of the main page, then use the definition of if Controller writing method to make the number of requests not be executed when the number of requests is 2 integer, so as to ensure that the number of requests can be halved, as follows:

    About /home/subjectList utilizationCSV Data set ConfigThe way of parameterization is the same as the above classification information interface, which will not be described here:

    • aboutif ControllerFunction description:

    The above Function generation can use the __jexl3 Function or __groovy Function in the Tools->Function Helper Dialog to evaluate the expression of the judgment condition and generate the corresponding evaluation operation Function. Then copy this function to the Expression input box of the If Controller:

    In this example, we need to obtain the number of user requests first. We can select __counter in Function Helper, set it to true, and click Generate & Copy to clipbord to Generate the Function

    Copy the function and select it again__jexl3And then set the function that generates counter when it cannot be an integer 2:

3. Practical operation demonstration

The first page of the script has been completed, and the interfaces are arranged in a 2:4:2:1 ratio. Then run the script to check the effect

  • Run the script once for the first 10 threads to verify the correctness of the script: the result shows that the interface was successfully requested in a 2:4:2:1 ratio
  • If the pressure test continues, you can also see the test data displayed in Grafana:

4. Notice of the next period

In the future, we will continue to complete the test of order and payment scenario, for details, please refer to the article: Performance Test based on e-commerce mode (V) Complete a daily pressure test of typical e-commerce scene based on Jmeter (order and payment)