Postman upgraded version (4)

Why parameterize the request

During the test, we need to constantly change our request parameters to cyclically issue requests to our interface. At this time, we need to parameterize the requested data, so that it is more in line with our automated testing standards, not only can be judged , And can also run automatically, which can be called automated testing
Insert picture description here
Insert picture description here

How to automate
  • First we need to parameterize the value of the request that will change
    Insert picture description here
  • Then we use the following picture as an example to test
    Insert picture description here
  • Next, let's run it
    Insert picture description here
    -and then the result we get is that although the request is successful, the result is wrong. The reason is that when the request is made, others don't know where the value of your node_name is obtained from.
Variable scope

How to get our variables, we can choose the environment. If it is not in the specified environment, the global variables are used by default. If the environment is selected, when the environment variables conflict with the global variables, the environment variables are used by default. Use, data is a variable imported from the document in the future
Insert picture description here

  • Add the environment variable [Global Variable]
    Insert picture description here
    After adding it, the path to run our test. At
    Insert picture description here
    this time we will find that it has been run successfully.
How to cycle automatically
  • First we need to use the collection,
    Insert picture description here
    click on the key, and then run
    Insert picture description here
    and then the following page will appear
    Insert picture description here
  • Create a test.json file on the desktop, enter in the file
[{"node_name":"php"},{"node_name":"python"},{"node_name":"qna"}]
#若有其他的参数,也可以以键值对的形式,继续添加,若使用此文档,则上述循环的次数应该填3

At the end of the run, you can view the results of the run

Run from the command line

Insert picture description here
Insert picture description here

  • Export collection
    Insert picture description here
  • Install newman
    Insert picture description here
  • Run and generate a report. Note that the exported collection.json file and the test parameter json file must be in the same directory. Cd into this directory and execute the following statement.
newman run  导出文件名.json  -d  参数文件 -r  html,cli,json,junit

Insert picture description here

Published 37 original articles · won praise 4 · Views 3621

Guess you like

Origin blog.csdn.net/qq_29074261/article/details/105460741