霍格沃兹测试开发学社
霍格沃兹测试开发学社








| 测试类型 | 工具 |
|---|---|
| 接口数据分析 | Charles、Fiddler、谷歌开发者工具 |
| 弱网测试 | Charles、Fiddler |
| 性能测试 | JMeter |
| 安全测试 | owasp |
| 功能测试 | Postman |
| 自动化测试 | Python+Request、Java+RestAssured |
| 性能测试 | JMeter |
| Mock技术 | Charles、Python+Requests、Java+RestAssured |
| 级别 | 年限 | 技术需求 |
|---|---|---|
| 初级 | 应届生 | 掌握协议相关的计算机网络知识 掌握基本的http协议接口的测试 掌握常用工具的使用:Postman、Charles、Fiddler |
| 中级 | 1~3年 | 掌握http自动化测试技术,python+requests、java+rest-assured |
| 高级 | 3~5年 | 能优化接口自动化测试脚本,并了解其他的接口测试技能,比如mock、性能测试 |
| 资深 | 5年以上 | 能二次定制常用的接口测试框架,并掌握其他的接口测试技能,比如mock、安全、性能 |
| 专家 | 5年以上 | 能独立开发可用的接口测试框架,类似HttpRunner |


| 形式 | 章节 | 课时 |
|---|---|---|
| 知识点 | 接口测试价值与体系 | 0.5课时 |
| 知识点 | 常见的接口协议与简单抓包 | 0.5课时 |
| 知识点 | 接口测试用例编写 | 1 课时 |
| 知识点 | postman 基础使用 | 1~2个课时 |
| 知识点 | 抓包工具 charles | 1~2个课时 |
| 知识点 | 抓包工具 fiddler(与charles二选一) | 1个课时 |
| 知识点 | 抓包工具证书配置 | 1个课时 |
| 知识点 | App 接口数据抓包 | 1~2个课时 |
| 知识点 | 代理工具 弱网 mock 使用 | 2个课时 |
| 形式 | 章节 | 课时 |
|---|---|---|
| 实战 | 抓包分析实战练习 | 1~2 课时 |
| 实战 | 接口测试实战练习 | 3~6课时 |
| 实战 | mock实战练习 | 2~4课时 |
| web自动化测试 | 接口自动化测试 | |
|---|---|---|
| 成本 | ⭐️⭐️⭐️ | ⭐️ |
| 测试效率 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 用例编写效率 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 稳定性 | ⭐️⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 自动化回归测试效率 | ⭐️⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 测试覆盖度 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 自动生成用例 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |






| Web/App 自动化测试 | 接口自动化测试 | |
|---|---|---|
| 成本 | ⭐️⭐️⭐️ | ⭐️ |
| 测试效率 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 用例编写效率 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 稳定性 | ⭐️⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 自动化回归测试效率 | ⭐️⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 测试覆盖度 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
| 自动生成用例 | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ |
看起来接口自动化测试什么都比 Web/App 自动化测试要好,为什么还要做 Web/App 自动化测试?


| 形式 | 章节 | 描述 |
|---|---|---|
| 知识点 | 接口自动化测试框架介绍 | 使用最流行的 requests 进行接口测试 |
| 知识点 | 接口请求构造 | http 请求头、请求参数、请求方法构造 |
| 知识点 | 接口测试断言 | 状态码、返回内容等断言 |
| 知识点 | json、xml 请求 | 以 json、xml 结构化的格式发送请求 |
| 知识点 | xml 响应断言 | 利用 xpath 进行断言 |
| 知识点 | json 响应断言 | 利用 json path 进行断言 |
| 知识点 | schema 响应断言 | 应对大量响应数据字段的格式断言 |
| 知识点 | 代理配置 | 利用代理分析测试脚本,排查请求错误 |
| 形式 | 章节 | 课时 |
|---|---|---|
| 实战 | 接口自动化测试实战 | 6~12 课时 |





