二、YMAL接口信息标准格式

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: post
    header: ${get_headers(json)}
    cookies: ${get_extract_data(Cookie)}
  testCase:
    - case_name: 用户登陆成功-001
      json:
        user_name: testadduser
        passwd: admin123
        role_id: 12345678
        dates: ${get_now_time()}
        phone: 15600000000
        token: ${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: 用户登陆成功002
      json:
        user_name: testadduser
        passwd: admin456
        role_id: 12345678
        dates: ${get_now_time()}
        phone: 13900000000
        token: ${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: post
    header: ${get_headers(json)}
    cookies: ${get_extract_data(Cookie)}
  testCase:
    - case_name: 用户登陆成功
      json:
        user_name: testadduser
        passwd: admin123
        role_id: 12345678
        dates: ${get_now_time()}
        phone: 15600000000
        token: ${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: get
    header: ${get_headers(data)}
    cookies: ${get_extract_data(Cookie)}
  testCase:
    - case_name: 使用get查询信息
      params:
        token: ${get_extract_data(url)}
      validation:
        - code: 300
posted @ 2025-02-25 10:55  测试三思  阅读(103)  评论(0)    收藏  举报