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

Jmeter Interface testing practice-interesting cookie

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Jmeter Interface testing practice-interesting cookie

Scene:

Interface testing often requires login, request method (post), login common methods are to obtain token, session, cookie, and so on. All of these have a common feature, validity period (expires).

The Session is valid after the connection is established, and the disconnected session is invalid. The token validity period is controlled by the server. The cookie is created when the user browses and visits, and is sent to the client by the server. The validity period is related to the server. The default values of different web servers are slightly different. In a temporary session cycle, cookie is generally not persisted, that is, closing the browser or logging out of the cookie is invalid.

How to get token has been introduced in our previous tweets (Jmeter API Test-regular expressions). Today, for cookie, since there is a validity period for using cookie, then exit or other circumstances invalidate cookie, isn't it very annoying to keep changing to the latest cookie in the interface test script? Is there any way to get rid of it once and for all? the answer is yes.

Actual combat:

Let's start with an example. First, let's find an interface that is already running (the original cookie acquires the dead cookie value in the custom variable, and then passes it to cookie manager), and looks for information in the result tree request-> request Body.

As can be seen from the figure, cookie data consists of several pieces of information.

Username

SESSION

SERVERID

So where can I get this information?

Using the developer tools of chrome, you can easily find the above information under the application tag.

With the above information, the next thing is easy to do. There are two ways to add

Http cookie manager (recommended)

Http Information Manager

Add cookie that needs to be stored in cookie management

Then delete the cookie value from the custom variable (the cookie value written to death) and use this method

To obtain cookie for other API under the same domain name, you can easily execute the API that requires login. Careful students will find that there are still username and SESSION in the cookie data that are not used. In my example, these two can be executed normally without using them. If you need to add them yourself, the interesting cookie can be used once and for all. You no longer have to worry about the expiration of cookie. I don't know if you have learned it or not. In the actual test scenario, problems like this often bother us, how to skillfully use the method to solve (lazy rule), the technical engineer who learns to be lazy is a qualified engineer.

Imagine, in this cold winter, on your own balcony, turning on your cell phone, sitting on the sofa, emptying yourself, listening to Huang Xiaofeng's [not that simple], making a pot of good tea, lazily basking in the sun, all the testing work has scripts we have written to execute for us, and the implementation results are sent to our mobile phones, and we only need to click on the phone to know whether it is perfect. Suddenly I heard a phone call from my boss. Why didn't I come to work? I woke up from my dream and found that I had overtaken my nap.

Today's recommended reading articles are recommended

Why do interface testing?

JMeter database operation

Jmeter Interface Test-regular expression

JMeter returns garbled code in Chinese

Jmeter interface testing-parameterization

JMeter Interface testing-Basics

Test-impression

Add Wechat to the consulting work

scan a QR code

Welcome self-recommendation and recommendation, need Wechat to push resume!

Please poke the QR code below to learn more.

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