VOL 182
14
2020-12
Today is 17 days before 2021
This is the 182nd tweet of ITester Software Testing Stack
Click on the top blue word " ITester software testing Flowering " I am concerned, every morning 08: 3 0 punctual push each month from time to time presented technical books .
WeChat official account backstage responds to " resources " and " test kit " to receive test resources, and responds to " WeChat exchange group " and " introduction group " to join the group to fight monsters.
This article is 2998 words, it takes about 8 minutes to read
In the last article of the moco series: Introduction to mock and the construction and use of moco framework , it mainly introduces mock application scenarios, advantages and disadvantages, and the construction and use of moco framework.
The following mainly introduces the common parameter configuration and practical examples of moco.
One
method defines the request type
①moco.json, add method request type, the content is as follows:
[
{
"description": "method,用于定于请求类型",
"request": {
"uri": "/get",
"method": "get"
},
"response": {
"text": "请求方法为get"
}
}
]
②Open Jmeter, write and send a get request.
③When viewing the result tree, the returned content is as follows:
two
Queries define get request parameters
①In moco.json, add the queries parameter, the content is as follows:
[
{
"description": "queries,定义get请求参数",
"request": {
"uri": "/get",
"method": "get",
"queries": {
"name":"vivi",
"age":"18"
}
},
"response": {
"text": "姓名vivi,年龄18"
}
}
]
②Open Jmeter, write and send a get request with parameters.
③When viewing the result tree, the returned content is as follows:
three
forms define form request body
①In moco.json, the request type is post, and the form type request body is defined. The content is as follows:
[
{
"description": "forms,定义表单请求体",
"request": {
"uri": "/login",
"method": "post",
"forms": {
"username":"vivi",
"password":"123456"
}
},
"response": {
"text": "login success"
}
}
]
②Open Jmeter, write and send a post request, and bring the forms.
③When viewing the result tree, the returned content is as follows:
four
Define json request body
①In moco.json, the request type is post, and the json request body is defined as follows:
[
{
"description": "定义json请求体",
"request": {
"uri": "/login",
"method": "post",
"json": {
"username":"vivi",
"password":"123456"
}
},
"response": {
"text": "login success"
}
}
]
②Open Jmeter, write and send a post request, and bring the json request body.
③When viewing the result tree, the returned content is as follows:
Fives
headers define request headers
①In moco.json, the request type is post, define the json request body, and bring the request header content as follows:
[
{
"description": "headers,定义请求头",
"request": {
"uri": "/login",
"method": "post",
"headers":{
"content-type":"application/json"
},
"json": {
"username":"vivi",
"password":"123456"
}
},
"response": {
"text": "login success"
}
}
]
②Open Jmeter and add request header information
③Open Jmeter, write and send a post request, and bring the json request body.
④When viewing the result tree, the returned content is as follows:
six
Define cookies on request
①In moco.json, the request type is get, with cookies when requesting, and the content is as follows:
[
{
"description": "cookies,定义请求时的cookies",
"request": {
"uri": "/index",
"method": "get",
"cookies":{
"login":"true"
}
},
"response": {
"text": "欢迎进入首页"
}
}
]
②Open Jmeter and add cookie manager.
③Open Jmeter, write and send a get request, and carry cookies.
④When viewing the result tree, the returned content is as follows:
Seven
Define JSON response data
①In moco.json, the request type is post, and the response content is in json format. The content is as follows:
[
{
"description": "定义JSON响应数据",
"request": {
"uri": "/login",
"method": "post",
"headers":{
"content-type":"application/json"
},
"json": {
"username":"vivi",
"password":"123456"
}
},
"response": {
"json":{
"msg":"login success",
"status":"200"
}
}
}
]
②Open Jmeter and add request header information.
③Write and send a post request, and bring the json request body.
④When viewing the result tree, the returned content is as follows:
Eight
Redirect
①In moco.json, the request type is get, and the request is redirected. The content is as follows:
[
{
"description": "重定向",
"request": {
"uri": "/redirect",
"method": "get"
},
"redirectTo": "/index",
"response": {
"text":"test redirect"
}
},
{
"description": "这是首页",
"request": {
"uri": "/index",
"method": "get"
},
"response": {
"json":{
"msg":"欢迎进入首页",
"status":"200"
}
}
}
]
②Open Jmeter, the request path is redirect, and test whether to jump to index.
③ It can be seen from the response request body that redirection is realized, and the path of the request changes from redirect to index.
the above
That‘s all
More series articles
Stay tuned
ITester software testing stack (ID: ITestingA), focuses on software testing technology and treasure dry goods sharing, updates original technical articles on time every week, and gives technical books irregularly every month. Please indicate the source for third-party reprints.
ITester software testing stack
Past content favored
1. Python interface automation-interface basics (1)
2. Python interface automation-interface basics (2)
3. Python interface automation-requests module get request
4. Python interface automation-requests module post request
5. Cookie and session application for Python interface automation
6. Detailed explanation and application of Token for Python interface automation
7. Python interface automation requests request packaging
8. Python interface automation of pymysql database operation
9. Python interface automation logging log
10. Python interface automation logging package and actual combat
Want to get more latest dry goods content
Come star and follow me
See you at 08:30 every Monday, Wednesday and Friday
<< Swipe to view the next picture >>
Backstage reply "resources" to take dry goods
Reply to " WeChat Group" to fight monsters and upgrade
Personal WeChat: Cc2015123
Please indicate your intention to add :)
True love four consecutive, skill blessing~