当前位置:网站首页>Authentication processing in interface testing framework

Authentication processing in interface testing framework

2022-07-01 16:18:00 Code classmate software test

picture
There is usually an authentication mechanism in interface automated testing , It is to judge whether it is in the login state , The logged in party can call the interface , If you are not logged in, you cannot call . This article will lead you to learn and use rest-assured The framework implementation is based on cookies and token Authentication Association of , Realize interface automation test .

1
be based on cookies Authentication Association of

  1. Familiar with business interface

    Code classmate full stack interface project is based on cookies Query balance interface , You must call the login interface to get cookie And pass it to the query balance interface , The information of the two interfaces is as follows

 picture

  1. View through packet capture cookies

    Log in to the banking system on the page , adopt Chrome Developer tools grab packages , You can see that after the login is successful, the interface returns cookie Information

 picture

  1. Use rest-assured Framework implementations cookie relation

First , Use script to call login interface , And get from the returned information cookie, The code is as follows , After the method is executed, the logged in cookies Stored in code cookies In the object

 picture

secondly , Call the query balance interface , And add cookies object , In this way, the query balance interface can bring validity when requesting cookies, The code is as follows

 picture

2
be based on token Authentication Association of

  1. Familiar with business interface

    Code classmate full stack interface project is based on token Query balance interface , You must call the login interface to get token And pass it to the query balance interface , The information of the two interfaces is as follows

 picture

  1. Caught analysis token The generation and transmission of

Log in to the banking system on the page , adopt fiddler Tool grab bag , You can see the generated in the interface return after successful login data The message is token Value
 Insert picture description here

Then let's analyze the interface for querying the balance when it is initiated token How information is transmitted , Is still fidder Tool grab bag , We can find in the request header There is a field called testfan-token, The corresponding value is returned by the login interface token value

 Insert picture description here

  1. Use rest-assured Framework implementations token relation

First , Use script to call login interface , And get from the returned information token, The code is as follows , After the method is executed, the logged in token Values are stored in the code token variable

 picture

secondly , Call the query balance interface , And add header Information , In this way, the query balance interface can bring validity when requesting token, The code is as follows

 picture

Okay , Whether it's cookies still token, We all have in rest-assured Associated use of framework , Try it now

原网站

版权声明
本文为[Code classmate software test]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207011600002593.html