Httptesting HTTP (s) interface to third-party test automation package

Coordinates:  https://pypi.org/project/HttpTesting

HttpTesting # 

! [PyPI] ( HTTPS: // img.shields.io/pypi/v/HttpTesting?style=plastic) 


HttpTesting is HTTP (S) protocol testing framework to write test cases by YAML; supported by pip directly from PyPi installation, operation command code is supported, not fixed structure, by command generation scaffold. 

## version information 

| number | version number | Description | 
|: --- |: --- |: --- | 
| . 1 | V1 .0 | using unittest framework | 
| 2 | V1 .1 | pytest frame using | 




## Quick start 

### python virtual environment virtualenv use 

- install the virtual environment: PIP install virtualenv 

- to create a virtual environment: virtualenv demo_env 

- command line mode switch to the virtual environment Script directory: /../scripts/ 

- activate the virtual environment: of an activate .bat

### HttpTesting installation 


#### pip-line installation 

- PIP install HttpTesting == 1.0.26 

#### Download whl file to install 

- PIP install HttpTesting- 1.0.40 -py3-none-any.whl 


#### HttpTesting update package 

has been installed HttpTesting package, updated by the command pip 

- pip list view HttpTesting installation package version information 

- --upgrade HttpTesting install pip 

- pip install --upgrade HttpTesting == 1.0.26 



### or AMT AMT command 

| No. | command parameters | description | 
|: --- |: --- |: --- |   
| . 1 | AMT -config sET | this command to set the basic configuration config.yaml | 
| 2 | AMT -file template.yaml | YAML implementation of use cases, support for absolute or relative path | 
| 3 | AMT -dir testcase | batch execution YAML under testcase directory use cases, support for absolute or relative path | 
| 4| amt -startproject demo | generate scaffolding demo directory, and use case template | 
| 5 | AMT -har httphar.har | packet capture tool according to http har exported file, generate test cases YAML | 
| 6 | AMT -convert demo.yaml | converts the data into HttpTesting test | 


#### basic configuration 

- URL settings 

- set nail robot 

- test report settings 

- eMAIL mailbox settings 


#### use cases execute 

- YAML execution: AMT -file template.yaml 

- YAML batch execution: -dir TestCase AMT 



#### generates scaffold 

- scaffolding function is to generate a test stencil. 



#### HAR 

HAR command parsing, Charles capture tools derived http .har request file format generated automatically HttpTesting use cases. 





# Example # written 


### use case model 

> {TestCase 

>> ' Case1 ' : [ ' Description' , {}, {}], # {} For each scene mode interface 

>> ' Case2 ' : [ ' Description ' , {}], a single interface mode # 

>} 


### Example YAML format with   


    TestCase: 
        # of Case1 scene two requests consisting of 
        Case1: 
            - 
                Asc: xxxx business scenario (Login -> edit) 
            - 
                Asc: the login interface
                 the Url: / the Login / the Login
                 Method, : GET
                 Headers: 
                    Content- of the type:  " the Application / json " 
                    cache- Control:  " Cache-NO "
                Data:
                    name: "test"
                    pass: "test123"
                OutPara: 
                    "$H_token$": result.data
                    "${content_type}$": header.content-type
                    "${name}$": Data.name 
                    "${pass}$": Data.pass
                Assert:
                    - eq: [result.status, 'success']
            -
                Desc: 编辑接口
                Url: /user/edit
                Method: GET
                Headers:
                    content-type: "${content_type}$"   
                    cache-control: "no-cache"
                    token: "$H_token$"
                Data:
                    name: "${name}$"
                    pass: "${pass}$"
                OutPara: 
                    "$H_token$": result.data
                Assert:
                    - ai: ['success', result.status]
                    -EQ: [ ' result.status ' , ' Modify success ' ] 


    TestCase: 
        # the same interface, different parameters, expanded to more than the CASE 
        Case1: 
            - 
                Asc: The login interface - normal sign-on capabilities 
            - 
                Asc: The login interface
                 the Url: / the Login / the Login
                 Method, : GET
                 Headers: 
                    Content- of the type:  " the Application / json " 
                    cache- Control:  " NO-Cache " 
                the Data: 
                    name:  " the Test" 
                    Pass:  " test123 " 
                OutPara:  
                    " $ H_cookie $ " : cookie.SESSION
                 the Assert: 
                    - EQ: [result.status, ' Success ' ]
         Case2: 
            - 
                Asc: The login interface - password error 
            - 
                Asc: The login interface
                 the Url: / the Login / the Login
                 Method, : GET
                 Headers: 
                    Content- of the type:  " the Application / json " 
                    cache- Control:  " NO-Cache " 
                the Data: 
                    name:  " Test " 
                    Pass:  " test123 " 
                OutPara: 
                    " $ H_cookie $ " : cookie.SESSION 
                 the Assert: 
                    - EQ: [result.status, ' error ' ] 

### Parameters 

- " $ H_token} $ { " : variable parameters, can be used in the header information in the data data 
- " % {MD5 ( 'AAAA')}% " : a function prototype, particularly visible below the table support function. 

### custom variable 

variable scope of the current the CASE. 


### example (part code snippet) 

    TestCase:  
        Case1:
            - 
                Desc:Interface Detailed Description
                 user_var: 
                    token:   XXXXXXXX 
            - 
                the Url: / XXXX / XXXX
                 Method, : the POST
                 Headers: {}
                 the Data: 
                OutPara: 
                the Assert: [] 


    
- above defined variables user_var dictionary object, key the variable name, value as a variable value; Usage: $ {$ token} 

- without having to define the variables, fields with user_var embodiment may be omitted. 

#### OutPara field variables 

OutPara field used for public variables used by other interfaces, the default is "" ; 

-   Example :  " $ {H_token} $ " : result.data result is a request, the nesting level is returned 
- OutPara dict type is to be done a plurality of common variables. 


#### asserts assert 

assert field defaults to [].

| Number | assertions | assertion description | 
|: --- |: --- |: --- | 
| . 1 | EQ: [a, B] | Analyzing equal to a and b, or Fail | 
| 2 | NQ: [a, b] | Analyzing a and b are not equal, or Fail | 
| . 3 | Al: [a, b] | IS b corresponds to a determination id (a) == id (b ), or Fail | 
| . 4 | AT: [A, B] | Analyzing IS A Not B corresponds to the ID (A) = ID (B) |! 
| . 5 | AI: [A, B] | Analyzing a in b, or Fail | 
| . 6 | ANI: [a, b] | judgment in A not b, or Fail | 
| 7 | ais: [a, b] | judgment isinstance (A, b) True | 
|. 8 | Anis: [A, B] | Analyzing the isinstance (A, B) False | 
| . 9 | LN: [A] | Analyzing a is None, or Fail | 
| 10 | LNN: [A] | Analyzing A IS Not none | 
| . 11 | BT: [a] | determined as a True | 
| 12 is | BF: [a] | determined as a False | 


#### built-in functions and extended 

with a prototype (without parameters and parameters) 

- " % MD5 {( 'AAAA')}% " or " % {timestamp ()}% " 



| function name | parameters | Description | 
|: --- |: --- |: --- | 
| MD5 | string TXT | generate md5 string example: cbfbf4ea6d7c8032584dcf0defa10276 | 
| timestamp | - | seconds Time stamp examples: 1563183829 | 
| UUID1 | - | generate a unique ID, UUID1 example: ebcd6df8a77611e99bb588b111064583 | 
| datetimestr | - | generation date time string, Example: 2019 - 07 - 16  10 : 50 : 16 | 
| mstimestamp | - | millisecond timestamp, 20 bits | 
| sleep_time | - | thread to sleep second stage, decimal 0.5 to 500 milliseconds, 1 second to 1 | 

- subsequent addition of other 


## common object (usually used as an argument variable) 
- RES: request Response object 
- Result: RES. json or res.text 
- cookie: res.cookie response cookie dictionary objects; when used as a parameter representative of the wording if cookie.SESSION taken SESSION object cookie, only if the write cookie, resolves into. " SESSION = XXXXXXX; NAME = xxxxxx " 
-headers: res.headers response to the first dictionary objects 
- header: header.content-type request header object 


## by performing Example 
- . 1 generates scaffolding 
- 2 , scaffolding testcase prepared with the stencil Example YAML 
- . 3 , switch to the directory testcase 
- . 4 , amt -dir testcase testcase YAML run automatically with cases 
- . 5 , automatically generate test reports the Html 


## framework of the basic configuration 
- . 1 , open command frame config.yaml 
- 2 , AMT -config SET 
- . 3 , modify the basic configuration, and save 




# # code package and upload PyPi 

  

### via setuptools tool framework package, you need to write setup.py 



- packing: python3 setup.py bdist_wheel 

  

- upload PyP: Twine the Upload dist / *

  

Renderings: console mode, and reporting mode

 

Guess you like

Origin www.cnblogs.com/yhleng/p/11290494.html