Use postman as an interface to test the method of passing in a large number of dynamic parameters

Postman is a very useful interface testing tool, and its functions are also very powerful. Today, I will simply talk about how to use postman to test a large number of parameters passed in an interface.

Take the platform I tested as an example. Our platform is an online education platform. The scenario I simulated is that the teacher has a class called ABC, and now 1,000 students need to join the ABC class. It is impossible for us to manually operate 1000 times, so we need to use tools at this time. Suppose the interface for students to join the ABC course is like this: https://hhhh.com/addstu/addcourse

The parameter student uuid is one of the parameters required by this interface. After calling this interface, students will join the course successfully, thus achieving our test purpose, that is, to allow 1000 students to enter the class. The above is the test scenario.

The general idea of ​​the implementation method is to store the uuids of 1,000 students in a file, use the runner tool of postman, select the uuid storage file of 1,000 students that we have prepared in the input parameters, and iterate the interface 1,000 times. Finish.

Step 1: Create a new collection in postman, and add the interface we use under the collection, as shown in Figure 1 (the uuid parameter needs to be passed by variable, and how to use variable to pass parameters will not be repeated here)

 

Step two:

Run the script tab page before the request (click Pre-request Script) to add the script statement of the set variable:

pm.environment.set("uuidE", data.uuidmm);
Among them, uuidE is the variable name defined in the global variable, data.uuidmm is the uuid array we read in the file, and uuidmm is the column saved in the variable storage file Name, the column names used in the script here must be consistent with the column names in the file.

Step 3: Open the runner of the collection. See the figure below for the opening method. It is clear at a glance, so I won’t say more.

After opening the runner, we come to our most critical step, which is the function of setting parameter iteration.

 

 For the Data item, click the select File button to select the uuid.txt file we have prepared, and select the corresponding file type for Data File Type. Here I am a txt file type, so I select text/csv. Preview is to preview the selected file. The most important thing The most important thing is that Iteration needs to be set to the number of times we need to iterate. There are 1000 uuids in my file, so I need to iterate 1000 times. Check the interfaces that need to be run on the right side. Some irrelevant interfaces do not need to be checked directly, so don’t waste the server . After the above settings are completed, click to start running, and wait for the operation to complete, and you're done.

Note the following points:

1. There must be a column name in the file that saves the iteration variable, as shown in the figure below, the column name can be named whatever you like, but there must be a column name.

2. The variable names in the data array in the script added by Pre-request Script must be exactly the same as the column names in the file, otherwise postman will not find the variables and will fail.

Guess you like

Origin blog.csdn.net/lzz718719/article/details/130901837