参考
领域 | DSL |
---|---|
xml | xpath |
html | css selector + xpath |
text | regex |
json | jsonpath |
assertion | hamcrest |
JsonPath
curl -k -H 'Cookie: xq_a_token=5806a70c6bc5d5fb2b00978aeb1895532fffe502;u=3446260779' -H 'User-Agent: Xueqiu Android 11.19' -H 'Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4' -H 'Host: stock.xueqiu.com' --compressed 'https://101.201.175.228/v5/stock/portfolio/stock/list.json?_t=1UNKNOWNc60715cb4a61425b311034a49f4aa024.3446260779.1563002521424.1563005246620&_s=8c6b2d&category=1&pid=-1&size=10000&x=1.3&page=1' | jq '.' | grep name
curl -k -H 'Cookie: xq_a_token=5806a70c6bc5d5fb2b00978aeb1895532fffe502;u=3446260779' -H 'User-Agent: Xueqiu Android 11.19' -H 'Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4' -H 'Host: stock.xueqiu.com' --compressed 'https://101.201.175.228/v5/stock/portfolio/stock/list.json?_t=1UNKNOWNc60715cb4a61425b311034a49f4aa024.3446260779.1563002521424.1563005246620&_s=8c6b2d&category=1&pid=-1&size=10000&x=1.3&page=1' | jq -r '.data.stocks[0].name'
curl -k -H 'Cookie: xq_a_token=5806a70c6bc5d5fb2b00978aeb1895532fffe502;u=3446260779' -H 'User-Agent: Xueqiu Android 11.19' -H 'Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4' -H 'Host: stock.xueqiu.com' --compressed 'https://101.201.175.228/v5/stock/portfolio/stock/list.json?_t=1UNKNOWNc60715cb4a61425b311034a49f4aa024.3446260779.1563002521424.1563005246620&_s=8c6b2d&category=1&pid=-1&size=10000&x=1.3&page=1' | jq
#python3还不支持
python2 -m jsonpath /tmp/1.json "$.data.stocks[*].name"
JsonSchema
- http://json-schema.org/learn/getting-started-step-by-step.html
- http://json-schema.org/implementations.html
- schema生成器 https://www.jsonschema.net/
- https://app.quicktype.io/#l=schema
schema生成器:JSON → JSON Schema
JSON → dict
- “type”: “string”
- “pattern”: “^(.*)$”
- “minimum”: 1.0,
- “maximum”: 100.0
关键代码
schema=json.load(open("list_schema.json"))
validate(instance=r.json(), schema=schema)
错误提示
E jsonschema.exceptions.ValidationError: '34.99' is not of type 'number'
E
E Failed validating 'type' in schema['properties']['price']:
E {'type': 'number'}
E
E On instance['price']:
E '34.99'
断言
企业微信实战
中场休息10分钟
16:20回来
数据驱动
模板技术
- mustache http://mustache.github.io/
用例管理
Case自动生成
作业1
- https://stock.xueqiu.com/v5/stock/portfolio/stock/list.json 断言返回的结果里只要出现招商银行,或者平安银行,就认为是对的,把代码贴到回复里、
实战作业
- 把部门、人员、消息推动、应用管理、素材、OA的api全部实现自动化测试
- 把代码上传到自己的github帐号内,并把github的项目地址贴到回帖下
- Allure2报告生成并截图到回复里
两周内交作业
TODO
- hook 完成自动化加解密
- 多环境支持
- 框架封装
- redmine系统的接口测试实战(Jenkin课程之后)
- mock第三方支付