Automatic test based on web interface (based on HttpRunner+Fiddler)

Posted by ssppllaatt on Thu, 14 Nov 2019 15:08:14 +0100

1. Install Fiddler, please refer to http://together-learn.com/post/263

2. Install HttpRunner, the test I did in windows, precondition: install python and pip

pip install httprunner

3. Record interface request through Fiddler

4. Export request session. har format file

5. The har file is converted to the test case file required by HttpRunner

har2case index.har -2y

Note: if there is an https request, add it under testteos - Request

verify: False, as follows

config:
    name: testcase description
    variables: {}

teststeps:
-   name: /skin/jkj/css/navlist.css
    request:
        headers:
            User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML,
                like Gecko) Chrome/73.0.3683.86 Safari/537.36
        method: GET
        url: https://www.cn-healthcare.com/skin/jkj/css/navlist.css
        verify: False
    validate:
    -   eq:
        - status_code
        - 302
    -   eq:
        - headers.Content-Type
        - text/html
-   name: /api/getsignature
    request:
        headers:
            If-None-Match: W/"8b-e7NKoutVtiIjmwo8g97hsg"
            User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML,
                like Gecko) Chrome/73.0.3683.86 Safari/537.36
            X-Requested-With: XMLHttpRequest
        method: GET
        params:
            url: https://www.cn-healthcare.com/
        url: https://www.cn-healthcare.com/api/getsignature
    validate:
    -   eq:
        - status_code
        - 200
    -   eq:
        - headers.Content-Type
        - application/json; charset=utf-8
    -   eq:
        - content.appId
        - wx71aec0aae5f6883a
    -   eq:
        - content.timestamp
        - '1573711790'
    -   eq:
        - content.nonceStr
        - 2iuiyokvdubit3x
    -   eq:
        - content.signature
        - 130967aff5dfa383e9c900759ec6af473a660571

6. Start up test

hrun index.yml

7. View the test report. After step 6 is executed successfully, the reports folder will be generated in the same directory

 

Reference documents:

https://docs.httprunner.org/

Topics: Programming Windows pip Python Session