2020 Fiddler+Postman接口自动化项目实战 【提供源码】

文章目录

      • 项目实战
        • 1、使用抓包结合postman实现如下功能
          • 1.1 phpwind论坛注册
          • 1.2 phpwind论坛登录->发帖(帖子内容每次都不一样)
        • 2、获取token
        • 3、登录论坛
        • 4、项目实战接口源码
        • 5、后续

项目实战

1、使用抓包结合postman实现如下功能

1.1 phpwind论坛注册
1.2 phpwind论坛登录->发帖(帖子内容每次都不一样)

实战地址:http://47.107.178.45/phpwind/index.php?m=bbs

2020 Fiddler+Postman接口自动化项目实战 【提供源码】_第1张图片

2、获取token

 var token = responseBody.match(new RegExp(/name="csrf_token" value="(.+?)"/))[1];
 pm.globals.set("token",token);

在这里插入图片描述

3、登录论坛

2020 Fiddler+Postman接口自动化项目实战 【提供源码】_第2张图片

4、项目实战接口源码

{
	"info": {
		"_postman_id": "5f78663c-d674-4b33-845d-0baf7959b40c",
		"name": "项目实战",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "论坛注册",
			"event": [
				{
					"listen": "test",
					"script": {
						"id": "ae36924c-508a-4658-ab05-3f5e3dc2bb69",
						"exec": [
							"var username='yangchaoyi';",
							"pm.globals.set(\"username\",username);",
							"pm.globals.set(\"pwd\",\"123456\");",
							"pm.globals.set(\"email\",\"[email protected]\");"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/x-www-form-urlencoded",
						"type": "text"
					}
				],
				"body": {
					"mode": "urlencoded",
					"urlencoded": [
						{
							"key": "username",
							"value": "{{username}}",
							"type": "text"
						},
						{
							"key": "repassword",
							"value": "{{pwd}}",
							"type": "text"
						},
						{
							"key": "password",
							"value": "{{pwd}}",
							"type": "text"
						},
						{
							"key": "email",
							"value": "{{email}}",
							"type": "text"
						},
						{
							"key": "csrf_token",
							"value": "{{token}}",
							"type": "text"
						}
					]
				},
				"url": {
					"raw": "http://47.107.178.45/phpwind/index.php?m=u&c=register&a=dorun",
					"protocol": "http",
					"host": [
						"47",
						"107",
						"178",
						"45"
					],
					"path": [
						"phpwind",
						"index.php"
					],
					"query": [
						{
							"key": "m",
							"value": "u"
						},
						{
							"key": "c",
							"value": "register"
						},
						{
							"key": "a",
							"value": "dorun"
						}
					]
				},
				"description": "论坛注册"
			},
			"response": []
		},
		{
			"name": "获取token",
			"event": [
				{
					"listen": "test",
					"script": {
						"id": "b8f8cfca-2a2a-43eb-b2f4-f877dcbf5a13",
						"exec": [
							"//1、获取网站token",
							"// var tmp = pm.response.text();",
							"// var token = tmp.match(new RegExp(/name=\"csrf_token\" value=\"(.+?)\"/))[1];",
							"// pm.globals.set(\"token\",token);",
							"// console.log(pm.globals.get(\"token\"));",
							"",
							" var token = responseBody.match(new RegExp(/name=\"csrf_token\" value=\"(.+?)\"/))[1];",
							" pm.globals.set(\"token\",token);"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "http://47.107.178.45/phpwind/index.php?m=u&c=register",
					"protocol": "http",
					"host": [
						"47",
						"107",
						"178",
						"45"
					],
					"path": [
						"phpwind",
						"index.php"
					],
					"query": [
						{
							"key": "m",
							"value": "u"
						},
						{
							"key": "c",
							"value": "register"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "登录论坛",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/x-www-form-urlencoded",
						"type": "text"
					}
				],
				"body": {
					"mode": "urlencoded",
					"urlencoded": [
						{
							"key": "username",
							"value": "{{username}}",
							"type": "text"
						},
						{
							"key": "password",
							"value": "{{pwd}}",
							"type": "text"
						},
						{
							"key": "backurl",
							"value": "http://47.107.178.45/phpwind/read.php?tid=66152&fid=64",
							"type": "text"
						},
						{
							"key": "invite",
							"value": "",
							"type": "text"
						},
						{
							"key": "csrf_token",
							"value": "{{token}}",
							"type": "text"
						}
					]
				},
				"url": {
					"raw": "http://47.107.178.45/phpwind/index.php?m=u&c=login&a=dorun",
					"protocol": "http",
					"host": [
						"47",
						"107",
						"178",
						"45"
					],
					"path": [
						"phpwind",
						"index.php"
					],
					"query": [
						{
							"key": "m",
							"value": "u"
						},
						{
							"key": "c",
							"value": "login"
						},
						{
							"key": "a",
							"value": "dorun"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "发帖",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"value": "application/x-www-form-urlencoded",
						"type": "text"
					}
				],
				"body": {
					"mode": "urlencoded",
					"urlencoded": [
						{
							"key": "atc_title",
							"value": "yangchaoyi",
							"type": "text"
						},
						{
							"key": "atc_content",
							"value": "admin888",
							"type": "text"
						},
						{
							"key": "pid",
							"value": "",
							"type": "text"
						},
						{
							"key": "tid",
							"value": "",
							"type": "text"
						},
						{
							"key": "special",
							"value": "default",
							"type": "text"
						},
						{
							"key": "reply_notice",
							"value": "1",
							"type": "text"
						},
						{
							"key": "csrf_token",
							"value": "{{token}}",
							"type": "text"
						}
					]
				},
				"url": {
					"raw": "http://47.107.178.45/phpwind/index.php?c=post&a=doadd&_json=1&fid=73",
					"protocol": "http",
					"host": [
						"47",
						"107",
						"178",
						"45"
					],
					"path": [
						"phpwind",
						"index.php"
					],
					"query": [
						{
							"key": "c",
							"value": "post"
						},
						{
							"key": "a",
							"value": "doadd"
						},
						{
							"key": "_json",
							"value": "1"
						},
						{
							"key": "fid",
							"value": "73"
						}
					]
				}
			},
			"response": []
		}
	],
	"protocolProfileBehavior": {}
}

5、后续

今天老师讲授的时候,发现这个网址不仅需要验证token还要验证status,所以上述方法是有bug的,但是总体方法是没问题的,后续待更新ing

学如逆水行舟,不进则退

你可能感兴趣的:(软件测试)