1、基本格式约定:yaml文件必须包含baseinfo和testCase,最外面-表示数据是一个list类型
baseinfo下面的关键词
- api_name:接囗名称
- url:接口地址
- method:请求方式
- header(可选):请求头,根据实际接口决定是否填写
- cookies(可选):cookie,根据实际项目情况决定
testCase下面的关键词:
- case name:测试用例名称
- data/params/json:请求参数类型,根据你的接口请求决定写什么类型,一般情况下get请求就写params,如果post,这时要跟请求是表单提交京data,是ison格式提交就填json
- validation:断言结果,有多种断言模式,如:contain、eg、ng、db
- extract(可选):接口的返回值提取,存放在extract.yaml,给别的接口使用,达到一个接口之间的上下游参数传递的目的
- extract_list(可选):返回值是多个。
2、单接口多用例样例
点击查看代码
- baseInfo:api_name: 用户登陆url: '/post'method: postheader: ${get_headers(json)}cookies: ${get_extract_data(Cookie)}testCase:- case_name: 用户登陆成功-001json:user_name: testadduserpasswd: admin123role_id: 12345678dates: ${get_now_time()}phone: 15600000000token: ${get_extract_data(goodsId,1)}validation:- code: 200- contain: {'url':'https://www.httpbin.org'}- eq: {'url':'https://www.httpbin.org/post'}extract:url: $.url- case_name: 用户登陆成功002json:user_name: testadduserpasswd: admin456role_id: 12345678dates: ${get_now_time()}phone: 13900000000token: ${get_extract_data(goodsId,1)}validation:- code: 300- contain: { 'url': 'https://www.httpbin.org' }- eq: { 'url': 'https://www.httpbin.org/post' }extract:url: $.url
3、业务场景多接口样例
点击查看代码
- baseInfo:api_name: 用户登陆url: '/post'method: postheader: ${get_headers(json)}cookies: ${get_extract_data(Cookie)}testCase:- case_name: 用户登陆成功json:user_name: testadduserpasswd: admin123role_id: 12345678dates: ${get_now_time()}phone: 15600000000token: ${get_extract_data(goodsId,1)}validation:- code: 200- contain: {'url':'https://www.httpbin.org'}- eq: {'url':'https://www.httpbin.org/post'}extract:url: $.url
- baseInfo:api_name: 获取信息url: '/get'method: getheader: ${get_headers(data)}cookies: ${get_extract_data(Cookie)}testCase:- case_name: 使用get查询信息params:token: ${get_extract_data(url)}validation:- code: 300