Code structure:
Target Schema:
1. Use Case Analyzer, automatically generate test cases based on interface parameters, type
2. Data Analyzer, automatic maintenance of interface parameter data, Dynamic Data generation automatically, return the results of automatic query judgment
3. Core call engine, sub-soap and HTTP two, call the use case, return the result of the interface call
4. Report output, statistics use case pass rate, error log, database persistence, continuous integration
Current implementation Features:
Core call engine, Data Analyzer (Demo)
1. Use case structure (update)
Excel stores use cases in two sheet,sheet1 with the following structure
Sheet2 Storage test Environment host, interface WSDL address, interface method mapping relationship between the structure as follows:
The first line is the mapping between the host and the WSDL path.
2,3,4 columns are the mappings between WSDL and interface methods
There are several advantages to establishing this mapping relationship:
The use case design in 1.sheet1 is very concise; 2. Changes in the test environment or WSDL changes are convenient
The mapping relationship is saved as two dictionaries, implemented as follows:
defGetsoaconf (uri,sheetindex=1): """: Rtype:list"""conflist=data2list (uri,sheetindex) Max_len= Len (conflist[0])#number of columns, that is, how many WSDLRow_len = Len (conflist)#Number of rows, that is, the maximum number of methodsip_wsdl_dict={} wsdl_method_dict={} ip_wsdl_dict[conflist[0][0]]= []#Conflist[0][0] is an IP address forIinchRange (1, Max_len): Ip_wsdl_dict[conflist[0][0]].append (Conflist[0][i])#the key to the IP_WSDL dictionary is that ip,value is the corresponding list of WSDL paths.Wsdl_method_dict[conflist[0][i]] = []#the key of the Wsdl_method dictionary is wsdl,value defined as a list forJinchRange (1, Row_len): Method=Conflist[j][i]ifMethod! ="': Wsdl_method_dict[conflist[0][i]].append (Conflist[j][i])return[Ip_wsdl_dict,wsdl_method_dict]
The parameter is the file address, and the configuration information in the Sheet2 is read by default
2.SOAP calling generic method update
Using the reflection mechanism to implement the interface and interface method of the parameter invocation, the implementation method is as follows:
#!/usr/bin/python#Coding:utf-8Importsysreload (SYS) sys.setdefaultencoding ("Utf-8" ) fromSuds.clientImportClient fromSuds.xsdImportSxbasicdefSoarequest (Wsdl,fnname,data):#Soap Interface Invocation methodSxbasic.resultlist=[]#Initialize the location listSoaservice =Client (WSDL). Service Soarep=GetAttr (soaservice,fnname) (data)returnSoarep
"ps:sxbasic.resultlist=[" #初始化location列表 the meaning of this sentence please refer to my other blog "Kee Suds module cycle-dependent pit-runtimeerror:maximum recursion depth Exceede D "
The common benefit is that each interface method does not have to define the corresponding classes and methods in the code to implement the invocation
3. Implementation of the Data Analyzer (demo)
The trouble with interface automation is that the data in the database changes every day, and there is no guarantee that the results of each invocation will be consistent with the original design, while the solution to keep the data fresh and effective is to specify a rule to be generated automatically (query from database or randomly generated)
The docking of the data is replaced before the parameter is passed in to the calling method.
If the interface passed in parameters with a mobile phone number, and the phone number of the rules we all know that in Excel, the corresponding value is defined as "[Phone]"
The value of the string type in the code is checked to include the values in the [,], then the string matches the corresponding decision branch, executes the corresponding processing method, then assigns the return value to the corresponding key can realize the data dynamic update and the substitution
Python Interface Automation Test--framework rectification (v)