Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Performance testing-introduction to regular expressions associated with JMeter

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Why should it be related?

In the process of communication between the client and the server, the data between multiple requests / responses will be interdependent. For example, some response data returned from the previous request needs to be used in subsequent requests.

Here are some typical examples:

1) for example, the session id obtained from the first visit to the website will be passed to the website on subsequent requests.

2) the server generates token and returns it to the user, and the token should be included in subsequent requests.

3) query a record according to the condition, and select the record in the query result set for operation (such as deletion)

...

However, some communication protocols are stateless and there is no context sensitivity. Data between multiple requests / responses cannot be passed directly

And each time the data returned by the server is not immutable, the transmitted data can not be hard-coded (written to death) to be saved.

For example, the above three cases will produce dynamic data:

1) the life cycle of session id usually ends when the browser is closed, and the session id returned for each browser visit is not the same.

2) token also has a life cycle, which is generally random and stateless.

3) if the query condition is parameterized or the query result set returned by the server changes, the subsequent operation may fail.

In these cases, you can consider saving the dynamically changed data returned by the server to a parameter and taking it out of it when needed.

I. the principle of relevance

For example, the process of watching a movie and watching a movie has the following steps:

1. Purchase tickets

two。 Check the ticket

3. Watch a movie

Each step can be seen as a request / response. The audience is equivalent to the client, and the cinema is equivalent to the server.

The process is shown in the following figure:

The movie tickets purchased by the audience can be regarded as the response data returned by the server, and the tickets must be checked before they can enter the cinema.

Audience ticket purchase is equivalent to a request, and ticket checking is the next request, which requires sending the response data (movie tickets) returned from the previous request to the server for processing in the next request.

Suppose the film is very wonderful and want to see it again, because the movie tickets can only be used once, and the audience must repurchase the tickets in order to pass the ticket checking; admission using the tickets purchased for the first time will certainly be turned away.

To solve this problem, consider making the following assumptions:

Every time you put your movie tickets into your portable LV wallet, and discard the used tickets before you put them in, so as to prevent you from getting the wrong ticket; when you enter, take out the ticket from your wallet to check the ticket, so it's foolproof.

Putting the movie ticket into the wallet is equivalent to saving the data returned by the server, where the wallet is the parameter to hold the associated data.

II. Definition of association

The process of saving qualified data in a packet returned by a server to a parameter.

How to save the data returned by the server? the post processor can be used in JMeter to process the associated data. The common methods are:

1. Regular expression extractor

2. JSON extractor

Characteristics that need to be associated with data

How to determine which data need to be associated can be identified from the characteristics of the associated data. The associated data has the following three characteristics:

1. The server returns

The data that needs to be associated must be returned from the server.

The data entered by the client does not need to be associated, such as the user name and password entered. This feature is required.

two。 The data will be sent to the server again for processing.

The purpose of saving the data in response to the previous request is to use it in the next request, otherwise it is meaningless to save it.

This feature is optional, which means it is possible to save data for association without sending it again.

3. Dynamic change of data

If the data of the last request response does not change dynamically, it can be written to death in the script without the need to save and retrieve it again.

It is precisely because of the dynamic changes of the data returned each time, we need to find out and save these dynamic data according to some rules.

Then the actual returned data will be taken out. But this feature is also optional. It can also be saved and associated without dynamic changes, but it doesn't make much sense.

III. Introduction to regular expressions

JMeter parses and processes regular expressions through embedded Apache Jakarta ORO software.

Jakarta-ORO is a set of Java classes for processing text. It is one of the most full-featured and best-performing regular expression API currently. It provides regular expressions that are compatible with Perl5 types.

Single-line mode and multi-line mode

Metacharacter

Extended regular expression

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report