The first interface automation framework

Demand 
1, automated first interface frame
1, read excel, to obtain data url, the request mode, the parameters, the checkpoint
2, call interface, returns the result acquiring
3, by checking whether with Example
4, to produce the report, mail

operations
1 .new folder

   

2.readme.md

3.config--setting

import os
import faker
from lib.util import random_password


EMAIL_INFO = {
    'user':'[email protected]',
    'host':'smtp.163.com',
    'password':'houyafan123'
}

TO = ['[email protected]','[email protected]','[email protected] '] 

The CC = [ ' [email protected] ' , ' [email protected] ' ] 
# ----------- define the following constants -------------- # ---- BASE_PATH
= os.path.dirname (os.path.dirname (os.path.abspath ( __FILE__ ))) # os.path.abspath get the path (path of atp) in the current directory, dirname obtain a copy directory CASE_PATH = os.path.join (BASE_PATH, ' Cases ' ) #join the case folder directory put together log_path = os.path.join (BASE_PATH, ' logs ' , ' atp.log ' ) # REPORT_PATH = os. path.join (BASE_PATH, ' Report ') # # ------------------------------------------ f = faker.Faker (the locale = ' ZH-the CN ' ) ENV = ' test ' # default test environment host_map = { " test " : " http://api.nnzhp.cn " , " dev " : " http://118.24.3.40 : 81 / " , " pre " : " http://api.nnzhp.cn/ " , } the HOST = host_map.get(ENV) func_map = { " <Phone> " : f.phone_number, " <id_card> " : f.ssn, " <In Email> " : f.email, " <name> " : F.Name, " <addr> " : F .Address, " <password> " : random_password } # this is supported parameterization, if you want to add other parameters of here continue to add on the line.

4.lib--read_case.py

A. jsonpath module installation, easy to find the relevant data

Import jsonpath 

D = {
     " STU " : {
         " Sex " : ' M ' ,
         " House " : {
             " Beijing " : { " Ring " : 5, " tricyclic " : 4 },
             " Shanghai " : { " Pudong " :. 4 } 
        } 
    }, 
    " STU2 " : 'abc'
}
Result = jsonpath.jsonpath (D, ' $ .. Beijing ' ) 

Print (D [ ' STU ' ] [ ' House ' ] [ ' Shanghai ' ] [ ' Pudong ' ])
 Print (Result)

B.config cases in New template

C. Editing read_case.py-- read excel, data acquisition

Examples of --setting D.atp instantiated

= func_map {
     " <Phone> " : f.phone_number,
     " <id_card> " : f.ssn,
     " <In Email> " : f.email,
     " <name> " : F.Name,
     " <addr> " : F .Address,
     " <password> " : random_password 
} # this is supported parameterization, if you want to add other parameters of here continue to add on the line.

Use Faker module

import faker

f = faker.Faker(locale='zh-CN')

# print(f.ssn())
# print(f.phone_number())
# print(f.email())
# print(f.address())
# print(f.name())
import random,string

def random_password():
    a  = random.sample(string.digits,2)
    b  = random.sample(string.ascii_letters,2)
    c  = random.sample(string.ascii_uppercase,2)
    d  = random.sample(string.punctuation,2)
    result = a + b + c + d
    random.shuffle(result)
    return ''.join(result)


func_map ={
    "<phone>":f.phone_number,
    "<id_card>":f.ssn,
    "<email>":f.email,
    "<name>":f.name,
    "<addr>":f.address,
    "<password>":random_password
}


def replace_param(s):
    for func_name,func in func_map.items():
        if func_name inS: 
            Result = FUNC () 
            S = s.replace does (func_name, Result)
     return S 

# replace_param ( "username = <Phone>, the passwd = 123456, addr = <addr>, id_card = <id_card>") 

# username = 15,539,055,994 , passwd = 123456, addr = Xinjiang East Market Xunyang Caolu Block A 498 947, id_card = 451123197106055998 
DEF str_to_dict (S): 
    D = {}
     for T in s.split ( ' , ' ): 
        K, V = T .split ( ' = ' ) 
        D [K] = V
     return D

 

E. package lib-request requesting class

F. check result lib-parse_response

 

 

 

  

 

Guess you like

Origin www.cnblogs.com/kexinwang/p/11256705.html