|
- #锚点
- host: &host http://192.168.xxxx.xxxx
- # 进行锚点定位,方便后面引用
- app_login: &app_login
- loginId: &applogin_loginid xxxxx
- password: &applogin_password test1234
-
- web_login: &web_login
- username: &weblogin_username xxxxx
- password: &weblogin_password test1234
- teachername: &teachername 李员
-
- test_init:
- login_type: web
- login_data:
- <<: *web_login
- # 保存响应结果(response.json()),文件为json文件,要输入该文件在jsonfile目录下的相对于jsonfile目录的路径,含名称
- # 后面的接口如果需要用到使用的响应结果就保存,用不到,无需保存.
- response_filepath: &weblogin_res_18342100004 qingjia/test_init_res.json
- # 保存token,文件为json文件,要输入该文件在jsonfile目录下的相对于jsonfile目录的路径,含名称
- token_filepath: &weblogin_token_18342100004 qingjia/test_init_token.json
-
- test_add:
- type: "api"
- # 接口的用例请求模板
- api_data:
- # 是否运行,当为null和true时,表示运行
- run_whether: true
- # 引用,访问地址
- host: *host
- path: /XXX/XXX/xxx/xxxxx/add
- data_type: data
- request_data:
- data:
- # 请假类型,该id的值为 其它 类型的请假
- actionType.id: 5298818
- students: [265002,265003,265004]
- studentname: &studentname [王妙海,孔萍,姜琴]
- starttime0: &starttime 2021-01-22 16:10
- endtime0: &endtime 2021-01-23 15:10
- description: &desc api 接口自动化测试框架提交的数据
- times[0].startTime: *starttime
- times[0].endTime: *endtime
- userId: null
- status: &status 待处理
- dependence_login: true
- login_data:
- # token_filepath的保存的文件,可以引用已有的文件.
- # 需要注意的是,当token_filepath不为None,且有值,session未过期时,会优先读取该json文件中的值.否则就读取login_data中的值.
- # 在读取login_data中的值,进行读取时,若token_filepath的值不为None,则此时会将登录后的token再保存到指定的json文件中
- token_filepath: *weblogin_token_18342100004
- login_type: web
- login_data:
- username: 18342100004
- password: 1
- dependence_case: false
- dependence_case_data: ~
- # 是否保存接口的响应结果,默认不保存.
- ensure_save_response: false
- # 保存该接口的执行的响应结果
- save_response: ~
- # 更不进行数据匹配校验.多用于查询接口,其他接口基本上用不到.查询接口,进行数据校验后,将匹配到数据保存下来
- # 供后续需要用到的接口使用.
- ensure_check: false
- check_data:
- # 断言,仅支持 pytest.assume() 和 hamcrest() 两种断言.
- assert:
- - assert_that(1,equal_to(1))
-
-
- test_query:
- type: "api"
- # 接口的用例请求模板
- api_data:
- # 是否运行,当为null和true时,表示运行
- run_whether: true
- # 引用,访问地址
- host: *host
- path: /XXX/XXX/xxx/xxxx/list
- data_type: data
- request_data:
- method: post
- url: ${url}
- data:
- currentPage: 1
- currentTerm: true
- pageSize: 100
- dependence_login: true
- login_data:
- login_type: web
- # 当为login_scope的范围为global时,可以填写这个值
- token_filepath: *weblogin_token_18342100004
- dependence_case: false
- # 依赖数据
- dependence_case_data:
- # 目前暂定的类型为:json,response,request 以及 sql.默认值为json
- # 当为response 和 request时,要在case_id里输入相关的yml文件的值.case层的 case_id 要与 page层的case_id 的yml文件进行拼接
- # 当为json(保存的结果,json文件),要在jsonfilepath里输入要读取的jsonfile的路径,含名称和目录,不包括jsonfile目录.如demo/query.json
- # 当为sql时,要在sqlstatement里输入相关的sql语句.
- dependence_type: json
- jsonfilepath:
- sqlstatement:
- case_id:
- dependence_key:
- replace_key:
- # 是否保存接口的响应结果,默认保存,config.yml有统一的开关.当不需要统一时,才会用到各自的开关.
- ensure_save_response: true
- # 保存响应结果 版块
- save_response:
- # 保存的文件类型,默认值为json, 三种类型:json、sql、all(在保存到json文件的同时,将结果插入到sql)
- save_type: json
- # 将该接口执行的响应结果,保存到指定的文件里.(在jsonfile目录下的相对路径,不含jsonfile目录.)
- response_filepath: qingjia/web_query_res.json
- # 以下为数据校验版块,对查询出的数据做校验匹配,最终来获取数据的id.
- # 是否进行数据检查,默认值为false,当为false时,check_data的值为None
- ensure_check: true
- check_data:
- # 将匹配到的第一条记录,保存到指定的json文件里.以供其他接口进行数据替换.
- save_jsonfile_path: &web_checkdata qingjia/web_query_check.json
- # 保存的字段,这里的值必须为query_keys的值的子集
- save_keys: [id]
- # 查询的字段,字段的个数包含save_keys.只有amount为固定字段,其他的字段,需要保存哪个字段的值,
- # 则写哪个字段,不需要保存,则不需要写.即:除amount,其余字段均为动态字段,根据需求写.
- query_keys:
- # 接口查询后,返回的记录总数,jsonpath表达式,用于for循环. 固定字段.
- amount: jsonpath(res,"$.amount")[0]
- # 记录id,jsonpath表达式,该表达式执行的结果应该为一个list. 一般用于返回.
- id: jsonpath(res,"$..id")
- # 校验的数据
- check_data:
- # 期望值
- expect_data:
- - *teachername
- - *starttime
- - *endtime
- - *studentname
- - *desc
- - *status
- # 实际值,需要注意actual_data里的值的顺序要与 expect_data的顺序保持一致.校验的字段的个数两者也要统一.
- # 当表达式为list时,要加引号
- actual_data:
- - jsonpath(res,"$..creator")
- - '[jsonpath(res,f"$.data[{i}].actionTimes[0].startTime")for i in range(jsonpath(res,"$.amount")[0])]'
- - '[jsonpath(res,f"$.data[{i}].actionTimes[-1:].endTime")for i in range(jsonpath(res,"$.amount")[0])]'
- - '[jsonpath(res,f"$.data[{i}].partakes[*].student") for i in range(jsonpath(res,"$.amount")[0])]'
- - jsonpath(res,"$..description")
- - jsonpath(res,"$.data[::].status")
- # 是否进行时差校验,,默认值为false
- ensure_checktime: true
- time_delta:
- # 时间差类型,s:秒(默认值), m:分钟,h:小时 ,d:天
- # 由于系统显示的提交时间到分钟,所有不能使用秒,
- time_type: m
- # 允许时间的范围,只在在这个范围内,就表示是目标数据
- timedelta_value: 1
- # 记录的创建时间,jsonpath表达式,查询结果.list类型
- # 当查询到的记录的创建时间与当前的时间相关值在timedelta_value范围内,就表示是目标数据
- create_time: jsonpath(res,"$..createTime")
- assert:
- - assert_that(1,equal_to(1))
-
- test_deldata:
- type: "api"
- # 接口的用例请求模板
- api_data:
- # 是否运行,当为null和true时,表示运行
- run_whether: true
- request_data:
- method: post
- url: ${url}
- params:
- id: ${id}
- dependence_login: true
- login_data:
- login_type: web
- # 当为login_scope的范围为global时,可以填写这个值
- token_filepath: *weblogin_token_18342100004
- dependence_case: true
- # 依赖数据
- dependence_case_data:
- dependence_type: json
- jsonfilepath: *web_checkdata
- dependence_key: [$.id]
- replace_key: [id]
- # 是否保存接口的响应结果,默认保存,config.yml有统一的开关.当不需要统一时,才会用到各自的开关.
- ensure_save_response: false
- # 保存响应结果 版块
- save_response: ~
- ensure_check: false
- check_data: ~
- assert:
- - assert_that("删除成功",is_in(jsonpath(res,"$.reason")))
-
- # 最全的key
- all:
- type: "api"
- # 接口的用例请求模板
- api_data:
- # 是否运行,当为null和true时,表示运行
- run_whether: true
- # 引用,访问地址
- host: *host
- path: /XXX/XXX/xxxx/xxx/list
- data_type: data
- request_data:
- method: post
- url: ${url}
- data:
- id: ${id}
- name: ${name}
- dependence_login: true
- login_data:
- login_type: web
- # 当为login_scope的范围为global时,可以填写这个值
- token_filepath: *weblogin_token_18342100004
- login_data:
- username: xxxxxx
- password: xxxxxx
- dependence_case: true
- # 依赖数据
- dependence_case_data:
- # 目前暂定的类型为:json,response,request 以及 sql.默认值为json
- # 当为response 和 request时,要在case_id里输入相关的yml文件的值.case层的 case_id 要与 page层的case_id 的yml文件进行拼接
- # 当为json(保存的结果,json文件),要在jsonfilepath里输入要读取的jsonfile的路径,含名称和目录,不包括jsonfile目录.如demo/query.json
- # 当为sql时,要在sqlstatement里输入相关的sql语句.
- dependence_type: json
- jsonfilepath: xxxxx/xxxx/xxx.json
- sqlstatement:
- case_id:
- dependence_key: [$.id,$.name]
- replace_key: [id,name]
- # 是否保存接口的响应结果,默认保存,config.yml有统一的开关.当不需要统一时,才会用到各自的开关.
- ensure_save_response: true
- # 保存响应结果 版块
- save_response:
- # 保存的文件类型,默认值为json, 三种类型:json、sql、all(在保存到json文件的同时,将结果插入到sql)
- save_type: json
- # 将该接口执行的响应结果,保存到指定的文件里.(在jsonfile目录下的相对路径,不含jsonfile目录.)
- response_filepath: qingjia/web_query_res.json
- # 以下为数据校验版块,对查询出的数据做校验匹配,最终来获取数据的id.
- # 是否进行数据检查,默认值为false,当为false时,check_data的值为None
- ensure_check: true
- check_data:
- # 将匹配到的第一条记录,保存到指定的json文件里.以供其他接口进行数据替换.
- save_jsonfile_path: &web_checkdata qingjia/web_query_check.json
- # 保存的字段,这里的值必须为query_keys的值的子集
- save_keys: [id]
- # 查询的字段,字段的个数包含save_keys.只有amount为固定字段,其他的字段,需要保存哪个字段的值,
- # 则写哪个字段,不需要保存,则不需要写.即:除amount,其余字段均为动态字段,根据需求写.
- query_keys:
- # 接口查询后,返回的记录总数,jsonpath表达式,用于for循环. 固定字段.
- amount: jsonpath(res,"$.amount")[0]
- # 记录id,jsonpath表达式,该表达式执行的结果应该为一个list. 一般用于返回.
- id: jsonpath(res,"$..id")
- # 校验的数据
- check_data:
- # 期望值
- expect_data:
- - *teachername
- - *starttime
- - *endtime
- - *studentname
- - *desc
- - *status
- # 实际值,需要注意actual_data里的值的顺序要与 expect_data的顺序保持一致.校验的字段的个数两者也要统一.
- # 当表达式为list时,要加引号
- actual_data:
- - jsonpath(res,"$..creator")
- - '[jsonpath(res,f"$.data[{i}].actionTimes[0].startTime")for i in range(jsonpath(res,"$.amount")[0])]'
- - '[jsonpath(res,f"$.data[{i}].actionTimes[-1:].endTime")for i in range(jsonpath(res,"$.amount")[0])]'
- - '[jsonpath(res,f"$.data[{i}].partakes[*].student") for i in range(jsonpath(res,"$.amount")[0])]'
- - jsonpath(res,"$..description")
- - jsonpath(res,"$.data[::].status")
- # 是否进行时差校验,,默认值为false
- ensure_checktime: true
- time_delta:
- # 时间差类型,s:秒(默认值), m:分钟,h:小时 ,d:天
- # 由于系统显示的提交时间到分钟,所有不能使用秒,
- time_type: m
- # 允许时间的范围,只在在这个范围内,就表示是目标数据
- timedelta_value: 1
- # 记录的创建时间,jsonpath表达式,查询结果.list类型
- # 当查询到的记录的创建时间与当前的时间相关值在timedelta_value范围内,就表示是目标数据
- create_time: jsonpath(res,"$..createTime")
- assert:
- - assert_that(1,equal_to(1))
|