F05_HttpRunner关联:使用提取到的 SessionID

F05_HttpRunner关联:使用提取到的 SessionID

 

 

我们要实现关联的目的是模拟用户身份访问接口,这就需要:

  1. 从前面步骤的响应中获取用户身份(本案例是保存在cookie中)
  2. 拿到该用户身份后访问其他接口资源

 

 

那么整个用例的基本结构就变为:

- config:
    name: 测试用例

- test:
    name: 测试步骤1
    request:
      url: http://xxxxxxx

    extract:
      # 提取cookies  
      p_cookies: headers.Set-Cookie


- test:
    name: 测试步骤2
    request:
      url: http://xxxxxxx
      headers:
        # 将前面提取的 cookies 应用到本次请求中  
        cookie: $p_cookies


- test:
    name: 测试步骤3
    request:
      url: http://xxxxxxx
    headers:
        # 将前面提取的 cookies 应用到本次请求中
        cookie: $p_cookies

 

 

关联过程如图所示:

 

那么完整的一个用例如下:


- config:
    name: open_danwei

- test:
    name: index - 打开登录页面
    request:
      url: http://localhost/myweb/jxc/index.asp
      method: GET
    extract:
      # 从上面请求结果(响应)中提取 cookies  
      - cookievalue: headers.Set-Cookie
    validata:
      - eq: [status_code, 200]

- test:
    name: login - 提交用户名和密码,完成登录操作
    request:
      url: http://localhost/myweb/jxc/index.asp?action=login
      method: POST
      data:
        username: admin
        pwd: admin
      headers:
        # 把提取到的 cookies 附加到本次请求头域  
        cookie: $cookievalue
    extract:
      - framesetname: (.*)frameset(.*)
    validata:
      - eq: [status_code, 200]
      - eq: [$framesetname, frameset]

- test:
    name: get_danwei - 登录成功后,打开系统设置页面
    request:
      url: http://localhost/myweb/jxc/system/danwei.asp
      method: GET
      headers:
        # 把提取到的 cookies 附加到本次请求头域    
        cookie: $cookievalue
    extract:
      - info: <form name=\"form1\" action=\"(.*)\">
    validate:
      - eq: [status_code, 200]
      - eq: [$info, danwei_del.asp]

 

 

执行测试用例,成功。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值