版本 | 日期 | 作者 | 修改记录 | 备注 |
---|
1.0 | 2022-09-30 | arley | | |
概要说明
背景
没有代码基础如何搞定接口自动化?框架提供可执行文件att.exe运行按自动化用例规则编写的yml文件格式用例即可输出测试报告。
功能
1. 自动化用例Yml格式编写
2. 测试用例中接口必要关键字段独立为接口文档
3. 按测试配置文件执行用例
4. 并发执行用例
5. 按标签筛选用例执行
6. 接口请求过程中数据替换、数据保存
7. 用例步骤切换登录账号
8. 失败用例重跑
9. 测试报告&日志输出
10. 用例变量隔离开关
11. 自定义扩展函数:应用于随机数据的生成
12. 用例步骤强制等待&智能等待
13. 基于locust的性能压测
14. 用例支持数据库sql操作
目录结构
快速上手
操作步骤
1. 新建接口文档文件,例如: api_doc.yml
2. 编写接口文档文件
3. 新建测试目录,例如: test_case
4. 在测试目录下新建用例文件,例如: 登录用例.yml
5. 编写用例
6. 编写执行配置文件,例如: run_file.yml
7. 执行测试,例如: python run.py run_file.yml
编写接口文档
抽离测试用例中接口必要关键字段独立为接口文档;
避免接口改动而大批量修改用例;
文档记录整个项目中所需接口信息;
login:
name: 登录接口
author: 研发
url: /login
method: get
requstType: data
headers:
Content-Type: multipart/form-data;
params:
response:
编写执行配置文件
配置文件所有变量都会在执行用例开始时加载到环境变量池, 编写用例中可通过 $cache{host1} 调用
var_suffix: y
is_common_test: y
pro_name: 测试项目
host: https://127.0.0.1:81
test_case: C:\Users\22220\Desktop\test_case
api_doc: C:\Users\22220\Desktop\resource\api_doc.yml
resource: C:\Users\22220\Desktop\resource
account:
test1:
user: admin
passwd: '123456'
test2:
user: user12
passwd: '123456'
db:
pgsql1:
type: pgsql
database: test
user: postgres
password: S123
host: 127.0.0.1
port: 8832
pgsql2:
type: pgsql
database: jw
user: jw_biz
password: jw_biz
host: 172.16.4.15
port: 5432
env: 测试环境
author:
report: n
thread:
tag: ORP0
reruns:
deptId: 370
companyId: 370
编写测试用例
collect_addtool_02:
name: 登录用例
tag: P0,登录
author: 陈磊
step:
-
name: 步骤一
action: login
account: test1
domain: $cache{host1}
headers:
params:
user:
passwd:
save:
token: $.token
assert:
-
jsonpath: $.errorCode
type: ==
values: 1
message:
sleep: 0
wait: 20
collect_addtool_06:
name: 异常图片视频上传
tag: P6
author: 陈磊
step:
-
name: 步骤一
action: file_upload
domain: $cache{host}
account: test1
headers:
Authorization: Bearer cb8f5d1e96ae4d019acc866dd8b57ccb
deptId: '1573497819780440065'
adminUserId: ''
tenantId: ''
file:
-
field_name: file
file_path: test\test1.txt
file_type: text/plain
-
field_name: file
file_path: test\test2.txt
file_type: text/plain
save:
msg: $.msg
assert:
-
jsonpath: $.code
type: ==
value: '0'
msg: error code 应等于0
-
jsonpath: $.msg
type: ==
value: 操作成功
msg: error code 应等于0
sleep: 2
wait: 10
collect_addtool_07:
name: 数据库查询操作
tag: P7
author: 陈磊
step:
-
name: 步骤一
db_name: pgsql1
sql: select * from customer_company limit 2;
save:
company_name: $[5]
assert:
-
jsonpath: $[5]
type: ==
value:
msg: $[5]
sleep: 2
wait:
详细说明