HttpRunner learning 3 - extract extract data and references

Foreword

In HttpRunner, we want to extract the parameters from the response result of the current HTTP request, you can extract to achieve keywords.

testing scenarios

Here, I will be a student recharge gold interface to simulation tests, this interface in Jmeter test instance of an interface - a small chopper pilot has instructions in the article.

Students gold recharge Interface: http://doc.nnzhp.cn/index.php?s=/6&page_id=11

This interface has permission to verify, we need to log in via an interface A, then B, recharge operations in the interface.

extract extract data

- test:
    name: login case
    request:
      url: /api/user/login
      method: POST
      headers:
        Content-Type: application/x-www-form-urlencoded
        User-Agent: Fiddler
      data:
        username: test1010
        passwd: aA123456
    extract:
      - sign: content.login_info.sign
    validate:
      - eq: [status_code, 200]
      - eq: [content.error_code, 0]

In this interface A, extract the keyword extracted by the sign value, the sign adding cookie for subsequent authentication.

 extract:
      - sign: content.login_info.sign

Reference data

- test:
    name: add gold
    request:
      url: api/user/gold_add
      method: POST
      headers:
        Content-Type: application/x-www-form-urlencoded
        User-Agent: Fiddler
        Cookie: test1010=$sign
      data:
        stu_id: 2114
        gold: 500
    validate:
      - eq: [status_code, 200]
      - eq: [content.error_code, 0]
      - eq: [content.msg, "操作成功!"]

In this interface B, first add the cookie authentication is complete ( test1010 is on a user interface to log in), and then recharge gold operations.

If you want to use the extract extracted from the sign, it is the $ sign referenced form.

Cookie: test1010=$sign

Run a use case

Complete with for example YAML format ( test_extract.yml ):

- config:
    name: extract test
    request:
      base_url: http://api.nnzhp.cn

- test:
    name: login case
    request:
      url: /api/user/login
      method: POST
      headers:
        Content-Type: application/x-www-form-urlencoded
        User-Agent: Fiddler
      data:
        username: test1010
        passwd: aA123456
    extract:
      - sign: content.login_info.sign
    validate:
      - eq: [status_code, 200]
      - eq: [content.error_code, 0]

- test:
    name: add gold
    request:
      url: api/user/gold_add
      method: POST
      headers:
        Content-Type: application/x-www-form-urlencoded
        User-Agent: Fiddler
        Cookie: test1010=$sign
      data:
        stu_id: 2114
        gold: 500
    validate:
      - eq: [status_code, 200]
      - eq: [content.error_code, 0]
      - eq: [content.msg, "操作成功!"]

In the current directory with YAML embodiment, Run: hrun test_extract.yml

Run a use case

View test report

View Report

Click to log , view the report details, you can see the interface A by extract data extracted sign, in reference to the success of the interface B.

Guess you like

Origin www.cnblogs.com/wintest/p/11779526.html