Getting Started with Python test basis webservice interfaces

Webservice interface test method there are many (such as by SoapUI pretty good), but the practice of using P ython do test friends, the following may be relatively more popular.

1. Preparing the environment

A mounting, installed offline


webservice interface testing, need to use suds library, Baidu's online library of various suds had not even installed, Python3.5 version I have here, so not those suds online libraries are installed there is no way to install, so we are available to provide here a methods and suds library.

1) download suds library, file name: suds-jurko-0.4.1.jurko.4.zip
2) extracting archive file into the Python scripts installation path folder below.
3) Then the cmd command line, into suds-jurko-0.4.1.jurko.4 file, enter the command: Python setup.py the install
. 4) successfully installed
5) Note: If the import suds write code in the error py , it is imperative suds-jurko-0.4.1.jurko.4 following folder dist, suds suds_jurko.egg-info and three folders copied to the following site-packages Lib path (~ root / Lib / site-packages) below, you can be a normal visit.
6) If you are prompted ModuleNotFoundError: No module named 'version' , need to be updated about the suds-jurko, execution pip install --upgrade suds-jurko


Installation Second, the online tool pip to install python


1) PIP install SUDS
2) PIP install SUDS-Jurko
everything is ready, you can begin testing it!



New dream Share Dry


2, the use of suds library to test the webservice interfaces

1) introduction of suds library, as follows:

Import Client suds.client from
2) create a webservice object to call webservice which types of interfaces
user_url = "http://120.24.235.105:8080/finance-user_info-war-1.0/ws/financeUserInfoFacade.ws?wsdl" # here is the address to access your webservice
client = Client (user_url) #Client which is placed directly access the URL, you can generate a webservice target
3) to print out all the wsdl interface information inside the address:
Print (Client) # print inside the webservice All names interface method, the results shown in the screenshot below:

New dream Share Dry


4) the use of a look soapui webservice composition and parameters of an interface, wherein an interface register as follows:


New dream Share Dry


A total of six parameters, if the Python which to pass such parameters, how to assemble splicing, read on.


5) How to pass parameters:

t={"channel_id":2,"ip":"129.45.6.7","mobile":mobile ,"pwd":"123456","user_id" :"shabicu8","verify_code":”123456”} #用字典的方式传值

6) how to call this interface to register the service in Python:

= client.service.userRegister the Result (t)
#client this object, this method calls the service, and then call userRegister this interface function, the function which has just passed have we prepared Dictionary parameters t
Print (the Result) # print return results

7) The final returns the result is printed as follows:

New dream Share Dry


Guess you like

Origin blog.51cto.com/14627097/2456724