Software testing - Postman Script script function

As a very popular debugging tool in software testing, Postman provides us with an environment to execute JavaScript scripts, so we can use js language to write scripts to solve some interface automation problems, such as interface dependencies, interface assertions, and so on. Postman has two modules for writing js scripts, Pre-RequestScript and Tests, which support the dynamic preparation of test data in the form of embedded scripts, and design test cases according to business requirements.

Postman running sequence: Before each request, first run the method in Pre-requestScript, and then call the interface - run the method endTime in Tests

一、Pre-request Script

In fact, this module is mainly to write a Pre-request Script and customize the request before sending the request. For example, there is a query interface that needs to pass in the query time, and the parameter names are endTime and beginTime. This is implemented through the code in the Pre-request Script. Every time before calling the interface, the date endTime and beginTime are obtained first, and then stored as environment variables or global variables, which are provided to the interface to pass parameters.
insert image description here
Every time the interface is called, the endTime and beginTime values ​​of the global variables will be updated.
insert image description here

2. Tests

After receiving the response, we can use Tests to process the returned data. Mainly those places that deal with interface dependencies and implement interface assertions.

1. Interface parameter dependence: We solve the interface parameter dependence problem by obtaining the value in the returned data and saving or updating it as an environment variable or global variable.

2. Assertion: It is mainly to judge whether the data returned by the interface contains each specific value, and to check whether the interface is normal. For example, get the token parameter value when returning data from the login interface, then save it in a global variable, and call it for the subsequent interface.
insert image description here
If the following interface needs to use the user token as an input parameter, it can be called by referencing the value of the global variable token
insert image description here


              [The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled]


1. From entry to mastery of Python programming

2. Interface automation project actual combat 

3. Actual Combat of Web Automation Project


4. Actual Combat of App Automation Project 

5. Resume of first-tier manufacturers


6. Test and develop DevOps system 

7. Commonly used automated testing tools

Eight, JMeter performance test 

9. Summary (little surprise at the end)

life is long so add oil. Every effort will not be let down, as long as you persevere, there will be rewards in the end. Cherish your time and pursue your dreams. Don't forget the original intention, forge ahead. Your future is in your hands!

Life is short, time is precious, we cannot predict what will happen in the future, but we can grasp the present moment. Cherish every day and work hard to make yourself stronger and better. Firm belief, persistent pursuit, success will eventually belong to you!

Only by constantly challenging yourself can you constantly surpass yourself. Persist in pursuing your dreams and move forward bravely, and you will find that the process of struggle is so beautiful and worthwhile. Believe in yourself, you can do it! 

Guess you like

Origin blog.csdn.net/nhb687095/article/details/132022305