| 形式 | 章节 | 描述 |
|---|---|---|
| 知识点 | 接口加密与解密 | 接口加密情况下的测试方案 |
| 知识点 | 多套被测环境 | 多套被测环境切换的测试方案 |
| 知识点 | 多协议封装设计 | 结合抽象工厂设计模式实现多协议封装 |
| 知识点 | 接口鉴权的多种情况与解决方案 | token、cookie、auth 等多种接口认证与解决方案 |
| 实战 | 电子商城接口自动化测试框架实战 | 接口用例编写、框架设计 |
| 形式 | 章节 | 描述 |
|---|---|---|
| 知识点 | http与https 的区别 | 分析 http 与 https 的区别 |
| 知识点 | get、post 区别 | get 与 post 的本质区别与具体抓包解读 |
| 知识点 | session、cookie、token 的区别 | 基于真实系统了解 session、cookie、token 的区别 |
| 知识点 | tcp 三次握手与四次挥手 | 分析三次握手与四次挥手流程 |
| 知识点 | tcp 与 udp 的区别 | 分析 tcp 与 udp 的区别 |
需求:搜索商品功能。
| 形式 | 章节 |
|---|---|
| 知识点 | 接口测试基础概念 |
| 知识点 | 接口自动化测试框架介绍 |
| 知识点 | 接口请求方法 |
| 知识点 | 接口请求参数 |
| 知识点 | 接口请求头 |
| 知识点 | 接口请求体-json |
| 知识点 | 接口响应断言 |
| 知识点 | json 响应体断言 |
HTTP协议
https://www.baidu.com/s?wd=霍格沃兹&rsv_spt=1
httpwww.baidu.com/swd=霍格沃兹&rsv_spt=**1
> GET /uploads/user/avatar/31438/8216a3.jpg HTTP/1.1
> Host: ceshiren.com
> Accept-Encoding: deflate, gzip
> Connection: keep-alive
> Pragma: no-cache
> Cache-Control: no-cache
> User-Agent: Mozilla/5.0
(Macintosh; Intel Mac OS X 10_15_0)
AppleWebKit/537.36
(KHTML, like Gecko)
Chrome/80.0.3987.116 Safari/537.36
> Accept: image/webp,image/apng,image/*,*/*;q=0.8
> Referer: https://ceshiren.com/
> Accept-Language: en,zh-CN;q=0.9,zh;q=0.8
> Cookie: user_id=xx;
_homeland_session=xx;
>

