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
How to automate
- First we need to parameterize the value of the request that will change
- Then we use the following picture as an example to test
- Next, let's run it
-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
- Add the environment variable [Global Variable]
After adding it, the path to run our test. At
this time we will find that it has been run successfully.
How to cycle automatically
- First we need to use the collection,
click on the key, and then run
and then the following page will appear
- 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
- Export collection
- Install newman
- 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