Today, most companies adopt an SOA architecture. So how do we know what service methods SOA provides? is the browser constantly clicking on the attempt? or through WCF? Or is there always a document behind the code in the software development industry by reading the SOA interface documentation? These tactics are too clumsy. In fact, we can achieve this goal through some quicker and more efficient means.
The background to this idea is that our company deploys several SOA services. Then we test automation is very dispersed, form a variety of various, is simply eight Immortals crossing recount, very difficult to statistical automation coverage statistics. As a results, the method of using script to scan statistics is thought. Not muchSaidout,Directly on the code,The script is as follows:
#Coding=utf-8ImportRequests fromlxmlImportetree fromSuds.clientImportClientImportCsvpresoa= R"http://192.168.1.20:8085/"Soaurl=requests.get (Presoa) detail_html=etree. HTML (soaurl.content) links=detail_html.xpath (Ur"//a") HREFs= [Presoa +x.attrib["href"] forXinchLinksif ". config" not inchX.text and "bin" not inchX.text and "Demo" not inchX.text and ". asax" not inchX.text]svclinks=[]defGetsvcurl (templink): Tempsoaurlcontent=Requests.get (templink). Content temphtml=etree. HTML (tempsoaurlcontent) Temphtmllink=temphtml.xpath (Ur"//a/text ()") Svclink= [Templink + x +"? singlewsdl" forXinchTemphtmllinkif ". svc" inchx] [Svclinks.append (x) forXinchSvclink] [Getsvcurl (x) forXinchHrefs]getsvcurl (Presoa)Print "Svc count:{0}". Format (len (svclinks)) client=Client (svclinks[0]) svcfuns=[]defDealsvcmethods (Svclink): Methods=[X[0] forXinchClient (svclink). sd[0].ports[0][1]] [Svcfuns.append ({"funcname": X,"Svc": Svclink}) forXinchmethods] [Dealsvcmethods (x) forXinchsvclinks]with open (Ur"E:\ main station Soa2016-10-25.csv",'ab+') as Csvfile:writer= csv. Dictwriter (csvfile,fieldnames = ["funcname","Svc"]) Writer.writeheader () writer.writerows (svcfuns)
Of course, there are prerequisites for using this approach. First, the SOA site must expose the service. With this, we can easily find out the new service methods before and after the version.
Scan SOA and output all service methods