< HTTP/1.1 200 OK
< Server: nginx/1.10.2
< Date: Thu, 12 Mar 2020 09:13:44 GMT
< Content-Type: image/png
< Content-Length: 11390
< Connection: keep-alive
pip install requests| 方法 | 说明 |
|---|---|
| requests.request() | 构造一个请求,支撑以下各方法的基础方法。 |
| requests.get() | 构造 HTTP 协议中的 GET 请求。 |
| requests.post() | 构造 HTTP 协议中的 POST 请求。 |
| requests.put() | 构造 HTTP 协议中的 PUT 请求。 |
| requests.delete() | 构造 HTTP 协议中的 DELETE 请求。 |
具体详见《常见接口协议》录播
requests.get(url, params=None, **kwargs)
# 导入依赖
import requests
def test_get():
# 定义接口的 url 和拼接在 url 中的请求参数
url = "https://httpbin.ceshiren.com/get"
# 发出 GET 请求,r 接收接口响应
r = requests.get(url)
# 打印接口响应
logger.info(f"接口响应为 {r}")
requests.request(method, url, **kwargs)
GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE。def request(method, url, **kwargs):
"""Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to send
in the query string for the :class:`Request`.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
to add for the file.
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
:param timeout: (optional) How many seconds to wait for the server to send data
before giving up, as a float, or a :ref:`(connect timeout, read
timeout) <timeouts>` tuple.
:type timeout: float or tuple
:param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
:type allow_redirects: bool
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
:param verify: (optional) Either a boolean, in which case it controls whether we verify
the server's TLS certificate, or a string, in which case it must be a path
to a CA bundle to use. Defaults to ``True``.
:param stream: (optional) if ``False``, the response content will be immediately downloaded.
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
:return: :class:`Response <Response>` object
:rtype: requests.Response
| 参数 | 应用场景 |
|---|---|
| method | 请求方法 |
| url | 请求 URL |
| params | 请求中携带 URL 参数 |
| data | 请求中携带请求体(默认为表单请求) |
| json | 请求中携带 json 格式的请求体 |
| headers | 请求中携带头信息 |
| cookies | 请求中携带 cookies |
| files | 请求中携带文件格式的请求体 |
| auth | 请求中携带认证信息 |
| timeout | 设置请求超时时间 |
| allow_redirects | 请求是否允许重定向 |
| proxies | 设置请求代理 |
| verify | 请求是否要认证 |
| cert | 请求中携带 ssl 证书 |
案例: https://ceshiren.com/search?expanded=true&q=requests
?代表客户端向服务端传递的参数。key=value 形式拼接在 URL 中。&分隔?username=Hogwarts&id=666。requests.get(url, params)# 导入依赖
import requests
def test_get_by_params():
# 定义接口的 url 和拼接在 url 中的请求参数
url = "https://httpbin.ceshiren.com/get"
params ={
"get_key": "get_value"
}
# 发出 GET 请求,r 接收接口响应
r = requests.get(url, params=params)
def test_get_by_url():
# 定义接口的 url 和拼接在 url 中的请求参数
url = "https://httpbin.ceshiren.com/get?get_key=get_value"
# 发出 GET 请求,r 接收接口响应
r = requests.get(url)
飞书接口文档
| 内容 | 含义 |
|---|---|
| Authorization | 表示客户端请求的身份验证信息 |
| Cookie | 表示客户端的状态信息,通常用于身份验证和会话管理 |
| Content-Type | 表示请求消息体的 MIME 类型 |
| User-Agent | 发送请求的客户端软件信息 |
headers = {'user-agent': 'my-app/0.0.1'}
r = requests.get(url, headers=headers)
飞书接口文档
| 类型 | 介绍 | Content-type |
|---|---|---|
| JSON(JavaScript Object Notation) | 轻量级的数据交换格式,最常见的一种类型。 | application/json |
| 表单数据(Form Data) | 以键值对的形式提交数据,例如通过 HTML 表单提交数据。 | application/x-www-form-urlencoded |
| XML(eXtensible Markup Language) | 常用的标记语言,通常用于传递配置文件等数据。 | application/xml text/xml |
| 文件(File) | 可以通过请求体上传文件数据,例如上传图片、视频等文件。 | 上传文件的 MIME 类型,例如 image/jpeg multipart/form-data |
| 纯文本(Text) | 纯文本数据,例如发送邮件、发送短信等场景 | text/plain |
| 其他格式 | 二进制数据、protobuf 等格式 |

# 导入依赖
import requests
def test_post_json():
# 定义接口的 url 和 json 格式请求体
url = "https://httpbin.ceshiren.com/post"
params = {
"post_key": "post_value"
}
# 发出 POST 请求,r 接收接口响应
r = requests.post(url, json=params)
import requests
from requests import Response
# Response就是一个响应对象
r: Response = requests.get('http://www.example.com')
| 属性 | 含义 |
|---|---|
r |
响应 Response 对象(可以使用任意的变量名) |
r.status_code |
HTTP 响应状态码 |
r.headers |
返回一个字典,包含响应头的所有信息。 |
r.text |
返回响应的内容,是一个字符串。 |
r.url |
编码之后的请求的 url |
r.content |
返回响应的内容,是一个字节流。 |
r.raw |
响应的原始内容 |
r.json() |
如果响应的内容是 JSON 格式,可以使用该方法将其解析成 Python 对象。 |
# 导入依赖
import requests
def test_res_assert():
# 定义接口的 url 和 json 格式请求体
url = "https://httpbin.ceshiren.com/get"
# 发出 GET 请求,r 接收接口响应
r = requests.post(url)
r.status_codeimport requests
def test_req():
r = requests.get("https://httpbin.ceshiren.com/get")
assert r.status_code == 200
{
"name": "John",
"age": 30,
"city": "New York"
}

r.json():返回 python 字典。import requests
def test_res_json():
r = requests.get("https://httpbin.ceshiren.com/get")
assert r.status_code == 200
assert r.json()["url"] == "https://httpbin.ceshiren.com/get"