8 years of experience - authentication processing in the interface testing framework!

There is usually an authentication mechanism in the interface automation test, which is to judge whether it is in the login state, and the interface can be called only if the user is logged in, and cannot be called if the user is not logged in. This article will lead you to learn to use the rest-assured framework to realize the authentication association based on cookies and tokens, and realize the automatic testing of the interface.

1. Authentication association based on cookies

1. Familiar with business interface

The code classmate full-stack interface project has a cookie-based query balance interface. You must first call the login interface to obtain the cookie and pass it to the query balance interface. The information of the two interfaces is as follows

2. View cookies by capturing packets

Log in to the banking system on the page, capture the packet through the Chrome developer tool, and you can see that the cookie information is generated in the interface return after the login is successful

3. Use the rest-assured framework to implement cookie association

First, use the script to call the login interface and get the cookie from the returned information. The code is as follows. After the method is executed, the logged-in cookies will be stored in the cookies object in the code

Secondly, call the query balance interface, and add cookies objects in the request information, so that the query balance interface can bring valid cookies when requesting, the code is as follows

现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:110685036

2. Token-based authentication association

1. Familiar with business interface

There is a token-based query balance interface in the code classmate full-stack interface project. You must first call the login interface to obtain the token and pass it to the query balance interface. The information of the two interfaces is as follows

2. Capture packets and analyze token generation and delivery

Log in to the banking system on the page, capture the packet through the fiddler tool, and you can see that the data information generated in the interface return after the login is successful is the value of the token

Then we analyze how the token information is transmitted when the interface for querying the balance is initiated. It is still captured by the fidder tool. We can find that there is a field called testfan-token in the header of the request, and the corresponding value is returned by the login interface. token value

3. Use the rest-assured framework to implement token association

First, use the script to call the login interface and get the token from the returned information. The code is as follows. After the method is executed, the logged-in token value will be stored in the token variable in the code

Secondly, call the query balance interface, and add header information in the request information, so that the query balance interface can bring a valid token when requesting, the code is as follows

Well, whether it’s cookies or tokens, we already have the associated use in the rest-assured framework, let’s try it out

The following are supporting learning materials. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse also accompanied me through the most difficult journey. I hope it can help you too!

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

Information acquisition method:

Supongo que te gusta

Origin blog.csdn.net/jiangjunsss/article/details/132611078
Recomendado
Clasificación